Open the mixer with a certain audio format
0 on success, -1 on errors
This must be called before using other functions in this library. SDL must be initialized with SDL_INIT_AUDIO before this call. frequency would be 44100 for 44.1KHz, which is CD audio rate. Most games use 22050, because 44100 requires too much CPU power on older computers. chunksize is the size of each mixed sample. The smaller this is the more your hooks will be called. If make this too small on a slow system, sound may skip. If made to large, sound effects will lag behind the action more. You want a happy medium for your target computer. You also may make this 4096, or larger, if you are just playing music. MIX_CHANNELS(8) mixing channels will be allocated by default. You may call this function multiple times, however you will have to call Mix_CloseAudio just as many times for the device to actually close. The format will not changed on subsequent calls. So you will have to close all the way before trying to open with different format parameters.
format is based on SDL audio support, see SDL_audio.h. Here are the values listed there:
AUDIO_U8 Unsigned 8-bit samples AUDIO_S8 Signed 8-bit samples AUDIO_U16LSB Unsigned 16-bit samples, in little-endian byte order AUDIO_S16LSB Signed 16-bit samples, in little-endian byte order AUDIO_U16MSB Unsigned 16-bit samples, in big-endian byte order AUDIO_S16MSB Signed 16-bit samples, in big-endian byte order AUDIO_U16 same as AUDIO_U16LSB (for backwards compatability probably) AUDIO_S16 same as AUDIO_S16LSB (for backwards compatability probably) AUDIO_U16SYS Unsigned 16-bit samples, in system byte order AUDIO_S16SYS Signed 16-bit samples, in system byte order
MIX_DEFAULT_FORMAT is the same as AUDIO_S16SYS.
Binds to C-funtion in SDL_mixer.h
int Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize)
// start SDL with audio support if(SDL_Init(SDL_INIT_AUDIO)==-1) { printf("SDL_Init: %s\n", SDL_GetError()); exit(1); } // open 44.1KHz, signed 16bit, system byte order, // stereo audio, using 1024 byte chunks if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)==-1) { printf("Mix_OpenAudio: %s\n", Mix_GetError()); exit(2); }
SdlMixer Class | Tao.Sdl Namespace | Mix_CloseAudio | Mix_QuerySpec | Mix_AllocateChannels