The basics:
SDL3 3.4.12
SDL_mixer 3.2.4
OS: Arch Linux
Arch: x86_64
I allow users to specify the frequency and number of channels in a settings file which I'm passing in like (abbreviated):
SDL_AudioSpec spec{SDL_AUDIO_F32, channels, freq};
MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec));
Later on I prepare a raw audio track to stream audio too from ffmpeg with code like this (edited for brevity, remove c++isms):
SDL_AudioSpec audio_spec;
MIX_GetMixerFormat(mixer, &audio_spec); // <-- problem line
mixer_frequency = audio_spec.freq;
mixer_channels = audio_spec.channels;
...
swr_alloc_set_opts2(&audio_resample_context, ch_layout.get(),
AV_SAMPLE_FMT_FLT, mixer_frequency,
&(audio_codec_context->ch_layout),
audio_codec_context->sample_fmt,
audio_codec_context->sample_rate, 0, nullptr);
...
empty_audio_chunk = MIX_LoadRawAudioNoCopy(mixer, audio_chunk_buffer.data(),
audio_chunk_buffer.size(), &audio_spec, false);
audio_track = MIX_CreateTrack(mixer);
MIX_SetTrackAudio(audio_track, empty_audio_chunk);
SDL_PropertiesID playProps = SDL_CreateProperties();
SDL_SetNumberProperty(playProps, MIX_PROP_PLAY_LOOPS_NUMBER, -1);
MIX_PlayTrack(audio_track, playProps);
SDL_DestroyProperties(playProps);
MIX_SetTrackCookedCallback(audio_track, movie_audio_callback, this);
Now that audio_spec I get from MIX_GetMixerFormat ignores the frequency I set and always returns 44100; which is not unexpected because that's what the system really supports. MIX_GetAudioFormat also returns 44100; but the spec that is included in the callback has my configured value e.g. 22050, and the number of samples is only enough for that frequency, resulting in the wrong playback speed.
I know from running the debugger that MIX_Mixer retains the 22050 and passes it to the track. What I haven't figured out is how I could query that, or better yet override the track's spec to match the hardware since I'm resampling the movie audio anyway.
The basics:
SDL3 3.4.12
SDL_mixer 3.2.4
OS: Arch Linux
Arch: x86_64
I allow users to specify the frequency and number of channels in a settings file which I'm passing in like (abbreviated):
SDL_AudioSpec spec{SDL_AUDIO_F32, channels, freq}; MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec));Later on I prepare a raw audio track to stream audio too from ffmpeg with code like this (edited for brevity, remove c++isms):
Now that audio_spec I get from MIX_GetMixerFormat ignores the frequency I set and always returns 44100; which is not unexpected because that's what the system really supports. MIX_GetAudioFormat also returns 44100; but the spec that is included in the callback has my configured value e.g. 22050, and the number of samples is only enough for that frequency, resulting in the wrong playback speed.
I know from running the debugger that MIX_Mixer retains the 22050 and passes it to the track. What I haven't figured out is how I could query that, or better yet override the track's spec to match the hardware since I'm resampling the movie audio anyway.