Introduction: Make the Volume Knob of Sound Blaster X-Fi Surround 5.1 Pro Sound Card Work in Raspberry Pi

About: Systems Administrator and Software Programmer.

Introduction

After completing "Create a Volume Control for USB Sound Card in Raspberry Pi" instructable, the volume of the sound card is controllable by a "software" volume controller. However, the sound card's built-in hard volume knob (the shiny circular object as shown in the picture) was still unusable. I felt it was a shame to leave it at that. So after digging around, I learned that the sound card has an infrared receiver interface. However, this particular sound card that I purchased did not come with remote control in the box. The surprising thing is that the built-in volume knob communicates with the sound card's infrared receiver and Linux Infrared Remote Control (LIRC) could read the signals received by the sound card's infrared receiver. This was a pleasant surprise!

Scope

This instructable will cover the following:

  • Create software volume control
  • Install LIRC
  • Train LIRC to capture signals received by the hard volume knob of the sound card
  • Configure LIRC's Daemon to monitor ALSA device's Infrared Receiver
  • Configure LIRC's IREXEC to map LIRC keys and control ALSA software volume control
  • Use ALSA utilities to test sound card and sound device

This instructables will NOT cover the following

  • PulseAudio
  • Open Sound System (OSS)

Specifications

My Raspberry Pi:

  • Raspberry Pi 2 model
  • Raspbian based on Debian Version 8.0 (a.k.a Jessie)
  • Advanced Linux Sound Architecture Driver Version k4.1.10-v7+
  • Pulse Audio and OSS are NOT installed. You must UNINSTALL PulseAudio or any other sound servers.
  • 2 speakers connected to Raspberry Pi's audio/video 3.5mm socket.

Step 1: Install Sound Blaster X-Fi Surround 5.1 Pro Sound Card

Complete the steps in "Use USB Sound Card in Raspberry Pi" instructable.

Step 2: Change the Name and Index of the Sound Card in Raspberry Pi

Step 3: Test Sound Card and Speakers

Step 4: Create a Software Volume Control

The Sound Blaster X-Fi Surround 5.1 Pro sound card does NOT provide any hardware mixer. Therefore a software volume control is needed.

Complete the steps in "Create a Volume Control for USB Sound Card in Raspberry Pi" instructable.

Step 5: Install LIRC Software

Step 6: Train LIRC to Capture Signals From X-Fi Surround 5.1 Pro Sound Card Infrared Receiver

Open terminal emulator of Raspberry Pi.

Stop the LIRC daemon

$sudo service lirc stop 
$cd ~

Run the program irrecord

$irrecord --device=hw:0,0 --driver=alsa_usb my_lirc_control.conf

Refer to screenshot. The irrecord's wizard is launched.

Follow all the wizard's instructions.

When wizard says: "Hold down an arbitrary button"

We continuously turn the volume knob clockwise.

When the wizard says "Please enter the name for the next button (press to finish recording)"

We type KEY_VOLUMEUP

When the wizard says: Now hold down button "KEY_VOLUMEUP".

We continuously turn the volume know clockwise until the wizard tell us to do something else.<br>

When the wizard says: Please enter the name for the next button (press to finish recording)

We type KEY_VOLUMEDOWN

When the wizard says: Now hold down button "KEY_VOLUMEDOWN"

We continuously turn the volume know ANTI-clockwise until the wizard tell us to do something else.

When the wizard says: "Please enter the name for the next button (press to finish recording)"

We press "ENTER" key to tell wizard that we want to stop recording.

When the wizard says: "Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON'T HOLD the button down!."

We turn the volume knob clockwise until a dot appears. Stop for 3 second and repeat until:<br>

The wizard will display "Successfully written config file" at the end".

If you make any mistake along the way, you can press Control + C to abort. Delete the my_lirc_control.conf file. Then run irrecord again.

Check the configuration file ~/my_lirc_control.conf as shown in the third screenshot.

ls -l ~/my_lirc_control.conf

Refer to screenshot.

Step 7: Configure LIRC Daemon to Monitor X-Fi Sound Card's ALSA Device

Open the terminal emulator

cd /etc/lirc

Make backup before we modify the file

sudo cp hardware.conf hardware.conf.pristine

sudo cp lircd.conf lircd.conf.pristine

Refer to screenshot. Change the settings in the hardware.conf which is a configuration file

sudo vi hardware.conf

Save the hardware.conf file.

Place the LIRC configuration file in /etc/lirc directory

sudo cp ~/my_lirc_control.conf /etc/lirc/lircd.conf

Change the name of the remote in the /etc/lirc/lircd.conf to something more descriptive like "sb_xfi_surround_51_pro_volume_knob"

sudo vi /etc/lirc/lircd.conf

Refer to screenshot.

Step 8: Check Whether the LIRC Daemon Is Ready to Use LIRC Interface

Open terminal emulator:

sudo service lirc stop
sudo service lirc start
sudo service lirc status

Refer to screenshot.

"..........lircd(alsa_usb) ready, using /var/run/lirc/lircd" means LIRC daemon is ready to send LIRC events to the LIRC interface. If you do NOT see this message, then you cannot proceed to the next step because no application can receive any LIRC events.

Step 9: Test Whether LIRC Daemon Is Responding Correctly to X-Fi Sound Card's Volume Knob Events

Open terminal:

irw
Turn hard volume knob clockwise.<strong><br>Expected Result:</strong><br>irw should display one or more of the following message:<strong><br>0000000000000010 00 KEY_VOLUMEUP my_lirc_control.conf</strong>
Turn hard volume knob ANTI-clockwise.<strong><br>Expected Result:</strong><br>irw should display one or more of the following message:<strong><br>000000000000000f 00 KEY_VOLUMEDOWN my_lirc_control.conf</strong>

Refer to screenshot

Step 10: Configure IREXEC Software

IREXEC is a program launcher. It responds to LIRC daemon's button/key events.

Open terminal

cd /etc/lirc

Create a system-wide configuration

sudo vi lircrc

Refer to screenshot. Enter lines as shown.

Save the file

Step 11: Test IREXEC Configuration

Open terminal emulator:

sudo service lirc stop 
sudo service lirc start 
sudo service lirc status
ircat irexec

Refer to screenshot.

Turn the volume knob clockwise.

Expected result is "amixer sset Master 1+" messages are shown

Turn the volume knob ANTI-clockwise.

Expected result is "amixer sset Master 1-" messages are shown

Step 12: Test the System

Open terminal:

sudo service lirc stop
sudo service lirc start  
sudo service lirc status
alsamixer

Turn the volume knob clockwise. The Master Volume should add coloured bars as you turn the volume knob.

Turn the volume knob ANTI-lockwise. The Master Volume should remove coloured bars as you turn the volume knob.

Open another terminal:

speaker-test -c2 -twav

The speakers volume should vary when you turned the volume knob clockwise or ANTI-clockwise.