_razorsedge.org____________________________________________________
Home | People | Picture Gallery | Mailing Lists | News | Stats | Search
Docs | Software | Résumé | Humour | Contact Info

ALSA Software Mixing and Java

Mike Arnold

<mike at
  razorsedge dot org>

v200703041130, 04 March 2007


This page documents the fix I have been searching for, off and on, for many years. I use Softsqueeze to listen to my music on a Dell Optiplex GX260 running CentOS 4. Softsqueeze never allowed me to hear any other sounds that the system made while it was open. I would have to close the app to hear any other sounds. But it wasn't Softsqueeze that was causing the problem: it was Sun's Java and it's ALSA library.

It seems that Sun's ALSA library likes to grab the plughw:0,0 device instead of the default device. This bypasses any attempts at redefining the default device as a dmix plugin. Simply redefining plughw in a user's .asoundrc file solves our problem.

I was also getting some stuttering after redefining pcm.!plughw to be a dmix plugin, so I defined pcm.dmixer to solve it.


$ cat /etc/redhat-release
CentOS release 4.4 (Final)

$ rpm -qa|egrep '(java|alsa)'|sort
alsa-lib-1.0.6-5.RHEL4
alsamixergui-0.9.0-0.2.rc1.el4.kb
alsaplayer-0.99.76-3
alsa-utils-1.0.6-5
gcc-java-3.4.6-3
java-1.4.2-gcj-compat-1.4.2.0-27jpp
java-1.5.0-javadoc-1.5.0-1jpp
java-1.5.0-sun-1.5.0.10-2jpp
java-1.5.0-sun-alsa-1.5.0.10-2jpp
java-1.5.0-sun-devel-1.5.0.10-2jpp
java-1.5.0-sun-fonts-1.5.0.10-2jpp
java-1.5.0-sun-jce-policy-1.5.0-1jpp
java-1.5.0-sun-manual-1.5.0-1jpp
java-1.5.0-sun-plugin-1.5.0.10-2jpp

$ java -version
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 0: Intel ICH [Intel 82801DB-ICH4]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 4: Intel ICH - IEC958 [Intel 82801DB-ICH4 - IEC958]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ cat ~/.asoundrc
# ~/.asoundrc

# http://www.liddicott.com/~sam/?p=14
# Example /etc/asound.conf or ~/.asoundrc file showing how
# to configure ALSA so that a dmix plugin is used by default
#
# Make ALSA apps default to using dmix plugin instead of hw plugin
# (Exclamation point is needed in order to override the assignment to
# pcm.default in /etc/alsa/alsa.conf.)
pcm.!default {
    type plug
    #slave.pcm "dmix"
    slave.pcm "dmixer"
}
# Make OSS apps default to using dmix plugin too.
pcm.dsp0 {
    type plug
    #slave.pcm "dmix"
    slave.pcm "dmixer"
}
# I understand some things get cranky with no mixer defined.
ctl.mixer0 {
    type hw
    card 0
}

# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6271108
# Java Sound is broken.  Lets make it play nice with others.
# Softsqueeze finally shares the sound device!
pcm.!plughw {
    type plug
    #slave.pcm "dmix"
    slave.pcm "dmixer"
}

# http://alsa.opensrc.org/DmixPlugin#Still_Hearing_Stuttering.3F
# We have some stuttering.  Lets define larger period_size and buffer_size.
# Then we have to replace any "slave.pcm dmix" with "slave.pcm dmixer" above.
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        buffer_time 0
        period_size 2048
        buffer_size 32768
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}
ctl.dmixer {
    type hw
    card 0
}

Links: