tags:

views:

230

answers:

1

I'm using the ALSA dmix plugin on an embedded project, and mixing mp3 files by playing them with mpg321-alsa. In my asound.conf I've set my dmix sample rate to 44100Hz.

If I try to play any mp3 file sampled at a rate other than 44100Hz (or a rate that divides evenly into 44100Hz) then either the audio quality is degraded or even worse the start of the file is omitted. There's a random aspect to this: if I create an audio file that's say 300ms long and play it via mpg321-alsa then sometimes it plays OK and sometimes there's no sound at all.

Is this a known issue with dmix? Are there any workarounds, short of resampling the mp3 files?

+1  A: 

See the ALSA plugin documentation.

Note that the dmix plugin itself supports only a single configuration. That is, it supports only the fixed rate (default 48000), format (S16), channels (2), and period_time (125000). For using other configuration, you have to set the value explicitly in the slave PCM definition. The rate, format and channels can be covered by an additional plug plugin, but there is only one base configuration, anyway.

As an example (modify to fit your needs),

pcm.dsp0 {
    type plug
    slave.pcm "asym0"
    slave.rate 44100
}

pcm.asym0 {
    type asym
    playback.pcm "dmix0"
    capture.pcm "dsnoop0"
}

pcm.dmix0 {
    type dmix
    ipc_key 1024
    ipc_perm 0666
    slave {
        pcm {
            type hw
            card 0
            device 0
        }
        period_time 0
        period_size 1024
        buffer_size 65536
        format "S16_LE"
        periods 128
        rate 44100
    }
}

pcm.dsnoop0 {
    type dsnoop
    ipc_key 1025
    ipc_perm 0666
    slave.pcm {
        type hw
        card 0
        device 0
    }
}
ephemient
Thanks for this. I have a fairly similar config to the one you've shown above. I now wonder if I need to look at the buffering, though oddly the audio truncation is at the start not at the end. I've been through the ALSA documentation at http://alsa.opensrc.org/DmixPlugin but still think I'm missing something.
Simon Elliott