testaudiostreamdynamicresample: Load sample.wav correctly.

main
Ryan C. Gordon 2023-07-30 23:00:52 -04:00
parent 87eae9a0a1
commit 0eda582160
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
2 changed files with 15 additions and 2 deletions

View File

@ -122,7 +122,7 @@ add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS SOURCES loopwave.c)
add_sdl_test_executable(testsurround SOURCES testsurround.c) add_sdl_test_executable(testsurround SOURCES testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c) add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c)
add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c) add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c)
add_sdl_test_executable(testaudiostreamdynamicresample SOURCES testaudiostreamdynamicresample.c) add_sdl_test_executable(testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS SOURCES testaudiostreamdynamicresample.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c) file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES}) add_sdl_test_executable(testautomation NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})

View File

@ -15,6 +15,7 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <SDL3/SDL_main.h> #include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h> #include <SDL3/SDL_test.h>
#include "testutils.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -29,12 +30,24 @@ int main(int argc, char *argv[])
Uint32 audio_len = 0; Uint32 audio_len = 0;
SDL_AudioStream *stream; SDL_AudioStream *stream;
SDL_AudioDeviceID device; SDL_AudioDeviceID device;
const char *fname = "sample.wav";
char *path;
int rc;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
window = SDL_CreateWindow("Drag the slider: Normal speed", 640, 480, 0); window = SDL_CreateWindow("Drag the slider: Normal speed", 640, 480, 0);
renderer = SDL_CreateRenderer(window, NULL, 0); renderer = SDL_CreateRenderer(window, NULL, 0);
SDL_LoadWAV("sample.wav", &spec, &audio_buf, &audio_len); path = GetNearbyFilename(fname);
rc = SDL_LoadWAV(path ? path : fname, &spec, &audio_buf, &audio_len);
SDL_free(path);
if (rc < 0) {
SDL_Log("Failed to load '%s': %s", fname, SDL_GetError());
SDL_Quit();
return 1;
}
stream = SDL_CreateAudioStream(&spec, &spec); stream = SDL_CreateAudioStream(&spec, &spec);
SDL_PutAudioStreamData(stream, audio_buf, audio_len); SDL_PutAudioStreamData(stream, audio_buf, audio_len);
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec); device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec);