I'm trying to play a simple WAV file using SDL2. Most tutorials seem to opt to use SDL_mixer, but I instead took the masochistic approach of trying to use SDL2's native functionality for Audio.
I put together bits and pieces from the documentation and came up with this:
int main(int argc, char ** argv)
desired.freq = 48000;
desired.format = AUDIO_F32;
desired.channels = 2;
desired.samples = 4096;
desired.callback = NULL;
if (SDL_LoadWAV("Powerup5.wav", &wav_spec, &wav_buffer, &wav_length))
SDL_AudioDeviceID deviceId = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0);
int success = SDL_QueueAudio(deviceId, wav_buffer, wav_length);
if (success < 0)
SDL_ShowSimpleMessageBox(0, "Error", "Failed to queue audio", NULL);
SDL_ShowSimpleMessageBox(0, "Error", "Audio driver failed to initialize", NULL);
SDL_ShowSimpleMessageBox(0, "Error", "wav failed to load", NULL);
Everything is loading fine (I am not getting any message boxes) but no sound is being played. I tried switching the desired AudioSpec with that read from the WAV file, but it didn't change anything.
Any idea what I'm doing wrong?