test: Update testresample for SDL3 audio API.

main
Ryan C. Gordon 2023-06-24 15:46:40 -04:00
parent 3a02eecced
commit 29afc2e42b
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 12 additions and 11 deletions

View File

@ -22,12 +22,11 @@ static void log_usage(char *progname, SDLTest_CommonState *state) {
int main(int argc, char **argv)
{
SDL_AudioSpec spec;
SDL_AudioSpec cvtspec;
SDL_AudioStream *stream = NULL;
Uint8 *dst_buf = NULL;
Uint32 len = 0;
Uint8 *data = NULL;
int cvtfreq = 0;
int cvtchans = 0;
int bitsize = 0;
int blockalign = 0;
int avgbytes = 0;
@ -49,6 +48,8 @@ int main(int argc, char **argv)
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_zero(cvtspec);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
@ -65,14 +66,14 @@ int main(int argc, char **argv)
consumed = 1;
} else if (argpos == 2) {
char *endp;
cvtfreq = (int)SDL_strtoul(argv[i], &endp, 0);
cvtspec.freq = (int)SDL_strtoul(argv[i], &endp, 0);
if (endp != argv[i] && *endp == '\0') {
argpos++;
consumed = 1;
}
} else if (argpos == 3) {
char *endp;
cvtchans = (int)SDL_strtoul(argv[i], &endp, 0);
cvtspec.channels = (int)SDL_strtoul(argv[i], &endp, 0);
if (endp != argv[i] && *endp == '\0') {
argpos++;
consumed = 1;
@ -100,14 +101,14 @@ int main(int argc, char **argv)
goto end;
}
if (SDL_LoadWAV(file_in, &spec, &data, &len) == NULL) {
if (SDL_LoadWAV(file_in, &spec, &data, &len) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", file_in, SDL_GetError());
ret = 3;
goto end;
}
if (SDL_ConvertAudioSamples(spec.format, spec.channels, spec.freq, data, len,
spec.format, cvtchans, cvtfreq, &dst_buf, &dst_len) < 0) {
cvtspec.format = spec.format;
if (SDL_ConvertAudioSamples(&spec, data, len, &cvtspec, &dst_buf, &dst_len) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to convert samples: %s\n", SDL_GetError());
ret = 4;
goto end;
@ -122,8 +123,8 @@ int main(int argc, char **argv)
}
bitsize = SDL_AUDIO_BITSIZE(spec.format);
blockalign = (bitsize / 8) * cvtchans;
avgbytes = cvtfreq * blockalign;
blockalign = (bitsize / 8) * cvtspec.channels;
avgbytes = cvtspec.freq * blockalign;
SDL_WriteLE32(io, 0x46464952); /* RIFF */
SDL_WriteLE32(io, dst_len + 36);
@ -131,8 +132,8 @@ int main(int argc, char **argv)
SDL_WriteLE32(io, 0x20746D66); /* fmt */
SDL_WriteLE32(io, 16); /* chunk size */
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
SDL_WriteLE16(io, cvtchans); /* channels */
SDL_WriteLE32(io, cvtfreq); /* sample rate */
SDL_WriteLE16(io, cvtspec.channels); /* channels */
SDL_WriteLE32(io, cvtspec.freq); /* sample rate */
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
SDL_WriteLE16(io, blockalign); /* block align */
SDL_WriteLE16(io, bitsize); /* significant bits per sample */