Multiple audio sources to single ALSA device on different bit rates

0

I am building a audio streamer based on linux for high quality audio. I have several applications that i want to be able to have acces to the audio device at the same time. (like shairport-sync, roon and music player daemon)

I have found the dmix plugin for ALSA which makes it possible to have two stream of audio mixed into one audio device. However, dmix requires me to set the sample rate when defining the dmix device and i need the sample rate to be variable depending on the sample rate that is being outputted from the source.

Is there a plugin that allows for switching between inputs? Or am I missing something in dmix?

Milan van Dijck

Posted 2018-07-31T09:55:03.023

Reputation: 33

2PulseAudio does this automatically, based on the first stream's sample rate. – CL. – 2018-07-31T10:17:03.217

1I'd second using PulseAudio for resampling/transport stuff - much easier to set up. – dirkt – 2018-07-31T11:17:51.080

Answers

1

You should use the rate (rate conversion) or plug (automatic conversion) plugins. See the list of alsa-lib plugins.

The configuration should be done in the alsa-lib configuration file located in the user's home (.asoundrc).

Rate

This plugin converts a stream rate. The input and output formats must be linear.

Example of use:

pcm.<name> {
        type rate
        slave <slave_name>
}

Plug

This plugin converts channels, rate and format on request.

Example of use:

pcm.<name> {
        type plug
        slave <slave_name>
}

Example using dmix and automatic conversion plugins

# Overwrites 'default'
pcm.!default {
    type plug
    slave.pcm "dmixer"
}

pcm.dmixer  {
    type dmix
    ipc_key 1024 # Any unique value for Interprocess Communication
    slave {
        pcm "hw:1,0"
        period_size 1024
        buffer_size 4096
        rate 44100
    }
}

Ricardo Biehl Pasquali

Posted 2018-07-31T09:55:03.023

Reputation: 111