[SDL] SDL Audio questions

Ryan C. Gordon icculus at clutteredmind.org
Sun Jul 28 19:13:01 PDT 2002

> My question is this - All of the examples pass an SDL_AudioSpec structure
> to the SDL_OpenAudio stream as a request. Does this mean I need to keep
> this structure around, or is the data pulled from this structure and
> placed somewhere else? I have the SDL_AudioSpec structure declared as an
> autovariable and don't want to make SDL take a dump.

SDL_OpenAudio() makes a copy of the structure; it's acceptable to pass it
a pointer to the stack.

> That leads to my second question. Rather than having the SDL routines deal
> with the different format changes, I'm dealing with the conversion of the
> various sample types in my own code since it's more efficient to do that
> way. I'd like to pass information in to the callback (userdata) that
> indicates the sample type. However, with the current API, I need to know
> what that is before I do an SDL_OpenAudio, and it looks like the only way
> I can set userdata to anything is by doing an SDL_OpenAudio. Is there any
> way to change the user data callback after SDL_OpenAudio has been called?

Could you pass it a pointer to data that you update? The callback will get
the original pointer, but what it points to can be changed.

> I noticed the sample rate converter in SDL_ConvertAudio() won't convert
> sample rates of odd values. For example, if I have a 16Khz sample rate
> wave file and I need to convert it to 44.1khz, the frequency comes out
> wrong (not sure what it is, but it's definitley wrong). Plus, there's a
> good amount of noise/grainyness introduced.

The SDL sample rate converter only successfully converts between rates
that are powers of two (and even there, some would argue, not very well).

We have a more accurate converter in the works that is being developed in
the SDL_sound project (http://icculus.org/SDL_sound/)...the hope is that
after SDL_sound is finished being a good testbed for it, we can adapt it
to SDL for the 2.0 revision of the library. Might be worth your time to
look at.

> Is there any interest in me submitting a sample rate converter that has
> antialiasing? What is the process for submitting code?

Generally, send patches to the list against the latest CVS. After we are
done making fun of your code (no, we don't really. Honest.), we can decide
if it's right for SDL. I tend to commit fixes, but leave it up to Sam to
decide on big changes. (However, I'm the dictator for SDL_sound.  :)  )


More information about the SDL mailing list