LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > serafean
User Name
Password

Notices


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:
Code:
pcm.analog{
        type hw
        card 0
        device 0
}

pcm.optical{
        type hw
        card 0
        device 1
}

pcm.nvhdmi{
        type hw
        card 0
        device 3
}
pcm.dmixer{
        type dmix
        ipc_key 1024
        slave{  
                pcm "optical"
                period_size 2048
                buffer_size 8192
                rate 44100
        }
        ipc_key_add_uid false
        ipc_perm 0666
        bindings{
                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.
Code:
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;
        bindings.0.channel 0;
        bindings.1.slave A;
        bindings.1.channel 1;

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

        bindings.4.slave H
        bindings.4.channel 0
        bindings.5.slave H
        bindings.5.channel 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"
Code:
pcm.duplicate_output{
        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
Code:
pcm.A52Encode {
        type upmix
        slave.pcm{
                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.
Code:
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 2397 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 12:56 AM.

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