Bug 130593 - Default ALSA configuration should use asym [dmix] as the default device, but only for sound cards which really need it
Summary: Default ALSA configuration should use asym [dmix] as the default device, but ...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: alsa-lib
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Martin Stransky
QA Contact:
URL:
Whiteboard:
: 142378 (view as bug list)
Depends On: 158064
Blocks: 110117 FC4Target 147942
TreeView+ depends on / blocked
 
Reported: 2004-08-22 15:47 UTC by Mike Hearn
Modified: 2007-11-30 22:10 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-05-25 07:34:54 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Mike Hearn 2004-08-22 15:47:48 UTC
Description of problem:
Start two XMMS instances. Set them playing at once. The second will
not play.

Expected results:
dmix userspace mixing is used to allow them to play both at once.


Additional info:
You can make this work by copying /usr/share/alsa/alsa.conf to
/etc/alsa.conf and then setting the device in XMMS to "dmix" rather
than default but this is not the correct fix.

The correct fix is to set the ALSA "default" PCM device to use dmix.

This will allow sound-serverless mixing in userspace for ALSA apps.

Comment 1 Mike Hearn 2004-08-22 15:50:21 UTC
Oops, I meant "asym" as that allows both playback and recording, not
dmix sorry ... keeping dmix in the summary for search hits

Comment 2 Colin Walters 2004-09-21 21:10:17 UTC
Yeah, we really need to do this.  My impression is that ALSA makes it
fairly painful to do though.

I'm going to go ahead and move this to ASSIGNED, I hope Bill won't
jump on me :)

Comment 3 Colin Walters 2004-09-21 22:04:27 UTC
Here's some pages on this:

http://www.pseudorandom.co.uk/2004/debian/alsa/
http://gentoo-wiki.com/HOWTO_ALSA_sound_mixer_aka_dmix
http://www.thepenguin.org.uk/alsa/

Haven't looked in detail, but this looks doable as the default.

Comment 4 Colin Walters 2004-09-22 20:09:21 UTC
Ok, investigating a bit more, I see why using dmix is tricky.  We need
to pick a shmkey that is unique.  One solution might be to have a
little program that runs on X login and allocates the shmem segment
itself, and writes ~/.asoundrc, with a magic comment.  We barf if
~/.asoundrc already exists without the magic comment.

Still investigating.

Comment 5 Mike Hearn 2004-09-25 17:12:17 UTC
Hmm, are you sure? I seem to have used it before and never had to
think about shmkeys ... I guess the default worked.

Having said that, I've never run with dmix as the default. ALSA is
still a bit buggy in general so I tend to use the OSS emulation <doh>

Comment 6 Ralf Ertzinger 2004-10-29 14:59:44 UTC
I have the following in my ~/.asoundrc, and everything just magically
works (as long as it's using ALSA, that is.). FC3 is much better that
FC2 in this respect. Don't ask me what most of that stuff actually
does, though.

pcm.!default {
    type plug
    slave.pcm "dmixer"
}
 
pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}

pcm.dmixer  {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 8192
        # periods 128
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}
 
ctl.mixer0 {
    type hw
    card 0
}

Comment 7 Mike Hearn 2004-10-29 15:01:55 UTC
That isn't quite correct, it won't work for the case of multiple apps
attempting to record at once. You need to use the 'asym' plugin.

But yes that's the basic idea. The SHM key problem is a bit annoying
though. I wonder what the ALSA developers think about that?

Comment 8 Mike Hearn 2004-11-28 18:10:03 UTC
For FC3 just put this in /etc/asound.conf

pcm.!default {
        type plug
        slave.pcm "dmix"
}

In this case "dmix" should perhaps be "asym" however the default
config file does not set up asym. Should probably be fixed upstream.

Also kudzu would need to figure out if the sound card supports
hardware mixing and if not put this in the right place.

Comment 9 Mike Hearn 2004-11-28 18:10:48 UTC
Oh, final note, 1.0.7 may be needed to clear up some more dmix bugs.

Comment 10 Colin Walters 2004-12-09 15:37:57 UTC
*** Bug 142378 has been marked as a duplicate of this bug. ***

Comment 11 Alexandre Gomes 2004-12-22 14:10:53 UTC
I have to say that editing (in fact creating) /etc/asound.conf with
dmix, made mixing to work. Yet, at least in KDE, didn't test in gnome,
the sound something done strange, and xmms played 1-2 songs then
stoped without any error message.

Changing dmix to asym didn't work at all.

Yet the ~/asoundrc solution worked just fine to me. I do not record
anything so this is the best solution for me.

Comment 12 Colin Walters 2005-01-07 03:58:27 UTC
I worked a bit on this, more info here:
http://www.redhat.com/archives/fedora-desktop-list/2005-January/msg00011.html

Comment 13 Mike Hearn 2005-01-07 13:28:29 UTC
dmix is known to deadlock the audio pipeline in the version shipped in
FC3, that's probably what you're seeing Alexandre

Comment 14 Naadir Jeewa 2005-02-13 17:41:01 UTC
I find putting this in /etc/asound.conf works best. ipc_perm lets different
users access the plugins simultaneously.
I think the real problem is selecting the right card. Is this something for
kudzu to do?

#asym fun start here. we define one pcm device called "dmixed"
pcm.dmixed {
        ipc_key 1025
        ipc_perm 0666
        type dmix
        slave {
        pcm "hw:0,0"      # you cannot use a "plug" device here, darn.
        period_time 0
        period_size 1024  # must be power of 2
        buffer_size 16384
        }
}

#one called "dsnooped" for capturing
pcm.dsnooped {
        ipc_key 1027
        icp_perm 0666
        type dsnoop
        slave.pcm "hw:0,0"
}

#and this is the real magic
pcm.asymed {
        type asym
        playback.pcm "dmixed"
        capture.pcm "dsnooped"
}

#a quick plug plugin for above device to do the converting magic
pcm.pasymed {
        type plug
        slave.pcm "asymed"
}

#a ctl device to keep xmms happy
ctl.pasymed {
        type hw
        card 0
}

#for aoss:
pcm.dsp0 {
        type plug
        slave.pcm "asymed"
}

pcm.arts {
        type plug
        slave.pcm "asymed"
}

ctl.mixer0 {
        type hw
        card 0
}

pcm.!default {
    type plug
    slave.pcm "asymed"
}

#done


Comment 15 Martin Stransky 2005-04-12 15:29:50 UTC
First test version is here:

http://people.redhat.com/stransky/ainit/


Comment 16 Naadir Jeewa 2005-04-12 23:22:52 UTC
If i want to add dsnoop and asym, is it ok to just add %ipc_sem% again to
asoundrc.template to get a new key, or is that not possible yet?


Comment 17 Martin Stransky 2005-04-13 06:26:34 UTC
Yes, you can use dsnoop too, but you have to add all %% lines, not only %ipc_sem%.

Comment 18 Martin Stransky 2005-04-13 06:51:01 UTC
Here is small example for asoundrc.template with asym.
You have to change lines with "hw:1,0" and "hw:0,0" to your real record/playback
device.

pcm.!default {
        type plug
        slave.pcm "all"
}

pcm.dsp0 {
    type plug
    slave.pcm "all"
}

pcm.input {
    type dmix
    %ipc_sem%
    %ipc_mem_direct%
    %ipc_mem_plug%
    slave.pcm "hw:0,0"
}

pcm.output {
    type dsnoop
    %ipc_sem%
    %ipc_mem_direct%
    %ipc_mem_plug%
    slave {
            pcm "hw:1,0"
            channels 2
            period_size 1024
            buffer_size 4096
            rate 44100
            periods 0
            period_time 0
    }
    bindings {
            0 0
            0 1
    }
}

pcm.all {
        type asym
        playback.pcm "output"
        capture.pcm "input"
}


Comment 19 Naadir Jeewa 2005-04-27 17:35:02 UTC
Just to clarify, there's a typo in the above where dmix and dsnoop are
in the wrong places. 
asoundrc.template should be as follows:

pcm.!default {
    type plug
    slave.pcm "asym"
}

pcm.input {
        type dsnoop
        %ipc_sem%
        %ipc_mem_direct%
        %ipc_mem_plug%
        slave.pcm "hw:0,0"
}

pcm.asym {
        type asym
        playback.pcm "output"
        capture.pcm "input"
}

pcm.dsp0 {
        type plug
        slave.pcm "asym"
}


pcm.output  {
    type dmix
    %ipc_sem%
    %ipc_mem_direct%
    %ipc_mem_plug%
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 44100
    }
}

Comment 20 Marius Andreiana 2005-05-13 08:26:07 UTC
This was implemented with alsa 1.0.9rc2, in FC4t3 now. Ok to close?

Comment 21 Martin Stransky 2005-05-13 08:43:01 UTC
No, I have to hack system-config-soundcard, it writes only minimal configuration
to /etc/asound.conf and it turns off dmix/dsnoop for cards which need it.

My current solution in 1.0.2rc2 isn't very good and I'll improve it.

Comment 22 Martin Stransky 2005-05-13 13:45:26 UTC
http://people.redhat.com/stransky/alsa-dmix/alsa-lib-1.0.9rc2-5.src.rpm

This package uses dmix/dsnoop only if the card needs it. But you MUST
remove /etc/asound.conf and ~/.asoundrc.

Eventually (if you want to have the first card as the default one)
fill /etc/asound.conf with:

defaults.pcm.card 0
defaults.ctl.card 0


Comment 23 Kaj J. Niemi 2005-05-30 19:55:46 UTC
Either I'm not getting it or this doesn't work at all. With the newer alsa-libs
everything that uses esd locks up until you kill it if something else (such as
xlite, the soft phone client) attempts to play sound. This is on a T40p with
AC'97 audio (82801DBM).

Comment 24 Martin Stransky 2005-05-31 06:46:47 UTC
Your applications have to use the "default" device. Dmix doesn't work if you use
a hardware device (hw, plughw).


Note You need to log in before you can comment on or make changes to this bug.