Reputation:
I wrote a library to read unsigned 8 bit pcm audio from a old game and I stuffed the raw data into a Mix_Chunk using this code:
Mix_Chunk sfx;
sfx.allocated = 1;
sfx.abuf = (Uint8*)data;
sfx.alen = length;
sfx.volume = 32;
I know the samplerate is 10989HZ but when I set the sample rate using Mix_OpenAudio(10989, AUDIO_U8, 2, 2048
it plays the sound way too fast, am I setting the sample rate wrong or is it just SDL2 not liking PCM?
if I dump it into a file and open it with Audacity it plays just fine
Upvotes: 0
Views: 1174
Reputation:
fixed the problem, before you call Mix_OpenAudio run this:
SDL_AudioSpec wavSpec;
SDL_memset(&wavSpec, 0, sizeof(wavSpec)); /* or SDL_zero(want) */
wavSpec.callback = audioCallback;
wavSpec.userdata = nullptr;
wavSpec.format = AUDIO_S16;
wavSpec.channels = 2;
wavSpec.samples = 2048;
if (SDL_OpenAudio(&wavSpec, NULL) < 0)
{
fprintf(stderr, "Could not open audio: %s\n", SDL_GetError());
}
pcm audio plays correctly now
Upvotes: 1