emscripten-ports / SDL2_mixer

From https://www.libsdl.org/projects/SDL_mixer/, with Emscripten-specific patches when appropriate
Other
10 stars 4 forks source link

Playback sample rate seems to be hardcoded to 44100Hz? #3

Closed joshuaskelly closed 1 year ago

joshuaskelly commented 1 year ago

I'm writing a retro game engine and I'm testing out sound assets that are signed 16-bit PCM with a sample rate of 11025Hz. The audio plays fine when built for desktop, but when built with emscripten for web the playback is way too fast. I resampled my test audio to 44100Hz and it then played fine.

I'm just opening a default audio device:

if (Mix_OpenAudio(11025, MIX_DEFAULT_FORMAT, 1, 2048) < 0) {
    log_fatal("Error intializing SDL Mixer");
}

And then handing it PCM data:

Mix_Chunk* chunk = Mix_QuickLoad_RAW((uint8_t*)sound->pcm_data, sound->frame_count * sound->channel_count * sizeof(int16_t));
Mix_PlayChannel(-1, chunk, 0);

I'd appreciate any advice/help.

joshuaskelly commented 1 year ago

Turns out my issue was an SDL issue. I fixed it by using the more explicit OpenAudio api call:

if (Mix_OpenAudioDevice(11025, AUDIO_U8, 1, 2048, NULL, 0) < 0) { ... }