2005-05-17 09:59:50

by Karel Kulhavy

[permalink] [raw]
Subject: software mixing in alsa

Hello

http://www.math.tu-berlin.de/~sbartels/alsa/driver/driver.html says
"For example, there is currently ongoing work to allow mixing multiple
inputs to the pcm devices."

Does ALSA already support software mixing? If I run xmms with alsa
output plugin and then mpg123 into it, I get 'can't open /dev/dsp'
message.

Kernel version is 2.6.11-gentoo-r5

CL<


2005-05-17 10:08:13

by Jan Spitalnik

[permalink] [raw]
Subject: Re: software mixing in alsa

Dne ?t 17. kv?tna 2005 11:56 Karel Kulhavy napsal(a):
> Hello
>
> http://www.math.tu-berlin.de/~sbartels/alsa/driver/driver.html says
> "For example, there is currently ongoing work to allow mixing multiple
> inputs to the pcm devices."
>

Hi,

yes, ALSA can mix multiple inputs with its dmix plugin.
http://alsa.opensrc.org/index.php?page=DmixPlugin

bye,
spity

--
Jan Spitalnik
[email protected]

2005-05-17 14:16:45

by Karel Kulhavy

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, May 17, 2005 at 12:08:03PM +0200, Jan Spitalnik wrote:
> Dne ?t 17. kv?tna 2005 11:56 Karel Kulhavy napsal(a):
> > Hello
> >
> > http://www.math.tu-berlin.de/~sbartels/alsa/driver/driver.html says
> > "For example, there is currently ongoing work to allow mixing multiple
> > inputs to the pcm devices."
> >
>
> Hi,
>
> yes, ALSA can mix multiple inputs with its dmix plugin.
> http://alsa.opensrc.org/index.php?page=DmixPlugin

Thanks for your reply. I have proceeded according to this "Dmix Howto",
however it doesn't work. I have proceeded successfully up to the command
"aoss mpg123 some.mp3". When I run this, mp3 is played very fast, in
about 1-2 seconds (normal pitch, but skipping very fast forward).

mpg123 Version 0.59s-r9 (2000/Oct/27)
aoss doesn't have --version option
alsaplayer 0.99.76

The document doesn't contain any contact where to send bugreports that
the course described actually doesn't work.

Any other idea how to make Skype & XMMS run at the same time on Linux?

CL<

2005-05-17 18:32:52

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 2005-05-17 at 16:13 +0200, Karel Kulhavy wrote:
> On Tue, May 17, 2005 at 12:08:03PM +0200, Jan Spitalnik wrote:
> > Dne ?t 17. kv?tna 2005 11:56 Karel Kulhavy napsal(a):
> > > Hello
> > >
> > > http://www.math.tu-berlin.de/~sbartels/alsa/driver/driver.html says
> > > "For example, there is currently ongoing work to allow mixing multiple
> > > inputs to the pcm devices."
> > >
> >
> > Hi,
> >
> > yes, ALSA can mix multiple inputs with its dmix plugin.
> > http://alsa.opensrc.org/index.php?page=DmixPlugin
>
> Thanks for your reply. I have proceeded according to this "Dmix Howto",
> however it doesn't work. I have proceeded successfully up to the command
> "aoss mpg123 some.mp3". When I run this, mp3 is played very fast, in
> about 1-2 seconds (normal pitch, but skipping very fast forward).
>
> mpg123 Version 0.59s-r9 (2000/Oct/27)
> aoss doesn't have --version option
> alsaplayer 0.99.76
>
> The document doesn't contain any contact where to send bugreports that
> the course described actually doesn't work.
>
> Any other idea how to make Skype & XMMS run at the same time on Linux?

Yes, get the Skype developers to add proper ALSA support. If Doom 3
could do it, so can they.

mpg123 is an open source application so there's no excuse for it not to
support ALSA in 2005.

Finally, these questions are all OT for LKML. Try alsa-user at
lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
reporting system, linked from http://www.alsa-project.org.

Lee

2005-05-17 19:28:25

by Michal Schmidt

[permalink] [raw]
Subject: Re: software mixing in alsa

Lee Revell wrote:
> mpg123 is an open source application so there's no excuse for it not to
> support ALSA in 2005.

Its COPYING file says:
This software may be distributed freely, provided that it is
distributed in its entirety, without modifications, ...
This doesn't look like an open source license at all.
That's why Debian puts mpg123 in non-free.

Karel, you may want to try mpg321 instead. It already has ALSA support.

Michal

2005-05-17 19:27:53

by Karel Kulhavy

[permalink] [raw]
Subject: Re: software mixing in alsa

Lee Revell wrote:

> Finally, these questions are all OT for LKML. Try alsa-user at
> lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug

ALSA is a part of Linux kernel, right? This is linux-kernel. Why
is it OT here? Doesn't make sense for me.

CL<

> Lee

2005-05-17 19:34:56

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 2005-05-17 at 21:24 +0200, Karel Kulhavy wrote:
> Lee Revell wrote:
>
> > Finally, these questions are all OT for LKML. Try alsa-user at
> > lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
>
> ALSA is a part of Linux kernel, right? This is linux-kernel. Why
> is it OT here? Doesn't make sense for me.

Well, sort of. The parts of ALSA you are interested in (software mixing
and volume control) are implemented in userspace. They live in
alsa-lib.

You should at least cc: alsa-devel (non-subscribers can post) when
posting ALSA related questions to LKML.

Lee

2005-05-17 20:28:00

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 17 May 2005 21:24:12 +0200, Karel Kulhavy said:
> Lee Revell wrote:
>
> > Finally, these questions are all OT for LKML. Try alsa-user at
> > lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
>
> ALSA is a part of Linux kernel, right? This is linux-kernel. Why
> is it OT here? Doesn't make sense for me.

I was hoping somebody would explain how to get 'dmix' plugin working in the
kernel - then I could get rid of esd ;) (Note that running something in
userspace that accepts connections, runs dmix on them, and then creates one
thing spewing to /dev/pcm isn't a solution - I've already *got* esd, warts and all)


Attachments:
(No filename) (226.00 B)

2005-05-17 20:36:40

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 2005-05-17 at 16:27 -0400, [email protected] wrote:
> On Tue, 17 May 2005 21:24:12 +0200, Karel Kulhavy said:
> > Lee Revell wrote:
> >
> > > Finally, these questions are all OT for LKML. Try alsa-user at
> > > lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
> >
> > ALSA is a part of Linux kernel, right? This is linux-kernel. Why
> > is it OT here? Doesn't make sense for me.
>
> I was hoping somebody would explain how to get 'dmix' plugin working in the
> kernel - then I could get rid of esd ;) (Note that running something in
> userspace that accepts connections, runs dmix on them, and then creates one
> thing spewing to /dev/pcm isn't a solution - I've already *got* esd, warts and all)

I don't understand your message very well. The dmix plugin is part of
alsa-lib, which is part of userspace. From the application's point of
view, it does not matter whether the mixing happens in kernel or not.
ALSA follows the philosophy of doing as little as possible in the
kernel, and since mixing and volume control work fine in userspace,
that's where they live.

Lee

2005-05-17 21:08:16

by Karel Kulhavy

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, May 17, 2005 at 09:28:03PM +0200, Michal Schmidt wrote:
> Lee Revell wrote:
> >mpg123 is an open source application so there's no excuse for it not to
> >support ALSA in 2005.
>
> Its COPYING file says:
> This software may be distributed freely, provided that it is
> distributed in its entirety, without modifications, ...
> This doesn't look like an open source license at all.
> That's why Debian puts mpg123 in non-free.
>
> Karel, you may want to try mpg321 instead. It already has ALSA support.

Tried with the same result: fast forward.

CL<
>
> Michal

2005-05-17 21:36:42

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 2005-05-17 at 23:04 +0200, Karel Kulhavy wrote:
> On Tue, May 17, 2005 at 09:28:03PM +0200, Michal Schmidt wrote:
> > Lee Revell wrote:
> > >mpg123 is an open source application so there's no excuse for it not to
> > >support ALSA in 2005.
> >
> > Its COPYING file says:
> > This software may be distributed freely, provided that it is
> > distributed in its entirety, without modifications, ...
> > This doesn't look like an open source license at all.
> > That's why Debian puts mpg123 in non-free.
> >
> > Karel, you may want to try mpg321 instead. It already has ALSA support.
>
> Tried with the same result: fast forward.
>

Then the problem is probably with your ALSA configuration, or (less
likely) an ALSA bug. I suspect your MP3s are 44100 KHz and they are
being played at 48000 KHz. Please try ALSA CVS, there have been many
improvements since the version in the kernel. If the problem persists,
report it on the alsa-user list.

Lee

2005-05-17 23:35:33

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, 2005-05-17 at 17:36 -0400, Lee Revell wrote:
> On Tue, 2005-05-17 at 23:04 +0200, Karel Kulhavy wrote:
> > On Tue, May 17, 2005 at 09:28:03PM +0200, Michal Schmidt wrote:
> > > Lee Revell wrote:
> > > >mpg123 is an open source application so there's no excuse for it not to
> > > >support ALSA in 2005.
> > >
> > > Its COPYING file says:
> > > This software may be distributed freely, provided that it is
> > > distributed in its entirety, without modifications, ...
> > > This doesn't look like an open source license at all.
> > > That's why Debian puts mpg123 in non-free.
> > >
> > > Karel, you may want to try mpg321 instead. It already has ALSA support.
> >
> > Tried with the same result: fast forward.
> >
>
> Then the problem is probably with your ALSA configuration, or (less
> likely) an ALSA bug. I suspect your MP3s are 44100 KHz and they are
> being played at 48000 KHz.

OK, I found this bug report that describes the same problem:

https://bugtrack.alsa-project.org/alsa-bug/view.php?id=1098

The short answer is that you need to have mpg321 use the "plug:dmix"
device.

Lee

2005-05-18 06:30:24

by ross

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, May 17, 2005 at 04:27:44PM -0400, [email protected] wrote:
> I was hoping somebody would explain how to get 'dmix' plugin working in the
> kernel - then I could get rid of esd ;) (Note that running something in
> userspace that accepts connections, runs dmix on them, and then creates one
> thing spewing to /dev/pcm isn't a solution - I've already *got* esd, warts and all)


In all honesty - don't bother. esd does the job better, faster, more
flexibly, and without the hassle.

I have spent many hours attempting to get a usable dmix setup working
and I just don't think its possible (at least not with my hardware).

I use esd for all "consumer" level audio apps, and jackd for all
professional audio apps. This is by far the simplest way to manage
audio - I wouldn't waste your time with dmix. After all, what could
you do with dmix that you can't do with esd??


--
Ross Vandegrift
[email protected]

"The good Christian should beware of mathematicians, and all those who
make empty prophecies. The danger already exists that the mathematicians
have made a covenant with the devil to darken the spirit and to confine
man in the bonds of Hell."
--St. Augustine, De Genesi ad Litteram, Book II, xviii, 37

2005-05-18 08:42:55

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, 2005-05-18 at 02:30 -0400, [email protected] wrote:
> On Tue, May 17, 2005 at 04:27:44PM -0400, [email protected] wrote:
> > I was hoping somebody would explain how to get 'dmix' plugin working in the
> > kernel - then I could get rid of esd ;) (Note that running something in
> > userspace that accepts connections, runs dmix on them, and then creates one
> > thing spewing to /dev/pcm isn't a solution - I've already *got* esd, warts and all)
>
>
> In all honesty - don't bother. esd does the job better, faster, more
> flexibly, and without the hassle.
>

This problem is fixed with the upcoming ALSA 1.0.9 release - dmix will
"just work". It's been a big area of development lately.

Lee

2005-05-18 09:23:42

by Pavel Machek

[permalink] [raw]
Subject: Re: software mixing in alsa

Hi!

> > Finally, these questions are all OT for LKML. Try alsa-user at
> > lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
>
> ALSA is a part of Linux kernel, right? This is linux-kernel. Why
> is it OT here? Doesn't make sense for me.

You should use most specific list available. That's what they are
for. And it seems to me half of your problems is in userspace, so it
is indeed off-topic here.
Pavel

2005-05-18 13:25:44

by Karel Kulhavy

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, May 18, 2005 at 02:30:14AM -0400, [email protected] wrote:
> On Tue, May 17, 2005 at 04:27:44PM -0400, [email protected] wrote:
> > I was hoping somebody would explain how to get 'dmix' plugin working in the
> > kernel - then I could get rid of esd ;) (Note that running something in
> > userspace that accepts connections, runs dmix on them, and then creates one
> > thing spewing to /dev/pcm isn't a solution - I've already *got* esd, warts and all)
>
>
> In all honesty - don't bother. esd does the job better, faster, more
> flexibly, and without the hassle.

Is there some generic in-kernel support for mixing? I couldn't make
any of the userspace programs work.

I tried esd and it does the same as without esd - only one app gets to
the sound and the other waits. The only difference was only (horrible)
increase in sound latency.

Installed esd in gentoo by emerge, then added into the startiup scripts,
/etc/init.d/esd start, switched xmms over to esd and skype on start said
"using esd".

I would like to just run two sound programs concurrently. (Linux is a
time-sharing operating system, right?) I am not interested in a delay
line sound effect.

I also tried artsd and jack, but didn't succeed too.

CL<

2005-05-18 13:35:54

by Karel Kulhavy

[permalink] [raw]
Subject: Re: software mixing in alsa

On Tue, May 17, 2005 at 04:36:30PM -0400, Lee Revell wrote:

[...]

> alsa-lib, which is part of userspace. From the application's point of
> view, it does not matter whether the mixing happens in kernel or not.
> ALSA follows the philosophy of doing as little as possible in the
> kernel, and since mixing and volume control work fine in userspace,
> that's where they live.

Mixing is IMHO action that should be in kernel because

1) needs realtime scheduling to keep latency down
2) needs tight cooperation with the hardware to prevent dropouts
on underruns
3) Is a trivial linear algorithm involving memory blocks and linear
arithmetic, no complicated computations that are difficult to
check for BugFree(TM) so shouldn't present a great risk on kernel
stability
4) Fits into the kernel philosophy. Kernel is a program meant to provide
time-sharing access to limited hardware resource. Sound card is a
limited hardware resource.
5) From the knowledge of the exact hardware, the mixing routine in
kernel can know maximum allowable levels etc. to prevent clipping.


CL<

2005-05-18 13:45:15

by Takashi Iwai

[permalink] [raw]
Subject: Re: software mixing in alsa

At Tue, 17 May 2005 19:32:22 -0400,
Lee Revell wrote:
>
> On Tue, 2005-05-17 at 17:36 -0400, Lee Revell wrote:
> > On Tue, 2005-05-17 at 23:04 +0200, Karel Kulhavy wrote:
> > > On Tue, May 17, 2005 at 09:28:03PM +0200, Michal Schmidt wrote:
> > > > Lee Revell wrote:
> > > > >mpg123 is an open source application so there's no excuse for it not to
> > > > >support ALSA in 2005.
> > > >
> > > > Its COPYING file says:
> > > > This software may be distributed freely, provided that it is
> > > > distributed in its entirety, without modifications, ...
> > > > This doesn't look like an open source license at all.
> > > > That's why Debian puts mpg123 in non-free.
> > > >
> > > > Karel, you may want to try mpg321 instead. It already has ALSA support.
> > >
> > > Tried with the same result: fast forward.
> > >
> >
> > Then the problem is probably with your ALSA configuration, or (less
> > likely) an ALSA bug. I suspect your MP3s are 44100 KHz and they are
> > being played at 48000 KHz.
>
> OK, I found this bug report that describes the same problem:
>
> https://bugtrack.alsa-project.org/alsa-bug/view.php?id=1098

This sounds similar, but I guess it's different.

> The short answer is that you need to have mpg321 use the "plug:dmix"
> device.

The recent libao opens "default" PCM. So, dmix should work without
any changes when you install ALSA 1.0.9(rc3).


Takashi

2005-05-18 13:50:32

by Takashi Iwai

[permalink] [raw]
Subject: Re: software mixing in alsa

At Tue, 17 May 2005 16:27:44 -0400,
[email protected] wrote:
>
> On Tue, 17 May 2005 21:24:12 +0200, Karel Kulhavy said:
> > Lee Revell wrote:
> >
> > > Finally, these questions are all OT for LKML. Try alsa-user at
> > > lists.sf.net and alsa-devel at lists.sf.net. Also there's a bug
> >
> > ALSA is a part of Linux kernel, right? This is linux-kernel. Why
> > is it OT here? Doesn't make sense for me.
>
> I was hoping somebody would explain how to get 'dmix' plugin working in the
> kernel - then I could get rid of esd ;)

esd is working fine together with dmix. You should try the latest
versions (of esd and alsa-lib). The old version of esd might have a
bug.

arts had a problem, but got fixed in the recent version of alsa-lib.


Takashi

2005-05-18 13:55:47

by Jaroslav Kysela

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, 18 May 2005, Karel Kulhavy wrote:

> On Tue, May 17, 2005 at 04:36:30PM -0400, Lee Revell wrote:
>
> [...]
>
> > alsa-lib, which is part of userspace. From the application's point of
> > view, it does not matter whether the mixing happens in kernel or not.
> > ALSA follows the philosophy of doing as little as possible in the
> > kernel, and since mixing and volume control work fine in userspace,
> > that's where they live.
>
> Mixing is IMHO action that should be in kernel because
>
> 1) needs realtime scheduling to keep latency down

With a realtime scheduler and properly written drivers (no "schedule"
gaps) you'll reach same results. For x86 we use special instructions like
xchg and locking-free algorithm in dmix, so the latency is SAME for all
concurent apps with minimal overhead..

> 2) needs tight cooperation with the hardware to prevent dropouts
> on underruns

Yes, but having the code which computes something in interrupt is not
sane.

> 3) Is a trivial linear algorithm involving memory blocks and linear
> arithmetic, no complicated computations that are difficult to
> check for BugFree(TM) so shouldn't present a great risk on kernel
> stability

You need to write complete new virtual layer or use a new special driver
which connect to real soundcard. Thats a lot of new code - it's better to
do it safely in the user space.

> 4) Fits into the kernel philosophy. Kernel is a program meant to provide
> time-sharing access to limited hardware resource. Sound card is a
> limited hardware resource.

Why X drivers aren't in kernel, too? Because they're big and kernel should
drive the real bottom of hardware (interrupts, DMA, memory mapping), but
abstraction (which sound mixing _IS_) should be implemented in the user
space. Otherwise we will end up with a huge kernel implementing nearly
everything...

> 5) From the knowledge of the exact hardware, the mixing routine in
> kernel can know maximum allowable levels etc. to prevent clipping.

You can obtain all necessary info in the userspace as well.

We should definitely fix the dmix bugs. Or, if you want, you might buy
an accelerated soundcard which supports multiple streams in hardware.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

2005-05-18 14:38:49

by Pierre Ossman

[permalink] [raw]
Subject: Re: software mixing in alsa

Takashi Iwai wrote:
>
> esd is working fine together with dmix. You should try the latest
> versions (of esd and alsa-lib). The old version of esd might have a
> bug.
>

I'd beg to differ. I have to apply the patch made by you to avoid
getting a lot of distortions with esound and dmix:

http://bugzilla.gnome.org/show_bug.cgi?id=140803

Checking in the cvs, this still hasn't been commited.

Rgds
Pierre

2005-05-18 14:01:25

by Nix

[permalink] [raw]
Subject: Re: software mixing in alsa

On 18 May 2005, [email protected] uttered the following:
> I use esd for all "consumer" level audio apps, and jackd for all
> professional audio apps. This is by far the simplest way to manage
> audio

In my experience, polypaudio replaces esd with something both simpler
and more powerful. (Oh, and without esd's *horrible* stutter,
interruption, mis-authentication, and code cleanliness problems.)

(For the professional stuff there is no replacement for JACK, I agree.)

--
`End users are just test loads for verifying that the system works, kind of
like resistors in an electrical circuit.' - Kaz Kylheku in c.o.l.d.s

2005-05-18 17:47:33

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, 2005-05-18 at 15:53 +0200, Jaroslav Kysela wrote:
> On Wed, 18 May 2005, Karel Kulhavy wrote:
>
> > On Tue, May 17, 2005 at 04:36:30PM -0400, Lee Revell wrote:
> >
> > [...]
> >
> > > alsa-lib, which is part of userspace. From the application's point of
> > > view, it does not matter whether the mixing happens in kernel or not.
> > > ALSA follows the philosophy of doing as little as possible in the
> > > kernel, and since mixing and volume control work fine in userspace,
> > > that's where they live.
> >
> > Mixing is IMHO action that should be in kernel because
> >
> > 1) needs realtime scheduling to keep latency down
>
> With a realtime scheduler and properly written drivers (no "schedule"
> gaps) you'll reach same results. For x86 we use special instructions like
> xchg and locking-free algorithm in dmix, so the latency is SAME for all
> concurent apps with minimal overhead..

Also doing it in userspace lets us use SSE/MMX.

Lee

2005-05-18 18:31:11

by Lee Revell

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, 2005-05-18 at 16:38 +0200, Pierre Ossman wrote:
> Takashi Iwai wrote:
> >
> > esd is working fine together with dmix. You should try the latest
> > versions (of esd and alsa-lib). The old version of esd might have a
> > bug.
> >
>
> I'd beg to differ. I have to apply the patch made by you to avoid
> getting a lot of distortions with esound and dmix:
>
> http://bugzilla.gnome.org/show_bug.cgi?id=140803
>
> Checking in the cvs, this still hasn't been commited.

You really need to bug the Gnome developers about it. Takashi-san
posted the patch in January, and the bug is still listed as NEW.

Lee

2005-05-19 15:38:57

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: software mixing in alsa

On Wed, 18 May 2005 16:38:01 +0200, Pierre Ossman said:

> I'd beg to differ. I have to apply the patch made by you to avoid
> getting a lot of distortions with esound and dmix:
>
> http://bugzilla.gnome.org/show_bug.cgi?id=140803
>
> Checking in the cvs, this still hasn't been commited.

I owe Takashi a beer for creating the patch, and Pierre for bringing it
to my attention - it solves the issue I was seeing on Fedora Core where
alsa 1.0.9rc2 was hosing up esd.


Attachments:
(No filename) (226.00 B)