1

For a personal sound project with a raspberry PI 3 and an USB 7.1 channel sound card, I need to use the sound card as 8 independents mono channels, to play different mono sounds on specifics channel. And sometime 2 or more mono sounds car be played (mixed) in the same time on a given channel. I finally found the way to do that in my .asoundrc configuration file :

pcm_slave.usbsoundcard {
pcm "hw:1"
rate 44100
channels 8
periods 128
period_time 0
period_size 1024
buffer_time 0
buffer_size 4096
}

pcm.ch1 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 0 ]
}

pcm.ch2 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 1 ]
}

pcm.ch3 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 6 ]
}

pcm.ch4 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 7 ]
}

pcm.ch5 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 2 ]
}

pcm.ch6 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 3 ]
}

pcm.ch7 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 4 ]
}

pcm.ch8 {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 5 ]
}

With this config file, I can play what I want on the channel I want, and I can play multiple sound in same time on each independent channel if needed with commands like this:

aplay -D plug:ch3 sound1_mono.wav &
aplay -D plug:ch3 sound2_mono.wav &  # sound 2 mixed with sound 1 on channel 3
aplay -D plug:ch7 sound3_mono.wav &
aplay -D plug:ch8 sound4_mono.wav &

etc...

But I want to add another possibility. I want to add a virtual channel named "all", which must route the played sound on ALL 8 mono channels. The final goal is to configure Asterisk pbx system configured as intercom to use this channel : when called, Asterisk will autoanswer, and I want voice routed (mixed) on all 8 channels of the sound card.

I naively tried that :

pcm.all {
type dmix
slave usbsoundcard
ipc_key 1001
bindings [ 0 1 2 3 4 5 6 7 ]
}

But it doesn't work. For testing I also play a mono sound on the 'all' virtual channel. If I do : aplay -D plug:all sound5_mono.wav The sound is correctly played on all channel ch1... ch8 where no other wav file is played. But on channel where a sound is already played, can't hear sound5_mono. wav but I have crackling noices

How can I write my. asoundrc file to have it working ? What I want to do is a kind of audio multiroom : play differents mono file on each channel ch1.... ch8 in differents room, and when I call the raspberry with a SIP phone, voice is played (mixed) in all rooms.

  • dmix has no channel limit. How exactly are you trying to use all? – CL. Jul 17 '16 at 11:19
  • Like this : aplay -D plug:all sound.wav ---> the goal is to have the sound mixed on all 8 mono channels ch1... ch8 of the usb sound card. – Cyril Haenel Jul 17 '16 at 11:44
  • In fact I want to build a kind of audio multiroom : 8 different sounds are played on channels 1 to 8 in 8 different rooms. And the virtual channel 'all' is used by asterisk as an intercom system : I can call the raspberry with a SIP phone, the raspberry autoanswers, and the voice must be played (mixed) in all room. – Cyril Haenel Jul 17 '16 at 12:14
  • How many channels does sound.wav have? One? Eight? Please edit the question to specify what exactly should happen with the channels. – CL. Jul 17 '16 at 14:37
  • Sound played on ch1 to ch8 can be mono or stereo (thus downmixed to mono, but it seems it's automatic with plug: ). This part already works well with the first config file. Sound on 'all' virtual channel will be played by Asterisk when it will answer calls, I don't know if it's mono or stereo. But if stereo, should be mixed to mono and routed/mixed on all 8 channels ch1 to ch8 – Cyril Haenel Jul 17 '16 at 17:32
0

I'm not sure if you can use different dmix definitions with the same ipc_key; it might be a better idea to use a common dmix device.

To be able to play a stero file to all channels, you have to convert it to mono first.

pcm.dmix8 {
    type dmix
    slave {
        pcm "hw:1"
        rate 44100
        channels 8
        period_size 1024
        buffer_size 32768
    }
}

pcm.ch1 {
    type plug
    slave.pcm dmix8
    ttable.0.0 1
}
pcm.ch2 {
    type plug
    slave.pcm dmix8
    ttable.0.1 1
}
# and so on with "ttable.0.x 1"

pcm.all {
    type plug
    slave {
        pcm {
            type route
            slave.pcm dmix8
            ttable [ [ 1 1 1 1 1 1 1 1 ] ]
        }
        channels 1
    }
}
  • I added an ipc_key in pcm.dmix8, if not present I have an error (ALSA lib pcm_direct.c:1707: (snd1_pcm_direct_parse_open_conf) Unique IPC key is not defined). And changed channels to 2 to try on my computer. ch1 and ch2 works as expected. But when playing a mono file to "all", there is an error : ALSA lib pcm_params.c:2162:(snd1_pcm_hw_refine_slave) Slave PCM not usable aplay: set_params:1204: Configuration erronée pour ce périphérique PCM: pas de configuration – Cyril Haenel Jul 18 '16 at 8:37
0

even if your last proposition doesn't work for virtual channel "all", it helped me a lot, and I tried something which works perfectly on my computer, with the same USB sound card.

Here is the config file :

pcm.dmix8 {
    type dmix
    ipc_key 1001
    slave {
        pcm "hw:2"
        rate 44100
        channels 8
        period_size 1024
        buffer_size 32768
    } }

pcm.ch1 {
    type plug
    slave.pcm dmix8
    ttable.0.0 1 }

pcm.ch2 {
    type plug
    slave.pcm dmix8
    ttable.0.1 1 }

pcm.ch3 {
    type plug
    slave.pcm dmix8
    ttable.0.6 1 }

pcm.ch4 {
    type plug
    slave.pcm dmix8
    ttable.0.7 1 }

pcm.ch5 {
    type plug
    slave.pcm dmix8
    ttable.0.4 1 }

pcm.ch6 {
    type plug
    slave.pcm dmix8
    ttable.0.5 1 }

pcm.ch7 {
    type plug
    slave.pcm dmix8
    ttable.0.6 1 }

pcm.ch8 {
    type plug
    slave.pcm dmix8
    ttable.0.7 1 }

pcm.all {
    type plug
    slave.pcm dmix8
    ttable.0.0 1
    ttable.0.1 1
    ttable.0.2 1
    ttable.0.3 1
    ttable.0.4 1
    ttable.0.5 1
    ttable.0.6 1
    ttable.0.7 1 }

With this config file, everything works as expected !! The channel "all" is used by Asterisk as a local softphone, and ch1...ch8 are used to play different mono sounds in 8 different rooms. And when I call Asterisk, it auto-answers and I can hear the voice in the 8 HP, mixed with existing sound of the room :)

Thank you very much for your help !

Next step, try on my raspberry PI 3 board, but no reason to have a different behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.