#define MUS_PATH "../MAZIOB/Pliki/11.wav"
int main(int argc, char* argv[]){
// Initialize SDL.
if (SDL_Init(SDL_INIT_AUDIO) < 0)
return 1;
// local variables
static Uint32 wav_length; // length of our sample
static Uint8 *wav_buffer; // buffer containing our audio file
static SDL_AudioSpec wav_spec; // the specs of our piece of music
SDL_AudioDeviceID dev;
/* Load the WAV */
// the specs, length and buffer of our wav are filled
if( SDL_LoadWAV(MUS_PATH, &wav_spec, &wav_buffer, &wav_length) == NULL ){
return 1;
}
wav_spec.callback = NULL;
wav_spec.userdata = NULL;
/* Open the audio device */
dev = SDL_OpenAudioDevice(NULL, 0, &wav_spec, NULL, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
/* Start playing */
Print SDL_QueueAudio(dev, wav_buffer, wav_length) NL
SDL_PauseAudio(0);
Pause(1000)
// shut everything down
SDL_CloseAudio();
SDL_FreeWAV(wav_buffer);
}
I hear nothing…
It works using callback
Would it be possible instead of mixing the sounds, e.g. triggering the sounds to play in separate threads, and the mixing would be done by the operating system?
I use very similar code, and it works in Windows for me. The main difference is that I don’t pass the SDL_AUDIO_ALLOW_FORMAT_CHANGE flag, instead I convert the audio to AUDIO_S16LSB format using SDL_ConvertAudio().