mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-02 18:07:40 +00:00
test: Update testresample for SDL3 audio API.
This commit is contained in:
parent
3a02eecced
commit
29afc2e42b
1 changed files with 12 additions and 11 deletions
|
@ -22,12 +22,11 @@ static void log_usage(char *progname, SDLTest_CommonState *state) {
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec spec;
|
SDL_AudioSpec spec;
|
||||||
|
SDL_AudioSpec cvtspec;
|
||||||
SDL_AudioStream *stream = NULL;
|
SDL_AudioStream *stream = NULL;
|
||||||
Uint8 *dst_buf = NULL;
|
Uint8 *dst_buf = NULL;
|
||||||
Uint32 len = 0;
|
Uint32 len = 0;
|
||||||
Uint8 *data = NULL;
|
Uint8 *data = NULL;
|
||||||
int cvtfreq = 0;
|
|
||||||
int cvtchans = 0;
|
|
||||||
int bitsize = 0;
|
int bitsize = 0;
|
||||||
int blockalign = 0;
|
int blockalign = 0;
|
||||||
int avgbytes = 0;
|
int avgbytes = 0;
|
||||||
|
@ -49,6 +48,8 @@ int main(int argc, char **argv)
|
||||||
/* Enable standard application logging */
|
/* Enable standard application logging */
|
||||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
|
||||||
|
SDL_zero(cvtspec);
|
||||||
|
|
||||||
/* Parse commandline */
|
/* Parse commandline */
|
||||||
for (i = 1; i < argc;) {
|
for (i = 1; i < argc;) {
|
||||||
int consumed;
|
int consumed;
|
||||||
|
@ -65,14 +66,14 @@ int main(int argc, char **argv)
|
||||||
consumed = 1;
|
consumed = 1;
|
||||||
} else if (argpos == 2) {
|
} else if (argpos == 2) {
|
||||||
char *endp;
|
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') {
|
if (endp != argv[i] && *endp == '\0') {
|
||||||
argpos++;
|
argpos++;
|
||||||
consumed = 1;
|
consumed = 1;
|
||||||
}
|
}
|
||||||
} else if (argpos == 3) {
|
} else if (argpos == 3) {
|
||||||
char *endp;
|
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') {
|
if (endp != argv[i] && *endp == '\0') {
|
||||||
argpos++;
|
argpos++;
|
||||||
consumed = 1;
|
consumed = 1;
|
||||||
|
@ -100,14 +101,14 @@ int main(int argc, char **argv)
|
||||||
goto end;
|
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());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", file_in, SDL_GetError());
|
||||||
ret = 3;
|
ret = 3;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_ConvertAudioSamples(spec.format, spec.channels, spec.freq, data, len,
|
cvtspec.format = spec.format;
|
||||||
spec.format, cvtchans, cvtfreq, &dst_buf, &dst_len) < 0) {
|
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());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to convert samples: %s\n", SDL_GetError());
|
||||||
ret = 4;
|
ret = 4;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -122,8 +123,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
bitsize = SDL_AUDIO_BITSIZE(spec.format);
|
bitsize = SDL_AUDIO_BITSIZE(spec.format);
|
||||||
blockalign = (bitsize / 8) * cvtchans;
|
blockalign = (bitsize / 8) * cvtspec.channels;
|
||||||
avgbytes = cvtfreq * blockalign;
|
avgbytes = cvtspec.freq * blockalign;
|
||||||
|
|
||||||
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
||||||
SDL_WriteLE32(io, dst_len + 36);
|
SDL_WriteLE32(io, dst_len + 36);
|
||||||
|
@ -131,8 +132,8 @@ int main(int argc, char **argv)
|
||||||
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
||||||
SDL_WriteLE32(io, 16); /* chunk size */
|
SDL_WriteLE32(io, 16); /* chunk size */
|
||||||
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
||||||
SDL_WriteLE16(io, cvtchans); /* channels */
|
SDL_WriteLE16(io, cvtspec.channels); /* channels */
|
||||||
SDL_WriteLE32(io, cvtfreq); /* sample rate */
|
SDL_WriteLE32(io, cvtspec.freq); /* sample rate */
|
||||||
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
||||||
SDL_WriteLE16(io, blockalign); /* block align */
|
SDL_WriteLE16(io, blockalign); /* block align */
|
||||||
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue