[pulseaudio-discuss] Moving sources and sinks

Matt Patterson matt at v8zman.com
Fri May 2 10:37:33 PDT 2008


I do agree that coding for pulse can be a steep learning curve, which is 
why I opted to build all my solutions by simply connecting to the text 
mode control socket and sending commands/parsing text output. I have 
built what is essentially a multiplex audio switch allowing any of x 
number input sources to play out of any x number of output sinks, all 
controlled via a python or php app.

You should check out module-combine-sink. You could combine all your 
outputs, then simply mute all but the one you currently want to use. I 
am using this as a 4x4 switch for audio and it works great.

I also have simple (but poorly commented) python/php source I am happy 
to share if it helps.

Matt


Nick Thompson wrote:
> OK so I figured out the error of my ways, but I have to say this list 
> is pretty unresponsive in helping the community so I have to ask 
> myself "is pulse is a sensible choice for audio development today"?   
> Particularly since there is little in the way of useful setup 
> documentation for actually using the library on a programatic way, the 
> error messages from the library and utilities are not particularly 
> helpful and so on. 
>
> What I need to be able to do is route audio around.  I suspect write a 
> module for pulse that will look at the alsa stream class and based on 
> that use the input index to set the sick for that stream.  It would be 
> nice to have a feature whereby I can rout all output sent to a 
> particular sink, to another sink.  I guess what I'd like to do is be 
> able to create virtual devices whose output can be changed on the fly. 
>  So for example I could define an mp3 output that I can switch between 
> headphone output and speaker output depending on a system setting.  Or 
> between one speaker output and another.  If pulse has a means to do 
> this already I'd appreciate someone pointing me in the direction that 
> can help.
>
> It seems ALSA will do most of this and the ALSA list seems to be a lot 
> more active, so maybe I was mistaken in thinking that Pulse would 
> really be a useful addition to our audio stack, particularly since on 
> an embedded system it consume disproportionate resources for the 
> benefit it provides.
>
> Also where is the mixer implemented and how is it controlled.  Or is 
> the mixer just a dumb "you have 3 streams coming in and I will make 
> them one" type deal.  In other words is there bussing or output 
> switching in the mixer.  If not, is this planned?
>
> Anyway, in case this helps anyone else, the sources that are listed by 
> list-sources are not really sources to pulse.  So trying to move them 
> around will not work.  Here's something I wrote up on the subject:
>
> To see the output devices we have created use the list-sinks command 
>
>   
>
> >>> list-sinks
> 2 sink(s) available.
>   * index: 0
>         name: <usbAudio>
>         driver: <modules/module-alsa-sink.c>
>         flags: LATENCY HARDWARE
>         state: IDLE
>         volume: <0: 100% 1: 100%>
>         mute: <0>
>         latency: <97959 usec>
>         monitor source: <0>
>         sample spec: <s16le 2ch 44100Hz>
>         channel map: <front-left,front-right>
>         used by: <0>
>         linked by: <0>
>         module: <0>
>         description: <ALSA PCM on usbLexiconAlpha (USB Audio) via DMA>
>     index: 1
>         name: <hdaAudio>
>         driver: <modules/module-alsa-sink.c>
>         flags: LATENCY HARDWARE
>         state: IDLE
>         volume: <0: 100% 1: 100%>
>         mute: <0>
>         latency: <75827 usec>
>         monitor source: <1>
>         sample spec: <s16le 2ch 44100Hz>
>         channel map: <front-left,front-right>
>         used by: <0>
>         linked by: <0>
>         module: <1>
>         description: <ALSA PCM on intelHDA (ALC883 Analog) via DMA>
>
>
>
>
> Currently no sound is playing, so if you look to see the sink inputs, 
> you'll see that none have currently been created:
>
>   
>
> >>> list-sink-inputs
> 0 sink input(s) available.
>
>
>
> Play a file in a different terminal window (or using your preferred 
> method to make sound).  For this experiment I used paplay:
>   
>
>
> nick at nick-desktop:~$ paplay -v  Sony\ CD-ROM\ Test\ Disk\ Type\ 
> 3.0/14\ Cantibile\ Op.\ 17.wav
> Using sample spec 's16le 2ch 44100Hz'
> Connection established.
> Stream successfully created
>
>
>
> I used the -v option to get verbose output from the command, which has 
> no bearing on this experiment.
>
> Now if you look at the sink inputs you can see that one has been 
> created for the stream we are currently rendering.
>
>   
>
> >>> list-sink-inputs
> 1 sink input(s) available.
>     index: 9
>         name: <Sony CD-ROM Test Disk Type 3.0/14 Cantibile Op. 17.wav>
>         driver: <pulsecore/protocol-native.c>
>         flags:
>         state: RUNNING
>         sink: <0> 'usbAudio'
>         volume: <0: 100% 1: 100%>
>         mute: <0>
>         latency: <500000 usec>
>         sample spec: <s16le 2ch 44100Hz>
>         channel map: <front-left,front-right>
>         resample method: auto
>         module: <3>
>         client: <7> 'paplay'
>
>
>
>
> By inspection it can be seen that this stream is being rendered on the 
> "usbAudio" device.  To switch this stream to the built-in audio source 
> is a straightforward operation, use the move-sync-input command in 
> pacmd.  We can see from the output above that the stream index is 9 
> (note that the index is incremented for each time a new stream is 
> created, so it has to be determined for each stream).
>
>   
>
> >>> move-sink-input 9 hdaAudio
>
>
>
> Now if the sink inputs are listed again you can see the output sink 
> has changed, verifying this by listening, the output does indeed get 
> switched.
>
>   
>
> >>> list-sink-inputs
> 1 sink input(s) available.
>     index: 9
>         name: <Sony CD-ROM Test Disk Type 3.0/14 Cantibile Op. 17.wav>
>         driver: <pulsecore/protocol-native.c>
>         flags:
>         state: RUNNING
>         sink: <1> 'hdaAudio'
>         volume: <0: 100% 1: 100%>
>         mute: <0>
>         latency: <500000 usec>
>         sample spec: <s16le 2ch 44100Hz>
>         channel map: <front-left,front-right>
>         resample method: auto
>         module: <3>
>         client: <7> 'paplay'
>  
>
>
>
>
> The api routines for this are in the file 
> /pulseaudio-0.9.8/src/pulse/introspect.c
>
> Look at these routines:
>
>   
>
> *int     pa_stream_connect_playback (pa_stream *s,const char *dev, 
> const pa_buffer_attr *attr, pa_stream_flags_t flags, pa_cvolume 
> *volume, pa_stream *sync_stream)*
>
> /     Connect the stream to a sink./
>
> *int     pa_stream_connect_record (pa_stream *s, const char *dev, 
> const pa_buffer_attr *attr, pa_stream_flags_t flags)*
>
> /     Connect the stream to a source./
> *int     pa_stream_disconnect (pa_stream *s)*
>
> /     Disconnect a stream from a source/sink./
>  
>  
>
>
>
>
> On May 1, 2008, at 11:14 AM, Nick Thompson wrote:
>
>> Hi there,
>>
>> I have a system where I need to move sources to different sinks 
>> according to a policy.  I thought I'd try this out using pacmd before 
>> I  start trying to code this up with pulse, put pacmd does not behave 
>> as expected (by me :).
>>
>> I tried the following command in pacmd:
>>
>> >>> move-sink-input 0 hdaAudio.monitor
>> No sink input found with this index.
>>
>> When I list the sinks and sources I get the output listed below.
>>
>> Is anyone familiar with pacmd.  According to the help, this looks as 
>> if it should work.
>>
>> Eventually I want to publish several virtual devices, route them to a 
>> mixer (possibly via an SRC) and route the mixer output to a specific 
>> ALSA sink.  I need two instances of mixers so that I can mix some 
>> streams to one output device and some streams to another.  I need to 
>> be able to dynamically rout the entire output to another ALSA sink 
>> depending on the policy set.  I'd also like to rout sources to the 
>> different mixer instances as required.  If I can do routing within a 
>> single mixer instance, so much the better.  Is Pulse capable of this 
>> or do I need to find another route to implement this.
>>
>> Thanks for any advice,
>>
>> Nick
>>
>> here is the output of list for sources and sinks:
>>
>> >>> list-sources
>> 3 source(s) available.
>>     index: 0
>>         name: <usbAudio.monitor>
>>         driver: <modules/module-alsa-sink.c>
>>         flags:
>>         state: IDLE
>>         volume: <0: 100% 1: 100%>
>>         mute: <0>
>>         latency: <0 usec>
>>         sample spec: <s16le 2ch 44100Hz>
>>         channel map: <front-left,front-right>
>>         used by: <0>
>>         linked by: <0>
>>         monitor_of: <0>
>>         module: <0>
>>         description: <Monitor Source of ALSA PCM on usbLexiconAlpha 
>> (USB Audio) via DMA>
>>     index: 1
>>         name: <hdaAudio.monitor>
>>         driver: <modules/module-alsa-sink.c>
>>         flags:
>>         state: IDLE
>>         volume: <0: 100% 1: 100%>
>>         mute: <0>
>>         latency: <0 usec>
>>         sample spec: <s16le 2ch 44100Hz>
>>         channel map: <front-left,front-right>
>>         used by: <0>
>>         linked by: <0>
>>         monitor_of: <1>
>>         module: <1>
>>         description: <Monitor Source of ALSA PCM on intelHDA (ALC883 
>> Analog) via DMA>
>>   * index: 2
>>         name: <alsa_input.hw_0>
>>         driver: <modules/module-alsa-source.c>
>>         flags: HW_VOLUME_CTRL LATENCY HARDWARE
>>         state: IDLE
>>         volume: <0:   0% 1:   0%>
>>         mute: <0>
>>         latency: <23219 usec>
>>         sample spec: <s16le 2ch 44100Hz>
>>         channel map: <front-left,front-right>
>>         used by: <0>
>>         linked by: <0>
>>         module: <2>
>>         description: <ALSA PCM on hw:0 (ALC883 Analog) via DMA>
>> >>>
>>
>> _______________________________________________
>> pulseaudio-discuss mailing list
>> pulseaudio-discuss at mail.0pointer.de 
>> <mailto:pulseaudio-discuss at mail.0pointer.de>
>> https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at mail.0pointer.de
> https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20080502/e8f7fee0/attachment.htm>


More information about the pulseaudio-discuss mailing list