From f18cf7cffb9f0e5de0ed9933614f107cd506317b Mon Sep 17 00:00:00 2001 From: Brick <6098371+0x1F9F1@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:05:15 +0000 Subject: [PATCH] Avoid changing dst_spec in testaudiostreamdynamicresample skip_audio This is no longer allowed on bound streams --- test/testaudiostreamdynamicresample.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/testaudiostreamdynamicresample.c b/test/testaudiostreamdynamicresample.c index 9ccdf1dfb9c2b..06c2ba9d1ab28 100644 --- a/test/testaudiostreamdynamicresample.c +++ b/test/testaudiostreamdynamicresample.c @@ -137,8 +137,8 @@ static void queue_audio() static void skip_audio(float amount) { float speed; - SDL_AudioSpec dst_spec, new_spec; - int num_frames; + SDL_AudioSpec dst_spec; + int num_bytes; int retval = 0; void* buf = NULL; @@ -147,23 +147,16 @@ static void skip_audio(float amount) speed = SDL_GetAudioStreamFrequencyRatio(stream); SDL_GetAudioStreamFormat(stream, NULL, &dst_spec); - /* Gimme that crunchy audio */ - new_spec.format = SDL_AUDIO_S8; - new_spec.channels = 1; - new_spec.freq = 4000; - SDL_SetAudioStreamFrequencyRatio(stream, 100.0f); - SDL_SetAudioStreamFormat(stream, NULL, &new_spec); - num_frames = (int)(new_spec.freq * ((speed * amount) / 100.0f)); - buf = SDL_malloc(num_frames); + num_bytes = (int)(SDL_AUDIO_FRAMESIZE(dst_spec) * dst_spec.freq * ((speed * amount) / 100.0f)); + buf = SDL_malloc(num_bytes); if (buf) { - retval = SDL_GetAudioStreamData(stream, buf, num_frames); + retval = SDL_GetAudioStreamData(stream, buf, num_bytes); SDL_free(buf); } - SDL_SetAudioStreamFormat(stream, NULL, &dst_spec); SDL_SetAudioStreamFrequencyRatio(stream, speed); SDL_UnlockAudioStream(stream); @@ -411,14 +404,15 @@ int main(int argc, char *argv[]) filename = GetResourceFilename(filename, "sample.wav"); rc = SDL_LoadWAV(filename, &spec, &audio_buf, &audio_len); - SDL_free(filename); if (rc < 0) { SDL_Log("Failed to load '%s': %s", filename, SDL_GetError()); + SDL_free(filename); SDL_Quit(); return 1; } + SDL_free(filename); init_slider(0, "Speed: %3.2fx", 0x0, 1.0f, 0.2f, 5.0f); init_slider(1, "Freq: %g", 0x2, (float)spec.freq, 4000.0f, 192000.0f); init_slider(2, "Channels: %g", 0x3, (float)spec.channels, 1.0f, 8.0f);