alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* Playing multiple sounds at the same time
@ 2010-04-30 10:38 Andreas Falkenhahn
  2010-04-30 10:43 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Falkenhahn @ 2010-04-30 10:38 UTC (permalink / raw)
  To: alsa-devel

Hi,

I'm new to ALSA programming so please bear with me if the following
question is all too obvious. I did some research on my question before but
I didn't come across a clear answer.

What I want to do is really simple: Playing multiple sounds in different
formats at the same time. E.g.

Sound 1: 12345 hz, 8-bit signed, mono
Sound 2: 44100 hz, 16-bit unsigned, stereo
Sound 3: 8000 hz, 8-bit unsigned, stereo

Now I want to play sounds 1 to 3 at the same time. My question is now: Can
ALSA do automatic mixing for me here or do I have to do the mixing on my
own? In other words, can I simply feed all these three sound streams to
ALSA or do I have to mix them into a fourth audio stream first and feeding
this new fourth stream to ALSA then?

Thanks,

Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Playing multiple sounds at the same time
  2010-04-30 10:38 Playing multiple sounds at the same time Andreas Falkenhahn
@ 2010-04-30 10:43 ` Mark Brown
  2010-04-30 12:36   ` Andreas Falkenhahn
  2010-05-04  2:34   ` Raymond Yau
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Brown @ 2010-04-30 10:43 UTC (permalink / raw)
  To: Andreas Falkenhahn; +Cc: alsa-devel

On Fri, Apr 30, 2010 at 12:38:49PM +0200, Andreas Falkenhahn wrote:

> Now I want to play sounds 1 to 3 at the same time. My question is now: Can
> ALSA do automatic mixing for me here or do I have to do the mixing on my
> own? In other words, can I simply feed all these three sound streams to
> ALSA or do I have to mix them into a fourth audio stream first and feeding
> this new fourth stream to ALSA then?

The easiest thing for your application is to just open and play multiple
audio streams and allow a system mixing daemon such as PulseAudio to
take care of the mixing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Playing multiple sounds at the same time
  2010-04-30 10:43 ` Mark Brown
@ 2010-04-30 12:36   ` Andreas Falkenhahn
  2010-05-04  2:34   ` Raymond Yau
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Falkenhahn @ 2010-04-30 12:36 UTC (permalink / raw)
  To: Alsa-devel

> On Fri, Apr 30, 2010 at 12:38:49PM +0200, Andreas Falkenhahn wrote:
>
>> Now I want to play sounds 1 to 3 at the same time. My question is now:
>> Can
>> ALSA do automatic mixing for me here or do I have to do the mixing on my
>> own? In other words, can I simply feed all these three sound streams to
>> ALSA or do I have to mix them into a fourth audio stream first and
>> feeding
>> this new fourth stream to ALSA then?
>
> The easiest thing for your application is to just open and play multiple
> audio streams and allow a system mixing daemon such as PulseAudio to
> take care of the mixing.

Thanks, that sounds easy enough.

I have some more questions... I hope I don't annoy anyone but the API
documentation of ALSA is extremely brief and the tutorials I was able to
find via Google only deal with the most simple case, i.e. just playing a
stream and exiting.

So before I start implementing my sound backend in a totally wrong way,
I'd be thankful if one of the experts here could tell me if it could be
done like I'm planning it or not.

So here's my proposed implementation for playing multiple sounds at the
same time with ALSA:

1) Launch a new thread that will now act as my sound manager

2) For each new sound to be played, call snd_pcm_open() with mode set to
SND_PCM_NONBLOCK. Then set the parameters on this stream to match the
format of the sound to be played.

3) Now loop over all sounds currently playing and consecutively feed data
to their respective PCM streams using calls to snd_pcm_writei(). Check the
return value of snd_pcm_writei() to see how many frames could be written
to the stream, then feed the rest until there is no more data left or feed
again from the beginning in case the sound should be looped.

Well, this would be the outline of my planned implementation. Could it be
done this way or is there a better way?

Thanks,

Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Playing multiple sounds at the same time
  2010-04-30 10:43 ` Mark Brown
  2010-04-30 12:36   ` Andreas Falkenhahn
@ 2010-05-04  2:34   ` Raymond Yau
  2010-05-04  8:23     ` Andreas Falkenhahn
  1 sibling, 1 reply; 5+ messages in thread
From: Raymond Yau @ 2010-05-04  2:34 UTC (permalink / raw)
  To: ALSA Development Mailing List

2010/4/30 Mark Brown <broonie@opensource.wolfsonmicro.com>

> On Fri, Apr 30, 2010 at 12:38:49PM +0200, Andreas Falkenhahn wrote:
>
> > Now I want to play sounds 1 to 3 at the same time. My question is now:
> Can
> > ALSA do automatic mixing for me here or do I have to do the mixing on my
> > own? In other words, can I simply feed all these three sound streams to
> > ALSA or do I have to mix them into a fourth audio stream first and
> feeding
> > this new fourth stream to ALSA then?
>
> The easiest thing for your application is to just open and play multiple
> audio streams and allow a system mixing daemon such as PulseAudio to
> take care of the mixing.
>
>
Are you sure that your program can connect to PA server multilple times ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Playing multiple sounds at the same time
  2010-05-04  2:34   ` Raymond Yau
@ 2010-05-04  8:23     ` Andreas Falkenhahn
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Falkenhahn @ 2010-05-04  8:23 UTC (permalink / raw)
  To: alsa-devel

On 04.05.2010 at 10:34 Raymond Yau wrote:

>2010/4/30 Mark Brown <broonie@opensource.wolfsonmicro.com>
>
>> On Fri, Apr 30, 2010 at 12:38:49PM +0200, Andreas Falkenhahn wrote:
>>
>> > Now I want to play sounds 1 to 3 at the same time. My question is now:
>> Can
>> > ALSA do automatic mixing for me here or do I have to do the mixing on
>my
>> > own? In other words, can I simply feed all these three sound streams to
>> > ALSA or do I have to mix them into a fourth audio stream first and
>> feeding
>> > this new fourth stream to ALSA then?
>>
>> The easiest thing for your application is to just open and play multiple
>> audio streams and allow a system mixing daemon such as PulseAudio to
>> take care of the mixing.
>>
>>
>Are you sure that your program can connect to PA server multilple times ?

Yes, it's working fine. I can call snd_pcm_open() as many times as I want
and it is playing multiple streams in different sample formats at the same
time just fine.

Greets,

Andreas
--
"Remember: It's nice to be important but it's more important to be nice!"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-04  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-30 10:38 Playing multiple sounds at the same time Andreas Falkenhahn
2010-04-30 10:43 ` Mark Brown
2010-04-30 12:36   ` Andreas Falkenhahn
2010-05-04  2:34   ` Raymond Yau
2010-05-04  8:23     ` Andreas Falkenhahn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).