I’m porting a little game from Windows. It uses a few small sounds, stored in WAV files. In Windows the details are all taken care of automatically, but here in SDL2 I’m having a challenge.
SDL_OpenAudioDevice wants to be told (via wavSpec) what sampling rate to expect, for example:
SDL_AudioSpec wavSpec;
soundDevice = SDL_OpenAudioDevice(NULL, 0, &wavSpec, NULL, 0);
So I was populating my wavSpec by loading my first WAV file and using the wavSpec that SDL_LoadWAV provides. Oops. Not all my WAV files have the same sampling rate. So if one is correct, the others are too fast or too slow and sound ridiculous.
What’s the best way of handling this? Close the device and open with a different sampling rate? (Feels overly heavy.) Explicitly resample all wave files to the same sampling rate? Oh please, no! Open multiple “devices” with different sampling rates?