3

After my first configuration war against alsa (won with the help of CL.) check this question ...

I would now want to go further :

I am able to play multi-channel sounds on my setup, but I now need to play them simultaneously !

I found out that using dmix should help me, but I still have issue setting the correct asound.conf file, here the different solutions I tried and their respective results :

Initial (working with multi-channel but not simultaneously) asound.conf :

pcm.!default {
       type asym
    playback.pcm {
        type plug
        slave.pcm "surround40:CA0106"
    }
    capture.pcm {
        type plug
        slave.pcm "hw:CA0106"
    }
}

Initial (Playing simultaneously but not multi-channel, only 2 channel here) asound.conf :

pcm.dmixed {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    slave.pcm "hw:CA0106"
}

pcm.duplex {
    type asym
    playback.pcm "dmixed"
}

# Instruct ALSA to use pcm.duplex as the default device
pcm.!default {
    type plug
    slave.pcm "duplex"
}

Note about the above setup This asound.conf allows me to play simultaneously 2 sounds, but only on 2 channel, I lost the multi-channel capacity...

Also, some sounds that used to work with my initial asound.conf (the first excerpt above) does not work anymore with this asound.conf, here is the fail message :

[root@server Sons]# aplay -N Apparition.wav
Playing WAVE 'Apparition.wav' : Signed 32 bit Little Endian, Rate 22050 Hz, Channels 4
aplay: set_params:1015: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: 32
FRAME_BITS: 128
CHANNELS: 4
RATE: NONE
PERIOD_TIME: 125000
PERIOD_SIZE: NONE
PERIOD_BYTES: (44096 44112)
PERIODS: (1 2)
BUFFER_TIME: (249977 249978)
BUFFER_SIZE: 5512
BUFFER_BYTES: 88192
TICK_TIME: 0

And one working sound example :

[root@server Sons]# aplay -vN Disparition.wav                                   
Playing WAVE 'Disparition.wav' : Signed 32 bit Little Endian, Rate 22254 Hz, Channels 4 
Plug PCM: Route conversion PCM (sformat=S32_LE)                                         
  Transformation table:                                                                 
    0 <- 0                                                                              
    1 <- 1                                                                              
Its setup is:                                                                           
  stream       : PLAYBACK                                                               
  access       : RW_INTERLEAVED                                                         
  format       : S32_LE                                                                 
  subformat    : STD                                                                    
  channels     : 4                                                                      
  rate         : 22254                                                                  
  exact rate   : 22254 (22254/1)                                                        
  msbits       : 32                                                                     
  buffer_size  : 5563                                                                   
  period_size  : 2781                                                                   
  period_time  : 125000                                                                 
  tstamp_mode  : NONE                                                                   
  period_step  : 1                                                                      
  avail_min    : 2781                                                                   
  period_event : 0                                                                      
  start_threshold  : 5563                                                               
  stop_threshold   : 5563                                                               
  silence_threshold: 0                                                                  
  silence_size : 0                                                                      
  boundary     : 729153536                                                              
Slave: Rate conversion PCM (48000, sformat=S16_LE)                                      
Its setup is:                                                                           
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 22254
  exact rate   : 22254 (22254/1)
  msbits       : 32
  buffer_size  : 5563
  period_size  : 2781
  period_time  : 125000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 2781
  period_event : 0
  start_threshold  : 5563
  stop_threshold   : 5563
  silence_threshold: 0
  silence_size : 0
  boundary     : 729153536
Slave: Direct Stream Mixing PCM
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 12000
  period_size  : 6000
  period_time  : 125000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 6000
  period_event : 0
  start_threshold  : 12000
  stop_threshold   : 12000
  silence_threshold: 0
  silence_size : 0
  boundary     : 1572864000
Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 12000
  period_size  : 6000
  period_time  : 125000
  tstamp_mode  : ENABLE
  period_step  : 1
  avail_min    : 6000
  period_event : 0
  start_threshold  : 1
  stop_threshold   : 1572864000
  silence_threshold: 0
  silence_size : 1572864000
  boundary     : 1572864000

I am using the "-N" option to get some very short sounds to play one after the other very quickly, I cannot get rid of this action.

To make long story short, I am looking for an asound.conf file which would allow me to keep the multi-channel capacity but that would also allow me to simultaneously play 2 different sounds.

Among the 2 sounds there is one using the 2 front speakers and the other one using the 2 rear speakers, both sounds are build using 4 channels with 2 channels (front or rear depending on the sound) blank.

From my little understanding I would need to specify a "custom device" (plug type or any other type ?) first and then "dmix" them, because I tried to changed the slave.pcm hardware address inside the pcm.dmixed block but this gives me an error stating that the type was not correct for this block (or something similar, I can provide the exact message if needed...)

hw:CA0106

to

surround40:CA0106

Any information and idea are welcome to help me solve that problem.

UPDATE_1 : Following CL. advices, I built this asound.conf :

pcm.dmixed {
        type dmix
        ipc_key 1024
        ipc_key_add_uid 0
        slave {
                pcm "hw:0,0"
                channels 4
        }
}

pcm.dmixed2 {
        type dmix
        ipc_key 1025
        ipc_key_add_uid 0
        slave {
                pcm "hw:0,1"
                channels 4
        }
}



pcm.quad {
        type multi

        slave.pcm "dmixed"
        slave.pcm "dmixed2"
}

# Instruct ALSA to use pcm.quad as the default device
pcm.!default {
    type plug
    slave.pcm "quad"
}

But it's still not working ... It fails with this error :

ALSA lib pcm_multi.c:1042:(_snd_pcm_multi_open) Unknown field slave

Looks like I am missing a slave definition but I can't find where ...

UPDATE_2 : Here my latest "almost" working file, thanks to CL., I am still having a sound played in 2 parts (see comments for more info), but it is still better than nothing..

pcm.!default {                         # The "!" is used to overwrite an existing definition (pcm.default in this case ...)
        type asym
    playback.pcm {
        type plug                      # plug is the "automatic conversion" plugin : convert data rate, channel and format on demand
        slave.pcm "quad"
    }
}


pcm.dmix_front {                        # Define the front speakers device : hw:0,0
    type dmix
    ipc_key 12345
    ipc_key_add_uid 0
    slave.pcm "hw:0,0"
}
pcm.dmix_rear {                         # Define the rear speakers device : hw:0,1
    type dmix
    ipc_key 67890
    ipc_key_add_uid 0
    slave.pcm "hw:0,1"
}
pcm.quad {
    type multi
    slaves {
        a { pcm dmix_front channels 2 }
        b { pcm dmix_rear  channels 2 }
    }
    bindings [
        { slave a channel 0 }
        { slave a channel 1 }
        { slave b channel 0 }
        { slave b channel 1 }
    ]
}

I finally went for the use of plug:dmix_front and plug:dmix_front from my app.

Thank you CL. for your kind support and patience.

4
  • The CA0106 chip has two independent devices for front and rear, so you need to create two dmix devices on top of those, and combine them with multi.
    – CL.
    Apr 11, 2014 at 11:31
  • Thank you CL., I am going to try to set this up by my own.
    – Pier
    Apr 11, 2014 at 14:18
  • CL., I am unable to make it works, if you'd be kind enough to give me a working example that would be very helpful (as we are about to start the validation test today !)
    – Pier
    Apr 14, 2014 at 7:38
  • Unknown field slave means that you must not use an entry named slave.
    – CL.
    Apr 14, 2014 at 9:21

1 Answer 1

1

According to the documentation, something like this should work:

pcm.dmix_front {
    type dmix
    ipc_key 12345
    ipc_key_add_uid 0
    slave.pcm "hw:0,0"
}
pcm.dmix_rear {
    type dmix
    ipc_key 67890
    ipc_key_add_uid 0
    slave.pcm "hw:0,1"
}
pcm.quad {
    type multi
    slaves {
        a { pcm dmix_front channels 2 }
        b { pcm dmix_rear  channels 2 }
    }
    bindings [
        { slave a channel 0 }
        { slave a channel 1 }
        { slave b channel 0 }
        { slave b channel 1 }
    ]
}
7
  • Thanks a lot CL., once again you saved a part of my day! I now got what I missed in my asound.conf, I (of course) read the ALSA doc to which you linked, but the multi plugin syntax was a bit 'too much' for me (and obviously English is not my first language...).
    – Pier
    Apr 14, 2014 at 10:41
  • I am still having an issue as my goal is to play one sound to rear speakers while playing another sound to front speakers, which is not happening with this config, I already tried some variation around the config file you provided me with (CL.) but I still cannot get them play as expected ...
    – Pier
    Apr 14, 2014 at 11:01
  • ALSA Noob speaking ! So I am now able to play sounds as exepected (almost) my last problem is now that one of the 2 sound is cut, by cut I mean that it is played but in 2 parts : The first part is played then blank then the second part is played .... It might be needing some custom parameter, CL. or anyone else : if you have any idea ?
    – Pier
    Apr 14, 2014 at 11:52
  • To play to front and rear separately, you don't need to combine them; just use the plug:front and plug:rear devices. (Or use plug:dmix_front if you need multiple sounds on the same device.)
    – CL.
    Apr 14, 2014 at 12:10
  • These 2-part sounds are a separate question.
    – CL.
    Apr 14, 2014 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .