The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Calling SDL_OpenAudio twice
Tomer Barletz
Guest

Hi,
I'm trying to play two audio files simultaneously by calling
SDL_OpenAudio twice with different SDL_AudioSpec.callback and
SDL_AudioSpec.userdata, but I still get the usual error:
"SDL_OpenAudio: Audio device is already opened"

What have I missed?

Fedora 10, SDL 1.2.

Thanks,
Tomer
Calling SDL_OpenAudio twice
Torsten Giebl
Guest

Hello !


Quote:
I'm trying to play two audio files simultaneously by calling
SDL_OpenAudio twice with different SDL_AudioSpec.callback and
SDL_AudioSpec.userdata, but I still get the usual error:
"SDL_OpenAudio: Audio device is already opened"

What have I missed?


Nothing, this is a limitation of SDL 1.2.
It can only open one audio channel at the time.
The same, as it can open only one window at the time.

Have a look at SDL 1.3. Most limitations are gone there.


CU
Calling SDL_OpenAudio twice
Tomer Barletz
Guest

Hi Torsten, and thanks for your reply.

On Tue, Feb 17, 2009 at 5:56 PM, Torsten Giebl <wizard at syntheticsw.com> wrote:
Quote:
Hello !


Quote:
I'm trying to play two audio files simultaneously by calling
SDL_OpenAudio twice with different SDL_AudioSpec.callback and
SDL_AudioSpec.userdata, but I still get the usual error:
"SDL_OpenAudio: Audio device is already opened"

What have I missed?


Nothing, this is a limitation of SDL 1.2.
It can only open one audio channel at the time.
The same, as it can open only one window at the time.

Have a look at SDL 1.3. Most limitations are gone there.


The thing is, that when I open two different instances of my
application - I do get two audio channels.
I also tested it with FFmpeg's player application - FFplay, which uses
SDL to render video and audio. Two instances of FFplay playing the
same file will work simultaneously.

Tomer
Calling SDL_OpenAudio twice
Torsten Giebl
Guest

Hello !


Quote:
The thing is, that when I open two different instances of my
application - I do get two audio channels.
I also tested it with FFmpeg's player application - FFplay, which uses
SDL to render video and audio. Two instances of FFplay playing the
same file will work simultaneously.


This is a different thing. Running two instances
(better to say two processes) of for example playwave
is different then opening two channels at the same time in one process.


CU
Calling SDL_OpenAudio twice
Stephen Anthony
Guest

On February 17, 2009 01:10:10 pm Torsten Giebl wrote:
Quote:
Hello !

Quote:
The thing is, that when I open two different instances of my
application - I do get two audio channels.
I also tested it with FFmpeg's player application - FFplay, which
uses SDL to render video and audio. Two instances of FFplay playing
the same file will work simultaneously.

This is a different thing. Running two instances
(better to say two processes) of for example playwave
is different then opening two channels at the same time in one
process.

How about opening the audio twice in the same program run, *after*
having closed it the first time? It works fine for me in all my
testing (with NVidia video hardware), but several people have reported
issues of it not working with ATI hardware.

I reported this a while back. Has anyone ever heard of this before??

SA
Calling SDL_OpenAudio twice
Tomer Barletz
Guest

On Tue, Feb 17, 2009 at 6:53 PM, Stephen Anthony <sa666666 at gmail.com> wrote:
Quote:
How about opening the audio twice in the same program run, *after*
having closed it the first time? It works fine for me in all my
testing (with NVidia video hardware), but several people have reported
issues of it not working with ATI hardware.

The thing is that I want to swap between those two sources multiple
times. I planned to do this by pausing one, then resuming the other,
which will be faster than repeatedly opening (allocating) and closing
(releasing) the channel.

Tomer
Calling SDL_OpenAudio twice
Torsten Giebl
Guest

Hello !


Quote:
How about opening the audio twice in the same program run, *after*
having closed it the first time? It works fine for me in all my
testing (with NVidia video hardware), but several people have reported
issues of it not working with ATI hardware.


I think he wants to play two sound files at the same time within
two channels. How would opening and closing audio help you in that case ?


CU
Calling SDL_OpenAudio twice
Pierre Phaneuf
Guest

On Tue, Feb 17, 2009 at 12:05 PM, Tomer Barletz <barletz at gmail.com> wrote:

Quote:
The thing is that I want to swap between those two sources multiple
times. I planned to do this by pausing one, then resuming the other,
which will be faster than repeatedly opening (allocating) and closing
(releasing) the channel.

Maybe what you need is SDL_mixer?

--
http://pphaneuf.livejournal.com/
Calling SDL_OpenAudio twice
Stephen Anthony
Guest

On February 17, 2009 01:35:31 pm Tomer Barletz wrote:
Quote:
On Tue, Feb 17, 2009 at 6:53 PM, Stephen Anthony <sa666666 at gmail.com>
wrote:
Quote:
Quote:
How about opening the audio twice in the same program run, *after*
having closed it the first time? It works fine for me in all my
testing (with NVidia video hardware), but several people have
reported issues of it not working with ATI hardware.

The thing is that I want to swap between those two sources multiple
times. I planned to do this by pausing one, then resuming the other,
which will be faster than repeatedly opening (allocating) and closing
(releasing) the channel.

Actually, I wasn't suggesting that approach, but asking if anyone had
seen the problems with ATI hardware that I'd found. But I can see how
I worded it as a suggestion :)

SA
Calling SDL_OpenAudio twice
Stephen Anthony
Guest

On February 17, 2009 01:38:12 pm Torsten Giebl wrote:
Quote:
Hello !

Quote:
How about opening the audio twice in the same program run, *after*
having closed it the first time? It works fine for me in all my
testing (with NVidia video hardware), but several people have
reported issues of it not working with ATI hardware.

I think he wants to play two sound files at the same time within
two channels. How would opening and closing audio help you in that
case ?

As in my previous response, it wouldn't. I didn't mean this to be a
suggestion; I was asking if anyone has seen similar problems with ATI
video cards, and opening the audio subsystem any time after it has been
closed once is not working.

SA
Calling SDL_OpenAudio twice
Torsten Giebl
Guest

Hello !


Quote:
As in my previous response, it wouldn't. I didn't mean this to be a
suggestion; I was asking if anyone has seen similar problems with ATI
video cards, and opening the audio subsystem any time after it has been
closed once is not working.


I am sorry then i misread it :-(

Can you put together a minimal example that shows
the problem or is there already one in Bugzilla ?

I know two people that have ATI cards, would
like to test it out on there computers.


CU
Calling SDL_OpenAudio twice
Stephen Anthony
Guest

On February 17, 2009 02:03:08 pm Torsten Giebl wrote:
Quote:
Hello !

Quote:
As in my previous response, it wouldn't. I didn't mean this to be
a suggestion; I was asking if anyone has seen similar problems with
ATI video cards, and opening the audio subsystem any time after it
has been closed once is not working.

I am sorry then i misread it :-(

Can you put together a minimal example that shows
the problem or is there already one in Bugzilla ?

I know two people that have ATI cards, would
like to test it out on there computers.

Sorry, I can't provide a test case right now, as this was reported by
end users with ATI hardware, and I don't have such hardware. That's
why I originally inquired about it; to see if anyone else has
experienced the same problem, and where I can possibly start in
tracking it down. In fact, I'm not even sure it's related to ATI
hardware (that seems to be the only constant with the people that are
having the problem).

SA
Calling SDL_OpenAudio twice
Donny Viszneki
Guest

On Tue, Feb 17, 2009 at 10:28 AM, Tomer Barletz <barletz at gmail.com> wrote:
Quote:
Hi,
I'm trying to [call] SDL_OpenAudio twice ...

What have I missed?

You cannot.

Most operating systems (or more accurately, the most common APIs to
get audio out of your application and into your computer's audio DAC)
do not allow you to open more than one audio stream to be plugged into
some separate mixer before being sent to your DAC (or, rather
similarly, sent to a unified device that does both mixing and DAC.)

The result is that if you want to play two sounds at the same time,
you need to mix them.

Are you playing music? Is your music comprised of multiple concurrent
sounds? Wonder how they were able to put multiple concurrent sounds
into the same audio track? Probably not, but it's called "mixing," and
if it isn't done ahead of time (because it probably cannot be done
ahead of time) then it has to be done just-in-time (in your
application.)

What kind of application are you working on? SDL may not be the most
appropriate choice if you're really only doing audio. I myself am
becoming quite fond of GStreamer (http://gstreamer.freedesktop.org/)
and if your application's primary programming challenges are things
like mixing multimedia streams, I recommend switching to GStreamer
immediately!

On the other hand, if you're writing a game, stick with SDL: writing a
mixer is not extremely complex, and can in fact be quite simple.

--
http://codebad.com/