From 5d4e9e5f80dbb5f62d5da31017f6c482c6ebc021 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 24 Jun 2023 01:44:12 -0400
Subject: [PATCH] test: Updated testaudiostreamdynamicresample to SDL3 audio
API.
---
test/testaudiostreamdynamicresample.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/test/testaudiostreamdynamicresample.c b/test/testaudiostreamdynamicresample.c
index 66600181143f..609bd646dd6c 100644
--- a/test/testaudiostreamdynamicresample.c
+++ b/test/testaudiostreamdynamicresample.c
@@ -16,13 +16,6 @@
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
-static void SDLCALL audio_callback(void *userdata, Uint8 * stream, int len)
-{
- SDL_AudioStream *audiostream = (SDL_AudioStream *) userdata;
- SDL_memset(stream, 0, len);
- SDL_GetAudioStreamData(audiostream, stream, len);
-}
-
int main(int argc, char *argv[])
{
SDL_Window *window;
@@ -42,18 +35,17 @@ int main(int argc, char *argv[])
renderer = SDL_CreateRenderer(window, NULL, 0);
SDL_LoadWAV("sample.wav", &spec, &audio_buf, &audio_len);
- stream = SDL_CreateAudioStream(spec.format, spec.channels, spec.freq, spec.format, spec.channels, spec.freq);
+ stream = SDL_CreateAudioStream(&spec, &spec);
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
- spec.callback = audio_callback;
- spec.userdata = stream;
- device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &spec, NULL, 0);
- SDL_PlayAudioDevice(device);
+ device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec);
+ SDL_BindAudioStream(device, stream);
slider_fill_area.w /= 2;
while (!done) {
SDL_Event e;
int newmultiplier = multiplier;
+
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
done = 1;
@@ -74,6 +66,7 @@ int main(int argc, char *argv[])
}
if (multiplier != newmultiplier) {
+ SDL_AudioSpec newspec;
char title[64];
int newfreq = spec.freq;
@@ -94,13 +87,13 @@ int main(int argc, char *argv[])
newfreq = spec.freq + (int) (spec.freq * (multiplier / 100.0f));
}
/* SDL_Log("newfreq=%d multiplier=%d\n", newfreq, multiplier); */
- SDL_LockAudioDevice(device);
- SDL_SetAudioStreamFormat(stream, spec.format, spec.channels, newfreq, spec.format, spec.channels, spec.freq);
- SDL_UnlockAudioDevice(device);
+ SDL_memcpy(&newspec, &spec, sizeof (spec));
+ newspec.freq = newfreq;
+ SDL_SetAudioStreamFormat(stream, &newspec, NULL);
}
/* keep it looping. */
- if (SDL_GetAudioStreamAvailable(stream) < (1024 * 100)) {
+ if (SDL_GetAudioStreamAvailable(stream) < (audio_len / 2)) {
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
}
@@ -116,6 +109,7 @@ int main(int argc, char *argv[])
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_CloseAudioDevice(device);
+ SDL_DestroyAudioStream(stream);
SDL_free(audio_buf);
SDL_Quit();
return 0;