Discussion:
newbie question about SDL_OpenAudio()
(too old to reply)
Yves Maurischat
2004-01-28 10:01:08 UTC
Permalink
Hi folks,

I am new to SDL and have some problems getting my app to work correctly.

I did quick glance into the archive of the mailing list, but didn't find
a post, that fully answers my questions (a search option would help a
lot ;-) ).
My app plays mp3 files (among some other proprietary formats). The
problem is, that it sounds funny. When I do SDL_OpenAudio() with the
desired and obtained parameters the obtained frequency is 48 kHz but my
desired (and I would say the standard) frequency for mp3 is 44,1 kHz ...
so what can I do to get correct output? Is this a driver problem with my
sounddevice?

Second, when I boot up my machine and try to play a song SDL_OpenAudio()
always returns with "No available audio device."
After starting XMMS (wich is based on OSS like SDL, too) and shutting it
down again, I have no problems playing the song with my app. A driver
problem, too?

I am using a self compiled version of SDL, version number is 1.2.6.

Greetings,

Yves
David Olofson
2004-01-28 11:03:10 UTC
Permalink
Post by Yves Maurischat
Hi folks,
I am new to SDL and have some problems getting my app to work
correctly.
I did quick glance into the archive of the mailing list, but didn't
find a post, that fully answers my questions (a search option would
help a lot ;-) ).
My app plays mp3 files (among some other proprietary formats). The
problem is, that it sounds funny. When I do SDL_OpenAudio() with
the desired and obtained parameters the obtained frequency is 48
kHz but my desired (and I would say the standard) frequency for mp3
is 44,1 kHz ... so what can I do to get correct output?
Resample to the rate you get. SDL does resampling internally, but only
by powers of two. There are various reasons for that, but IMHO, it's
just as well, as a poor resampler that steps when you least expect it
would suck, and a good resampler might burn more CPU power than some
users can spare.

One might assume that SDL should do that (and it does, with some
restrictions), but as high quality resampling is pretty much black
magic, and burns quite some CPU, IMHO it's actually better the way it
is.
Post by Yves Maurischat
Is this a
driver problem with my sounddevice?
Sort of. Although many cards run their converters at a fixed 48 kHz,
they usually do resampling in a DSP or something. (SB PCI512, Live!,
Audigy and related cards are examples of that kind of design.)

That's a pretty strange card you have, if it doesn't support 44.1 kHz
*at all*... Maybe it's a fixed 48 kHz card *without* a DSP? If you're
using such a card with a half finished Linux driver, it might not
implement resampling in the driver as intended. Or you just have a
broken driver.
Post by Yves Maurischat
Second, when I boot up my machine and try to play a song
SDL_OpenAudio() always returns with "No available audio device."
After starting XMMS (wich is based on OSS like SDL, too) and
shutting it down again, I have no problems playing the song with my
app. A driver problem, too?
Uh oh... Are you using the aRts sound daemon, by any chance? Unless
you have a multi-open (ie hardware mixing and resampling, like Live!,
Audigy etc) card, a sound daemon would steal your only PCM output and
set it as some rate - like 48 kHz. If SDL uses the daemon for output,
or uses it indirectly through some LD_PRELOAD hack (to intercept OSS
I/O), it depends on whether the daemon does resampling or not.
Post by Yves Maurischat
I am using a self compiled version of SDL, version number is 1.2.6.
That should be ok, I think. This definitely sounds like someone's
getting in the way of SDL.


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
Yves Maurischat
2004-01-28 12:19:40 UTC
Permalink
Post by David Olofson
Post by Yves Maurischat
Hi folks,
I am new to SDL and have some problems getting my app to work
correctly.
I did quick glance into the archive of the mailing list, but didn't
find a post, that fully answers my questions (a search option would
help a lot ;-) ).
My app plays mp3 files (among some other proprietary formats). The
problem is, that it sounds funny. When I do SDL_OpenAudio() with
the desired and obtained parameters the obtained frequency is 48
kHz but my desired (and I would say the standard) frequency for mp3
is 44,1 kHz ... so what can I do to get correct output?
Resample to the rate you get. SDL does resampling internally, but only
by powers of two. There are various reasons for that, but IMHO, it's
just as well, as a poor resampler that steps when you least expect it
would suck, and a good resampler might burn more CPU power than some
users can spare.
One might assume that SDL should do that (and it does, with some
restrictions), but as high quality resampling is pretty much black
magic, and burns quite some CPU, IMHO it's actually better the way it
is.
Hmm what exactly do you mean by resampling? I am not that deep into that
sound stuff. I am just porting the app to Linux for my employer *g*
Post by David Olofson
Post by Yves Maurischat
Is this a
driver problem with my sounddevice?
Sort of. Although many cards run their converters at a fixed 48 kHz,
they usually do resampling in a DSP or something. (SB PCI512, Live!,
Audigy and related cards are examples of that kind of design.)
That's a pretty strange card you have, if it doesn't support 44.1 kHz
*at all*... Maybe it's a fixed 48 kHz card *without* a DSP? If you're
using such a card with a half finished Linux driver, it might not
implement resampling in the driver as intended. Or you just have a
broken driver.
Well it's a "nForce2 AC97 AudioController (MCP)" on a mini-ITX board,
and SuSE 8.2 supports it. But I think I will talk about it to the system
administrator, as it seems, that it is not configured the right way...
Post by David Olofson
Post by Yves Maurischat
Second, when I boot up my machine and try to play a song
SDL_OpenAudio() always returns with "No available audio device."
After starting XMMS (wich is based on OSS like SDL, too) and
shutting it down again, I have no problems playing the song with my
app. A driver problem, too?
Uh oh... Are you using the aRts sound daemon, by any chance? Unless
you have a multi-open (ie hardware mixing and resampling, like Live!,
Audigy etc) card, a sound daemon would steal your only PCM output and
set it as some rate - like 48 kHz. If SDL uses the daemon for output,
or uses it indirectly through some LD_PRELOAD hack (to intercept OSS
I/O), it depends on whether the daemon does resampling or not.
Well.... yes, there's an aRts demon running (started by the KDE, I think).
But what exactly happens? I mean, XMMS blocks when my app is running and
vice versa... But why does XMMS work after bootup ans my app doesn't?
Shouldn't there be the same restrictions for XMMS as for my app?

Sorry for the dumb questions, but I am not that familiar with the sound
system of Linux....
Post by David Olofson
Post by Yves Maurischat
I am using a self compiled version of SDL, version number is 1.2.6.
That should be ok, I think. This definitely sounds like someone's
getting in the way of SDL.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
David Olofson
2004-01-28 13:07:28 UTC
Permalink
On Wednesday 28 January 2004 13.19, Yves Maurischat wrote:
[...]
Post by Yves Maurischat
Post by David Olofson
One might assume that SDL should do that (and it does, with some
restrictions), but as high quality resampling is pretty much
black magic, and burns quite some CPU, IMHO it's actually better
the way it is.
Hmm what exactly do you mean by resampling? I am not that deep into
that sound stuff. I am just porting the app to Linux for my
employer *g*
Converting from one sample rate to another.

The basic version is to just "stretch" or "compress" the data by
picking samples using a fractional index - the 1D version of scaling
an image with nearest pixel filtering. Problem is it sucks (at least)
as much as the graphics version...

You can use linear (a bit better), square (unusual) or cubic (pretty
good, but still fast) polynomial interpolation for better results,
but you still need a brickwall filter and/or oversampling to avoid
problems with sounds containing high frequencies.

Anyway, SDL can double or halve the sample rate a few times as needed,
but that's it. It won't use the "slow" fractional resampler
automatically, since that would result in output buffers with sizes
that are not powers of two, which is incompatible with some drivers.
Post by Yves Maurischat
Post by David Olofson
Post by Yves Maurischat
Is this a
driver problem with my sounddevice?
Sort of. Although many cards run their converters at a fixed 48
kHz, they usually do resampling in a DSP or something. (SB
PCI512, Live!, Audigy and related cards are examples of that kind
of design.)
That's a pretty strange card you have, if it doesn't support 44.1
kHz *at all*... Maybe it's a fixed 48 kHz card *without* a DSP?
If you're using such a card with a half finished Linux driver, it
might not implement resampling in the driver as intended. Or you
just have a broken driver.
Well it's a "nForce2 AC97 AudioController (MCP)" on a mini-ITX
board, and SuSE 8.2 supports it. But I think I will talk about it
to the system administrator, as it seems, that it is not configured
the right way...
AFAIK, the AC97 part is little more than a plain CODEC - no h/m
mixing, resampling or anything. Lots of cards use those though
(including the Live! and Audigy cards, IIRC), so it doesn't really
say much about the complete audio chipset's functionality.

I thought the nForce2 had accelerated 3D sound and stuff, though
(which would mean it does h/w mixing and resampling of multiple
channels) - but I could be mistaken... Or the Linux drivers just
don't support that part yet.
Post by Yves Maurischat
Post by David Olofson
Post by Yves Maurischat
Second, when I boot up my machine and try to play a song
SDL_OpenAudio() always returns with "No available audio device."
After starting XMMS (wich is based on OSS like SDL, too) and
shutting it down again, I have no problems playing the song with
my app. A driver problem, too?
Uh oh... Are you using the aRts sound daemon, by any chance?
Unless you have a multi-open (ie hardware mixing and resampling,
like Live!, Audigy etc) card, a sound daemon would steal your
only PCM output and set it as some rate - like 48 kHz. If SDL
uses the daemon for output, or uses it indirectly through some
LD_PRELOAD hack (to intercept OSS I/O), it depends on whether the
daemon does resampling or not.
Well.... yes, there's an aRts demon running (started by the KDE, I
think). But what exactly happens? I mean, XMMS blocks when my app
is running and vice versa... But why does XMMS work after bootup
ans my app doesn't? Shouldn't there be the same restrictions for
XMMS as for my app?
I suppose SDL is compiled without aRts support (you need some headers
and stuff for that) and XMMS uses the OSS or ALSA output plugins.
That would mean they both either bypass aRts through the driver
and/or h/w mixing (which doesn't seem to be the case), or both XMMS
and your SDL lib hit the OSS emulation that pipes their output to
aRts.

Why XMMS can get the stuff running and your app (or SDL) cannot beats
me, though.

I just don't use aRts, because it adds latency and causes trouble for
many apps, without really providing anything I need or want. (And
this is with an Audigy card! Seems like aRts somehow manages to kill
the multi-open + h/w mixing features... Oh, and that won't work with
mmap() I/O anyway, so Q3A and RTCW will just block stop in the audio
initialization if aRts is running.)


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
Yves Maurischat
2004-01-28 14:55:25 UTC
Permalink
Many thanks for your help!
Your guess with the driver was right. Seems like NVidia wasn't very
careful when coding it. Now I am using some other driver, and it works
fine.
Post by David Olofson
[...]
Post by Yves Maurischat
Post by David Olofson
One might assume that SDL should do that (and it does, with some
restrictions), but as high quality resampling is pretty much
black magic, and burns quite some CPU, IMHO it's actually better
the way it is.
Hmm what exactly do you mean by resampling? I am not that deep into
that sound stuff. I am just porting the app to Linux for my
employer *g*
Converting from one sample rate to another.
The basic version is to just "stretch" or "compress" the data by
picking samples using a fractional index - the 1D version of scaling
an image with nearest pixel filtering. Problem is it sucks (at least)
as much as the graphics version...
You can use linear (a bit better), square (unusual) or cubic (pretty
good, but still fast) polynomial interpolation for better results,
but you still need a brickwall filter and/or oversampling to avoid
problems with sounds containing high frequencies.
Anyway, SDL can double or halve the sample rate a few times as needed,
but that's it. It won't use the "slow" fractional resampler
automatically, since that would result in output buffers with sizes
that are not powers of two, which is incompatible with some drivers.
Post by Yves Maurischat
Post by David Olofson
Post by Yves Maurischat
Is this a
driver problem with my sounddevice?
Sort of. Although many cards run their converters at a fixed 48
kHz, they usually do resampling in a DSP or something. (SB
PCI512, Live!, Audigy and related cards are examples of that kind
of design.)
That's a pretty strange card you have, if it doesn't support 44.1
kHz *at all*... Maybe it's a fixed 48 kHz card *without* a DSP?
If you're using such a card with a half finished Linux driver, it
might not implement resampling in the driver as intended. Or you
just have a broken driver.
Well it's a "nForce2 AC97 AudioController (MCP)" on a mini-ITX
board, and SuSE 8.2 supports it. But I think I will talk about it
to the system administrator, as it seems, that it is not configured
the right way...
AFAIK, the AC97 part is little more than a plain CODEC - no h/m
mixing, resampling or anything. Lots of cards use those though
(including the Live! and Audigy cards, IIRC), so it doesn't really
say much about the complete audio chipset's functionality.
I thought the nForce2 had accelerated 3D sound and stuff, though
(which would mean it does h/w mixing and resampling of multiple
channels) - but I could be mistaken... Or the Linux drivers just
don't support that part yet.
Post by Yves Maurischat
Post by David Olofson
Post by Yves Maurischat
Second, when I boot up my machine and try to play a song
SDL_OpenAudio() always returns with "No available audio device."
After starting XMMS (wich is based on OSS like SDL, too) and
shutting it down again, I have no problems playing the song with
my app. A driver problem, too?
Uh oh... Are you using the aRts sound daemon, by any chance?
Unless you have a multi-open (ie hardware mixing and resampling,
like Live!, Audigy etc) card, a sound daemon would steal your
only PCM output and set it as some rate - like 48 kHz. If SDL
uses the daemon for output, or uses it indirectly through some
LD_PRELOAD hack (to intercept OSS I/O), it depends on whether the
daemon does resampling or not.
Well.... yes, there's an aRts demon running (started by the KDE, I
think). But what exactly happens? I mean, XMMS blocks when my app
is running and vice versa... But why does XMMS work after bootup
ans my app doesn't? Shouldn't there be the same restrictions for
XMMS as for my app?
I suppose SDL is compiled without aRts support (you need some headers
and stuff for that) and XMMS uses the OSS or ALSA output plugins.
That would mean they both either bypass aRts through the driver
and/or h/w mixing (which doesn't seem to be the case), or both XMMS
and your SDL lib hit the OSS emulation that pipes their output to
aRts.
Why XMMS can get the stuff running and your app (or SDL) cannot beats
me, though.
I just don't use aRts, because it adds latency and causes trouble for
many apps, without really providing anything I need or want. (And
this is with an Audigy card! Seems like aRts somehow manages to kill
the multi-open + h/w mixing features... Oh, and that won't work with
mmap() I/O anyway, so Q3A and RTCW will just block stop in the audio
initialization if aRts is running.)
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
Christophe Pallier
2004-01-28 14:06:00 UTC
Permalink
Post by Yves Maurischat
Hmm what exactly do you mean by resampling?
Doing a different interpolation in time:
For a software that works quite well if you really need to resample:
cf. http://ccrma-www.stanford.edu/~jos/resample/

--
Christophe Pallier
www.pallier.org
Continue reading on narkive:
Loading...