Audio device sharing on Linux

Some audio cards support hardware mixing. Such cards can be opened at the
same time from different applications natively. If this is not the case,
you will notice that is not possible to play music or process audio in
other applications while running SIP SIMPLE client SDK.

For audio cards that can be opened only once at a time, there are workarounds. More
information about them can be found in section 'The card does not support
hardware mixing', at http://alsa.opensrc.org/index.php/AlsaSharing

The Linux audio jungle

http://blogs.adobe.com/penguinswf/2007/05/welcome_to_the_jungle.html

Using dmix and dsnoop ALSA plugins

One of the workarounds is to modify /etc/asound.conf, for all uses in the
system, or ~/.asoundrc for the user that runs python-simsiple as follows:
Water Walls

pcm.card0 {
  type hw
  card 0
}
pcm.dmix0 {
  type dmix
  ipc_key 34521
  slave {
    pcm "card0" 
    rate 16000
    period_size 320
    buffer_size 10240
  }
}
pcm.dsnoop0 {
  type dsnoop
  ipc_key 34521
  slave {
    pcm "card0" 
    rate 16000
    period_size 320
    buffer_size 10240
  }
}
pcm.asym0 {
  type asym
  playback.pcm "dmix0" 
  capture.pcm "dsnoop0" 
}
pcm.pasym0 {
  type plug
  slave.pcm "asym0" 
}
pcm.dsp0 {
  type plug
  slave.pcm "asym0" 
}
ctl.dsp0 {
  type hw
  card 0
}
pcm.!default {
  type plug
  slave.pcm "pasym0" 
}
ctl.!default {
  type hw
  card 0
}

The above configuration sets as system default a special device called
pasym0 that uses asym, an ALSA plugin that combines the dsnoop input plugin
and dmix output into one full-duplex device. The dsnoop and dmix plugins
allows for concurrent access from multiple applications to the same physical
audio device for input and output respectively mixing and converting the
sample rates accordingly.

Note. It is important that other audio applications also access the same
virtual device, otherwise is still possible to block the access to the audio
card by opening it first from an application that does not use pasym0 as the
default device. For example is not possible to use this setup while other
applications use PulseAudio or other sound server that access the audio
device directly.

Using PulseAudio

Another workaround is to configure ALSA to route the requests the audio card
to the PulseAudio sound server, which in turn is performing the mixing from
all applications and accesses the audio device directly.

Modify /etc/asound.conf, for all uses in the system, or ~/.asoundrc for the
user that runs python-simsiple as follows:

pcm.pulse {
    type pulse
}
ctl.pulse {
    type pulse
}
pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

Note. PulseAudio introduces additional delay into the processing. This
solution offers more compatibility with other applications but is less
performant than when using dmix and dsnoop plugins.

This is not necessary with Ubuntu versions above 8.04.

Using PulseAudio with KDE

Distributions like Ubuntu ship with PulseAudio preinstalled when GNOME is the chosen desktop environment. On distributions where KDE is the default desktop environment (Kubuntu, for example) PulseAudio doesn't usually come installed since it was not stable enough.

Recently Kubuntu got KDE updated to version 4.5.0 which includes enhanced PulseAudio support in Phonon (KDEs multimedia API) and KMix (volume meter application).

Kubuntu users may update their systems to get PulseAudio working by doing the following:

  • Add the Kubuntu backports PPA repository and upgrade packages to KDE 4.5.0
    sudo add-apt-repository ppa:kubuntu-ppa/backports
    sudo apt-get update
    sudo apt-get dist-upgrade
    
  • Install PulseAudio
    sudo apt-get install pulseaudio pulseaudio-module-x11 pulseaudio-utils
    

After installing PulseAudio, restart your system. You should now be using PulseAudio. If you want to have a nice Plasmoid displaying the applications using audio at he moment install Veromix from here: http://kde-look.org/content/show.php/Veromix+-+A+Pulseaudio+volume+control?content=116676

Changing Devices fail

Some audio devices can be opened only at certain sample rates. Portaudio may fail to open them unless the sample rate is set to the native value of the device.

You may want to try setting up a different sample rate and then switch to the particular device until it works:

blink-settings -g set audio.sample_rate=RATE

Where RATE can be one of these values: 16000, 32000, 44100, 48000

8000 is usually always working but by using this value, is not possible to have wide-band audio experience when using G722 or speex codecs, they require a sample rate of 16000 or higher.

Example: A certain Logitech USB headset model can have its input device (the microphone) opened at 16000 HZ sample rate and the output device (the actual speaker) can be opened at 44100 HZ. You must set the sample rate to the lowest value of 16000.