| # Using the ALSA audio IR receiver driver ## Hardware This driver supports the IR-audio IR receiver module. A more detailed description of how to build and set up the hardware can be found by following the link. ## How to use ALSA Because I haven't seen yet any noticeable ALSA documentation for users, I should explain a little here about how to use ALSA itself. Still I will presume you already have installed ALSA and it is running. ALSA provides a lot of mixer controls, and it is not always obvious how to enable recording from a specific input, although as soon as you get the idea it turns to be relatively simple. Launch the alsamixer application (you can use the -c switch to select the desired sound card by number). Now scroll to see that you have a lot of controls :-) and many of them have unknown functions. Suppose your IR-audio module is connected to the CD-IN input; let's first test if your hardware works at all. Find the "CD" control, move the volume up and unmute it (with the 'M' key). Then take some remote control and activate it in front of your IR receiver. You should hear some kind of a bubbling, squeaking or beeping sound (depending on you remote control type). If you do, then your IR receiver works (I'll be surprised if it doesn't :). Now mute the channel again and select this channel for capturing by pressing "SPACE" on it: on the top you should see the text "CAPTUR" which means that this channel is connected to the analog-to-digital converter input (the level of CD control doesn't matter - it can be set to zero). Then look for a control called "Capture". Press SPACE on it (if it is applicable to your sound card) and move the "volume" up. On most sound cards this is enough, but on my Yamaha YMF754 I also had to move up the level of the "ADC Capture" and "Digital" controls (there are also ADC Capture 1 and Digital 1 but those are for SPDIF as far as I understand). Finally, let's test if recording from selected input works. In a separate window (I did it in X11) launch the arecord tool with the following parameters:
        arecord -D hw:# -c1 -r8000 -f U8
where # is the number of your sound card (0, 1, ...) (if your sound card has more than one ADC and your device is connected to the 2nd, 3rd, ... ADC you will have to use the extended form "-D hw:#,#" where second # selects the ADC device number on the sound card). The -c1 parameter tells arecord to sample monophonic signal (left channel), the -r8000 sets the sampling frequency to 8kHz and -f U8 selects "unsigned byte" sampling format. You should see a lot of garbage symbols. If you move the "Capture" lever down to zero, arecord should type just one or two symbols (that is "silence"). Now try to raise "Capture" and to disconnect from ADC all unneeded signals (e.g. turn "CAPTUR" off, if possible, from all inputs except CD). It still should show silence (because you don't press any buttons on IR control, aren't you?). Finally, press some buttons on IR control and you should clearly see how signal changes. If it doesn't (and you heard the signal in the previous experiment) you connected to the wrong (right) channel. If you used a BLS-04 connector (like me :-) you have to re-plug it after rotating by 180 degrees (since the center two pins are ground and L/R pins are on sides). Otherwise you will have to redo the connector (well, see yourself...). Okay, now if arecord shows correct results like described above, you're ready to use lirc (ugh... finally!). ## Using the driver The input device is by default "hw" (to see a list of available devices try "arecord -L"); this can be overridden with the --device command-line switch. For example, my IR module is connected to the second sound card, thus I run (for example) irrecord this way:
        irrecord -d hw:1,0 file
You also can use ALSA library internal environment variables such as ALSA_PCM_CARD and ALSA_PCM_DEVICE to specify the values for card number and card device number. Also you can specify the sampling rate (in Hertz) by placing a '@' after device name and then the numeric sample rate. The default value is 8000, however, you can play with it:
        irrecord -d hw@11025 file
The basic sampling frequencies (supported by most sound cards) are: 8000, 11050, 16000, 22050, 32000, 44100, 48000 Hertz. The higher the sampling frequency, the more accurate results (e.g. space/pulse lengths in microseconds) you will get, but with all remote controls I've tried 8000Hz is quite enough. However, when you create configuration files (e.g. with irrecord) I'd recommend you to set sampling rate as high as possible:
        irrecord -d hw@48000 file
This could help create more accurate timings in the config file and then you can use this config with lower sampling rates. Some sound cards do not support capturing in mono which is the default for audio_alsa. If you come across this you will receive a message stating an invalid argument when setting the capture format. You can get around this problem by telling audio_alsa to capture in stereo:
        irrecord -d hw@44100,l file
or:
        irrecord -d hw@44100,r file
The l (left) or r (right) character instructs audio_alsa on which channel it should inspect when reading the samples from the IR receiver. ## Quirks I have found that on my motherboard the built-in audio card has a bug that could influence other sound cards too. When xmms was playing something very loud and master volume was close to 100% I observed that lirc become "deaf" for some time. Investigations shown that there is a bug in audio card schematics that causes CD-IN pre-amplifier to shutdown because of not enough power when too much power goes to the master amplifier (well, this is just my suspicion). When I lowered master volume to 90%, everything started to work fine. In any case, playing at 100% volume was causing sound distortion (because master amplifier is also out of power and clips output signal, although it does not shutdown like pre-amplifier does) thus lowering master volume does only good. Another bug I've come across and you should be aware of is that some ALSA drivers (notably my driver for Yamaha YMF7[2,4,5]4) are buggy and sampled data sometimes contains noise (clicks) which influence badly recognition of proper command sequences. This happens for me, however, only at 11025 and 22050Hz rates, so you may wish to test if you're not affected by recording a wav file with arecord and the listening to it - the clicks are very noticeable by ear. A sign of this situation may be that while you're keeping the button on remote control pressed, the irw tool will repeatedly drop the repeat count (2nd column) to 0 after 2-6 repeats. [LIRC homepage] The LIRC Manual, last update: 10-June-2014 |