Search code examples
linuxembeddedalsabuildrootlibasound

Define a clean and working asound.conf for my embedded device


I am currently using a very complex asound.conf file from a reference design BSP. I would like to define my own asound.conf.

My current need on my embedded device : Play mono files only with 44100 Hz rate. In speaker mode I have only one output speaker. When I plug a jack, I must able to hear the sound on both headphones. I need also to be able to record sound from a microphone in mono with 11500 Hz rate.

My available audio card :

# aplay  -l
**** List of PLAYBACK Hardware Devices ****
card 0: wm8960audio [wm8960-audio], device 0: HiFi wm8960-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: wm8960audio [wm8960-audio], device 1: HiFi-ASRC-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
# 

I am not using the same rate between output and input. But the ASRC device allows me to keep good performance with different rates. That's why I want to use device 1 and not device 0.

I tried to define my config as follow :

# cat /etc/asound.conf 
pcm_slave.out {
                pcm {
                        type hw
                        card 0
                        device 1
                }
                channels 2
                period_time 0
                period_size 512
                buffer_size 1024
                rate 44100
}

pcm.out_mono {
        ipc_key 1042
        type dmix
        slave out
        bindings.0 0
        bindings.0 1
}

pcm_slave.in {
                pcm {
                        type hw
                        card 0
                        device 1
                }
                channels 2
                rate 11025
}

pcm.in_mono {
        ipc_key 1043
        type dsnoop
        slave in
        bindings.0 1
}

Its working great with speaker (so with one speaker only) and cpu performance is very good. I play the sound using out_mono pcm. But I am able to hear the sound in one headphone only in jack mode when I used in_mono pcm. In the asound.conf I tried to say that I want to redirect the mono sound on both outputs but it is not working :

    bindings.0 0
    bindings.0 1

The second line of bindings is erasing the first one... So I am looking for a way to be able to hear the sound on two output. Of course, if I used default pcm instead of out_mono, the sound is working perfectly on both outputs.

Did I misunderstand something in asound conf definition?


Solution

  • The dmix plugin has a 1:1 mapping of its own channels to slave channels.

    To allow other conversions, use the plug plugin. Its bindings can be configured with ttable, but the defaults should be OK:

    pcm.out_mono {
        type plug
        slave.pcm {
            ipc_key 1042
            type dmix
            slave out
        }
    }