Looking for advice for creating proper Sound_AudioInfo

Eric Wing ewing2121 at yahoo.com
Wed Oct 1 12:35:01 EDT 2003


Hi, I seemed to have boxed myself into a little corner
and I was hoping to get some advice.

I am using SDL_sound to decode stuff for use with
OpenAL. My strategy is to use SDL_sound to open and
process the data and then pass it off to an
alBufferData. I wished to load the file closest to the
"actual" file settings in hopes of minimizing the
amount of work SDL_sound has to do and pass the buck
to OpenAL and potential hardware acceleration. So if
the file was an 8bit,11khz sample, SDL_sound would
decode it that way, and OpenAL would do the work it
may have to do to play it (which might involve some
upsampling).

So when I fill out my Sound_AudioInfo for the desired
target, I want to do as few conversions as possible.
So I start by setting:
Sound_AudioInfo target;
target.format = 0;
target.channels = 0;
target.rate = 0;

This would tell SDL_sound to use the sound file's
actual values.

However, I learned the hardway that I must set the
bit-depth/endian order to match the system I'm running
on. So I need to fill out the target.format field
correctly.

The problem is that this value also depends on the
data itself. If the sample has an 8-bit bitdepth, then
should use the actual.format. But with a 16-bit
format, then I need to pick AUDIO_U16SYS or
AUDIO_S16SYS depending on the signedness.

So in order to fill out the format correctly, I needed
to open the file first with Sound_NewSample() and then
let it tell me what bit depth and signedness the
original file was. Then I could decide what to put in
my target.format
if(bit == 8) {
  target.format = sound_sample->actual.format;
} else { // 16bit
  if(signed) {
    target.format = AUDIO_S16SYS;
  } else {
    target.format = AUDIO_U16SYS;
  }
}

After trying it, it seems that SDL_sound won't let me
change the desired target after a sound has been
opened. So my workaround was to immediately close the
file, and then call NewSample again, this time with
the appropriate parameters.

This worked for files. But now I've discovered that
I've hung myself with SDL_RWops. The problem is that
when I close the sound_sample, it also destroys the
SDL_RWops so it is impossible for me to reopen it. (I
don't have access to the part of the code that created
the original RWops.)

So, I was wondering, first, does my reasoning seem
sound? And if so, is there something that I can do to
get around the issue with the RWops?

I've kicked around the idea about always picking
target.format as AUDIO_S16SYS or AUDIO_U16SYS.
However, this seems like a waste of memory and extra
processing to me since OpenAL is supposed to be able
to handle 8-bit samples. I'm also unclear of what the
impact is of picking between signed and unsigned (i.e.
if it really matters, or is there an optimal value for
OpenAL).

Thanks,
Eric





__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com



More information about the sdlsound mailing list