• Advertisement
Sign in to follow this  

How do I know which parameters to give Mix_OpenAudio() ?

This topic is 754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure how to find out what parameters to give to Mix_OpenAudio().

In the SDL wiki they do this : 

Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 1024)

However they never explain why those parameters are there.

 

So, my questions are : 

  • What do all of the parameters mean?
  • How do I know what to actually put there?

Share this post


Link to post
Share on other sites
Advertisement

 

These are the audio stream format parameters. They specify the format of the sound device's output stream. I don't know any specifics about the SDL API though or how it would deal with parameters that don't match the current device settings.

  1. Sample rate - 44100 Hz is standard for CD-quality audio. Some audio cards use 48kHz and pro-level hardware goes up to 192kHz.
  2. Sample type - in this case, signed 16-bit integers. This is the output format. Most audio DSP is done with 32-bit floats these days, then converted to 16 or 24-bit integers on output.
  3. Number of channels (2 = stereo)
  4. Audio buffer size - how big of a buffer should the sound be processed in. This influences the latency of the device. A 1024 sample buffer at 44100 kHz adds a latency of at least 23ms. Too much latency can be bad, but if the buffer size is too small it can cause glitches in the audio if the CPU isn't fast enough to finish the processing in time. I would try a buffer of 512 samples.

 

So I should pretty much set everything to "today's standard" ? :)

Edited by BiiXteR

Share this post


Link to post
Share on other sites
  • How do I know which parameters to give Mix_OpenAudio() ?
  • What do all of the parameters mean?
  • How do I know what to actually put there?

While Aressera’s question is good, it doesn’t quite answer your questions. Whenever you find yourself asking these kinds of questions, you should consult your library’s documentation. Additionally, you can learn how the method behaves, how it indicates errors, and perhaps a few usage examples as well.


Here is the documentation (assuming SDL 1.2, since SDL 2.0 uses SDL_OpenAudio):

Mix_OpenAudio
SDL_Mixer documentation

Share this post


Link to post
Share on other sites

 

  • How do I know which parameters to give Mix_OpenAudio() ?
  • What do all of the parameters mean?
  • How do I know what to actually put there?

While Aressera’s question is good, it doesn’t quite answer your questions. Whenever you find yourself asking these kinds of questions, you should consult your library’s documentation. Additionally, you can learn how the method behaves, how it indicates errors, and perhaps a few usage examples as well.


Here is the documentation (assuming SDL 1.2, since SDL 2.0 uses SDL_OpenAudio):

Mix_OpenAudio
SDL_Mixer documentation

 

Wait... No, I use SDL2 with the mixer Haddon library...

I feel like I'm making a horrible mistake here.

Should I not use the mixer addon if I use SDL2? (If not, that would explain the error I'm currently getting with the mixer library...)

Share this post


Link to post
Share on other sites

Usually the audio libraries will give you a way to query what the hardware supports.  You might choose among them based on what you know your audio data contains, or you may offer the choice to the user, often sorted by whatever you think is best.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement