Help answer threads with 0 replies.
Go Back > Blogs > serafean
User Name


Rate this Entry

A little ALSA magic

Posted 03-11-2011 at 06:27 PM by serafean

Wanted configuration :
  • user kde can play sound using the Optical output
  • user enna can play via analog and optical simultaneously (optionaly HDMI)
  • Both users can play via Optical at the same time
  • Both have access to an upmixing device that encodes the stream into A52 and sends via the Optical output

first we name the outputs (link numbers to names, this will be different on your hardware) and add a dmix device for the digital output to the global asoundrc:
        type hw
        card 0
        device 0

        type hw
        card 0
        device 1

        type hw
        card 0
        device 3
        type dmix
        ipc_key 1024
                pcm "optical"
                period_size 2048
                buffer_size 8192
                rate 44100
        ipc_key_add_uid false
        ipc_perm 0666
                0 0
                1 1
that takes care of points 1 and 3. Duplicating outputs now :
In user enna's asound.rc, create a new device of type "multi", which will contain 4 (6) channels, where each channel will be bound to a slave's channel.
pcm.bind {
        type multi;
        slaves.A.pcm "analog";
        slaves.O.pcm "dmixer";
        slaves.H.pcm "nvhdmi"
        slaves.A.channels 2;
        slaves.O.channels 2;
        slaves.H.channels 2;

        bindings.0.slave A; 0;
        bindings.1.slave A; 1;

        bindings.2.slave O; 0
        bindings.3.slave O; 1;

        bindings.4.slave H 0
        bindings.5.slave H 1
Next we have to bind the "bind" device's channels with the active stereo stereo, effectively duplicating it. the "route device is good for that"
        type route;
        slave.pcm "bind";
        ttable.0.0 1;
        ttable.1.1 1;

        ttable.0.2 1; #0 - front left, 2 channel from above bindings, 1 volume --> bind front left to channel 2;
        ttable.1.3 1;

        ttable.0.4 1;
        ttable.1.5 1;

Now playing while using the DuplicateOutput device plays on both analog and optical (and also should work on HDMI, but I don't have the possibility to try it). Point 2 done.

Last : stereo upmixing to 5.1, playable by an amp (encapsulated in A52) in the global asound.conf. Again, we create a 6 channel device that encodes the stream in A52
pcm.A52Encode {
        type upmix
                type a52
                bitrate 448
                card 0
        channels 6
And finally create the device that copies Front channels to the back, and mixes them together to create the central and LFE channels.
pcm.RoutingUpmix {
    type route
        slave.pcm "A52Encode"
        slave.channels 6
        ttable.0.0 1
        ttable.1.1 1
        ttable.1.2 1
        ttable.0.3 1
        ttable.0.4 0.5
        ttable.1.4 0.5
        ttable.0.5 0.5
        ttable.1.5 0.5
Point 3, check.
And thats it, everything I wanted is done... with some caveats :
  • videos with a digital stream will only play through one passthrough device (optical/HDMI)
  • Upmixing is possible only with one source at a time (2 programs cannot play simultaneously)+the passthrough problem
Do comment if you have any idea on how to fix this.

Most of this was put together from various examples on the ALSA wiki. All credit goes there. (Dmix part shamelessly copied)
Views 1993 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 03:48 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration