Tag: surround sound
Addressing Individual Audio Channels of a Multichannel ALSA System
by Mostafa on Oct.03, 2005, under Hardware, How To ..., Linux, Software
At first I thought I could just use one of the audio editors to create a 5.1 channel sound file and blank all the channels that I don’t want. Sweep claims to be a multichannel audio editor but at the moment it’s not possible to edit the individual audio channels. So, I tried out Audacity. Although Audacity allows the editing of the individual channels, it’s not possible to save the edited file in a multichannel format – it’s invariably down-mixed to stereo. So, custom sound files were no longer an option ..
At this point, I started looking at the ALSA PCM plugins. The route plugin seemed like the perfect candidate. In order to use the plugin I had to create the plugin definitions in the file ~/.asoundrc:
[darkknight@darkworld ~]$ cat .asoundrc pcm_slave.rt { pcm surround50 channels 5 } pcm.front_l { #Front Left type route slave rt ttable.0.0 1 } pcm.front_r { #Front Right type route slave rt ttable.0.1 1 } pcm.front_c { #Front Center type route slave rt ttable.0.4 1 } pcm.rear_l { #Rear Left type route slave rt ttable.0.3 1 } pcm.rear_r { #Rear Right type route slave rt ttable.0.2 1 } pcm.front_both { #Front - Both type route slave rt ttable.0.0 1 ttable.0.1 1 } pcm.rear_both { #Rear - Both type route slave rt ttable.0.2 1 ttable.0.3 1 }
The plugins can be used with the aplay utility:
[darkknight@darkworld ~]$ aplay -D front_c /usr/share/sounds/alsa/Front_Center.wav Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Of course it makes sense to use only Mono files with the plugins since the mappings are always carried out from channel 1. It’s the ttable entry that’s responsible for the mapping. The first value is the source channel (0 = channel 1, 1 = channel 2, etc.). The second value is the channel to route to. The third value controls the volume; a value of 0 means 0% volume and a value of 1.0 means 100% volume.
With the new plugin definitions, it’s even easier to balance the speaker levels. The following command will alternate between the front speakers and the center speaker until interrupted:
[darkknight@darkworld ~]$ while [ 1 ]; do /usr/bin/aplay -D front_both -q /usr/share/sounds/alsa/Noise.wav; /usr/bin/aplay -D front_c /usr/share/sounds/alsa/Noise.wav; done