Using LIRC and the sound card input to decode IR remote controls on Linux and Mac OS X/Darwin systems



This page first describes an approach to use the sound input to record IR remote control signals and then provides hard- and software to deploy it on Linux/Unix systems and on Mac OS X.

The Linux Infrared Remote Control project is used for the decoding from IR pulse/pause sequences to a specific button press on the remote control. It provides an extensible framework for decoding of IR signals recorded by a variety of hardware receivers. It was ported to the Mac and a new audio driver was added.

Some remarks concerning a (yet missing) application that maps remote control button presses by the user to actions on Mac OS X conclude this page.


Using the Audio Input


Because the only free input on my PowerMac G3/350 is the sound card, I reasoned about how I could use it to decode IR signals. I found an article about using a IR diode connected to the sound card to sample IR remote control signals. This approach doesn't provide a long range and only works in the dark.

As the normal home-brew receivers use an integrated circuit that have a reasonable range, why not use this IC and connect it to the sound in?
But the sound input is not intended to record TTL signals, so I first reduced the TTL level signal to 1 V with 2 resistors and then used a capacitor to set the default level to GND. See Figure 1 for the schematics. I used the 5 V supply from a hard drive connector from inside the computer.

If there is an IR burst, the IC changes its output and this high frequency signal passes the capacitor and the sound card measures a maximal value. I recorded the sound I got from a Sony Remote.

In this waveform, you can clearly see the IR bursts and detect their length and the pause in between them. Notice that the signal always drifts toward zero. This relates to the used capacitor. If there would be a very long signal burst, so that the signal would reach zero, the falling edge could still be detected.


Waveform of Sony RMT-812 Button T

Figure 1: Signal of the Sony RMT-812 Button T
(recorded with the prototype below plugged into the sound-input)

With this description, an algorithm for detecting pulse and pause length is obvious:

At the start, there is no IR burst and the sigal is zero. When the next IR burst starts, the signal goes to the upper or lower maximum. Wait for the next edge. This is the end of this burst. The time until the next edge is the pause time.

An edge can be detected by testing, if the difference between sample x and x+3 is about 0.9. I used x and x+3 as x and x+1 didn't work proper because the edge was not steep enough.

While implementing the audio driver, I was glad to find the PortAudio - portable cross-platform Audio API which was easy to use and promises to run on all major platforms.


Do-It-Yourself: Hardware



You need:
  • An IR receiver like the TSOP 1738 (see LIRC homepage for other options)
  • Two resistors, 4k7 and 1k
  • One capacitor 100 nF
  • An old 3,5 mm headphone cable or a 3,5 mm plug for your sound card
The schematic for this is fairly simple. The 2 resistors are used to reduce the 5V data signal of the IC to less than 1 V and the capacitor removes any DC voltage. If no IR bursts are detected, the sound card 'hears' nothing. GND is shown two times as it is needed for the power supply and for the signal ground.

Note: If the edges of the signal get smoothed to much, you can try to use a capacitor with an higher value, a user reported success using a 50 uF capacitor instead of the 100 nF one.

The nice schematic drawing was kindly provided by Miguel Ángel Vilela.





Figure 2: Schematic

Here's a picture of the free flowing circuit already glued inside the dvd tray panel of my mac:
Image of the prototype
Figure 3: Prototype

The mac is a design object, so adding wires and electronics outside isn't a good idea. I suggest placing the IR receiver and the electrical parts inside the mac as shown the picture. Getting the 5V power supply inside the mac is simple, just use on of the hard drive power connectors. Assert yourself with a voltage meter that you get 5 V and know which strip is plus.

Can you see the little black hole below the DVD eject button in this picture of the build-in IR receiver?

Built-In_IR receiver
Figure 4: Build-In IR receiver

In the close-up, you get a better chance to find the IR receiver.
Close-up of the build-In IR receiver
Figure 5: Close-Up of the build-in IR receiver

Do-It-Yourself: Software


Support for the audio IR driver based on the PortAudio - portable cross-platform Audio API was added with LIRC release version 0.7.

1. Get the sources:

2. Mac OS X only: Compile and install libgnugetopt:

expand the archive and cd into the libgnugetopt directory
> ./configure
> make
> sudo make install

3. Compile and install the PortAudio Library

Expand the archive and cd into the portaudio directory
> ./configure
> make
> sudo make install

4. Compile and Install LIRC

Expand the archive and cd into the lirc directory

To configure, compile, and install LIRC:
> ./configure --with-driver=audio
> make
> sudo make install

That's it. Now you've got a working LIRC version.

Read the LIRC documentation in doc/html for more information and what you can do next.


Useful Applications for Mac OS X


The first application you might want to try out is the open source Video Lan Client. It provides a LIRC plug-in, so you can at least watch your favorite movie controlled remotely.

To use it, you have to get the sources and compile them yourself. You can follow the Mac OS X compilation instructions on their Developer Wiki.

In the configure call you can add the option: --enable-lirc .

To enable lirc, specify lird in the extra interface field of the input tab of the preferences dialog or in the your ~/Library/Preferences/VLC/vlcrc file, setting extraintf=lirc .

You also have to create a .lircrc file in your home dir that maps the buttons of your remote to controls in VLC. An example is in the VLC sources at doc/lirc/example.lircrc .

Note that you might want to grant access to /usr/local/dev/lircd to anybody (sudo chmod a+rw /usr/local/dev/lircd ) so anybody can access the lircd. Good luck and enjoy.

A Mac Remote Control App like the one provided with the Keyspan USB Remote is missing. So far, you can enjoy watching the tool irw showing remote control button presses, use irxevent to send X11 events to X11 apps and use irexec to run shell commands. With the irexec tool and the osascript command, you can remote control other Mac applications via AppleScript. Although this is not really satifiying it might solve some needs already. I'm dreaming of a multimedia-box with an On-Screen-Display that allows me to watch DVDs and DivX movies and listen to music laying comfortable in my bed.

Using Apple Script and the System Events.app you can send all user interface events to any application on the mac that has AppleScript support. (most of them are) and then maybe you could write the missing app...

Matthias Ringwald

[LIRC homepage]
Last update: 2-November-2008