update SDL3 to latest commit

This commit is contained in:
Sasha Szpakowski
2024-10-06 20:30:44 -03:00
parent 1b0fdc338b
commit 9e5eb1b018
1426 changed files with 242456 additions and 103496 deletions
+299 -114
View File
@@ -19,18 +19,18 @@
/* Fixture */
static void audioSetUp(void *arg)
static void SDLCALL audioSetUp(void **arg)
{
/* Start SDL audio subsystem */
int ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
bool ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
if (ret != 0) {
SDLTest_AssertCheck(ret == true, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
if (!ret) {
SDLTest_LogError("%s", SDL_GetError());
}
}
static void audioTearDown(void *arg)
static void SDLCALL audioTearDown(void *arg)
{
/* Remove a possibly created file from SDL disk writer audio driver; ignore errors */
(void)remove("sdlaudio.raw");
@@ -64,7 +64,7 @@ static SDL_AudioDeviceID g_audio_id = 0;
* \sa SDL_QuitSubSystem
* \sa SDL_InitSubSystem
*/
static int audio_quitInitAudioSubSystem(void *arg)
static int SDLCALL audio_quitInitAudioSubSystem(void *arg)
{
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@@ -82,7 +82,7 @@ static int audio_quitInitAudioSubSystem(void *arg)
* \sa SDL_InitAudio
* \sa SDL_QuitAudio
*/
static int audio_initQuitAudio(void *arg)
static int SDLCALL audio_initQuitAudio(void *arg)
{
int result;
int i, iMax;
@@ -108,10 +108,10 @@ static int audio_initQuitAudio(void *arg)
}
/* Call Init */
SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver);
result = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
SDLTest_AssertCheck(result == true, "Validate result value; expected: true got: %d", result);
/* Call Quit */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@@ -122,10 +122,10 @@ static int audio_initQuitAudio(void *arg)
audioDriver = NULL;
/* Call Init */
SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver);
result = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_AudioInit(NULL)");
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
SDLTest_AssertCheck(result == true, "Validate result value; expected: true got: %d", result);
/* Call Quit */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@@ -145,7 +145,7 @@ static int audio_initQuitAudio(void *arg)
* \sa SDL_CloseAudioDevice
* \sa SDL_QuitAudio
*/
static int audio_initOpenCloseQuitAudio(void *arg)
static int SDLCALL audio_initOpenCloseQuitAudio(void *arg)
{
int result;
int i, iMax, j, k;
@@ -175,13 +175,13 @@ static int audio_initOpenCloseQuitAudio(void *arg)
for (j = 0; j < 2; j++) {
/* Call Init */
SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver);
result = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
SDLTest_AssertCheck(result == true, "Validate result value; expected: true got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
SDL_zero(desired);
switch (j) {
case 0:
/* Set standard desired spec */
@@ -200,11 +200,11 @@ static int audio_initOpenCloseQuitAudio(void *arg)
/* Call Open (maybe multiple times) */
for (k = 0; k <= j; k++) {
result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired);
if (k == 0) {
g_audio_id = result;
}
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d), call %d", j, k + 1);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, desired_spec_%d), call %d", j, k + 1);
SDLTest_AssertCheck(result > 0, "Verify return value; expected: > 0, got: %d", result);
}
@@ -235,7 +235,7 @@ static int audio_initOpenCloseQuitAudio(void *arg)
* \sa SDL_PauseAudioDevice
* \sa SDL_PlayAudioDevice
*/
static int audio_pauseUnpauseAudio(void *arg)
static int SDLCALL audio_pauseUnpauseAudio(void *arg)
{
int iMax;
int i, j /*, k, l*/;
@@ -266,13 +266,13 @@ static int audio_pauseUnpauseAudio(void *arg)
for (j = 0; j < 2; j++) {
/* Call Init */
SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver);
result = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
SDLTest_AssertCheck(result == true, "Validate result value; expected: true got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
SDL_zero(desired);
switch (j) {
case 0:
/* Set standard desired spec */
@@ -290,9 +290,9 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/* Call Open */
g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired);
result = g_audio_id;
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d)", j);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, desired_spec_%d)", j);
SDLTest_AssertCheck(result > 0, "Verify return value; expected > 0 got: %d", result);
#if 0 /* !!! FIXME: maybe update this? */
@@ -356,24 +356,24 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/**
* Enumerate and name available audio devices (output and capture).
* Enumerate and name available audio devices (playback and recording).
*
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioDeviceName
*/
static int audio_enumerateAndNameAudioDevices(void *arg)
static int SDLCALL audio_enumerateAndNameAudioDevices(void *arg)
{
int t;
int i, n;
char *name;
SDL_AudioDeviceID *devices = NULL;
const char *name;
SDL_AudioDeviceID *devices;
/* Iterate over types: t=0 output device, t=1 input/capture device */
/* Iterate over types: t=0 playback device, t=1 recording device */
for (t = 0; t < 2; t++) {
/* Get number of devices. */
devices = (t) ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Capture" : "Output", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
devices = (t) ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Recording" : "Playback", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "recording" : "playback", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* List devices. */
@@ -385,11 +385,9 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i) is not NULL", i);
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i) is not empty, got: '%s'", i, name);
SDL_free(name);
}
}
}
SDL_free(devices);
}
@@ -402,7 +400,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioDeviceName
*/
static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
static int SDLCALL audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
{
return TEST_COMPLETED; /* nothing in here atm since these interfaces changed in SDL3. */
}
@@ -413,7 +411,7 @@ static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
* \sa SDL_GetNumAudioDrivers
* \sa SDL_GetAudioDriver
*/
static int audio_printAudioDrivers(void *arg)
static int SDLCALL audio_printAudioDrivers(void *arg)
{
int i, n;
const char *name;
@@ -443,7 +441,7 @@ static int audio_printAudioDrivers(void *arg)
*
* \sa SDL_GetCurrentAudioDriver
*/
static int audio_printCurrentAudioDriver(void *arg)
static int SDLCALL audio_printCurrentAudioDriver(void *arg)
{
/* Check current audio driver */
const char *name = SDL_GetCurrentAudioDriver();
@@ -469,7 +467,14 @@ static const char *g_audioFormatsVerbose[] = {
"SDL_AUDIO_S32LE", "SDL_AUDIO_S32BE",
"SDL_AUDIO_F32LE", "SDL_AUDIO_F32BE"
};
static SDL_AudioFormat g_invalidAudioFormats[] = {
(SDL_AudioFormat)SDL_DEFINE_AUDIO_FORMAT(SDL_AUDIO_MASK_SIGNED, SDL_AUDIO_MASK_BIG_ENDIAN, SDL_AUDIO_MASK_FLOAT, SDL_AUDIO_MASK_BITSIZE)
};
static const char *g_invalidAudioFormatsVerbose[] = {
"SDL_AUDIO_UNKNOWN"
};
static const int g_numAudioFormats = SDL_arraysize(g_audioFormats);
static const int g_numInvalidAudioFormats = SDL_arraysize(g_invalidAudioFormats);
static Uint8 g_audioChannels[] = { 1, 2, 4, 6 };
static const int g_numAudioChannels = SDL_arraysize(g_audioChannels);
static int g_audioFrequencies[] = { 11025, 22050, 44100, 48000 };
@@ -485,18 +490,73 @@ SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S32BE_FORMAT, SDL_AUDIO_S32BE == (SDL_AUDIO_S3
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32LE_FORMAT, SDL_AUDIO_F32LE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_FLOAT | SDL_AUDIO_MASK_SIGNED));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32BE_FORMAT, SDL_AUDIO_F32BE == (SDL_AUDIO_F32LE | SDL_AUDIO_MASK_BIG_ENDIAN));
/**
* Call to SDL_GetAudioFormatName
*
* \sa SDL_GetAudioFormatName
*/
static int SDLCALL audio_getAudioFormatName(void *arg)
{
const char *error;
int i;
SDL_AudioFormat format;
const char *result;
/* audio formats */
for (i = 0; i < g_numAudioFormats; i++) {
format = g_audioFormats[i];
SDLTest_Log("Audio Format: %s (%d)", g_audioFormatsVerbose[i], format);
/* Get name of format */
result = SDL_GetAudioFormatName(format);
SDLTest_AssertPass("Call to SDL_GetAudioFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, g_audioFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", g_audioFormatsVerbose[i], result);
}
}
/* Negative cases */
/* Invalid Formats */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < g_numInvalidAudioFormats; i++) {
format = g_invalidAudioFormats[i];
result = SDL_GetAudioFormatName(format);
SDLTest_AssertPass("Call to SDL_GetAudioFormatName(%d)", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0',
"Verify result is non-empty; got: %s", result);
SDLTest_AssertCheck(SDL_strcmp(result, g_invalidAudioFormatsVerbose[i]) == 0,
"Validate name is UNKNOWN, expected: '%s', got: '%s'", g_invalidAudioFormatsVerbose[i], result);
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
}
return TEST_COMPLETED;
}
/**
* Builds various audio conversion structures
*
* \sa SDL_CreateAudioStream
*/
static int audio_buildAudioStream(void *arg)
static int SDLCALL audio_buildAudioStream(void *arg)
{
SDL_AudioStream *stream;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int i, ii, j, jj, k, kk;
SDL_zero(spec1);
SDL_zero(spec2);
/* Call Quit */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
@@ -507,7 +567,7 @@ static int audio_buildAudioStream(void *arg)
spec1.freq = 22050;
stream = SDL_CreateAudioStream(&spec1, &spec1);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec1)");
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", stream);
SDL_DestroyAudioStream(stream);
/* Typical conversion */
@@ -519,7 +579,7 @@ static int audio_buildAudioStream(void *arg)
spec2.freq = 44100;
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", stream);
SDL_DestroyAudioStream(stream);
/* All source conversions with random conversion targets, allow 'null' conversions */
@@ -539,7 +599,7 @@ static int audio_buildAudioStream(void *arg)
SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", stream);
if (stream == NULL) {
SDLTest_LogError("%s", SDL_GetError());
}
@@ -559,7 +619,7 @@ static int audio_buildAudioStream(void *arg)
*
* \sa SDL_CreateAudioStream
*/
static int audio_buildAudioStreamNegative(void *arg)
static int SDLCALL audio_buildAudioStreamNegative(void *arg)
{
const char *error;
SDL_AudioStream *stream;
@@ -568,6 +628,9 @@ static int audio_buildAudioStreamNegative(void *arg)
int i;
char message[256];
SDL_zero(spec1);
SDL_zero(spec2);
/* Valid format */
spec1.format = SDL_AUDIO_S8;
spec1.channels = 1;
@@ -621,7 +684,7 @@ static int audio_buildAudioStreamNegative(void *arg)
SDLTest_Log("%s", message);
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
SDLTest_AssertCheck(stream == NULL, "Verify stream value; expected: NULL, got: %p", (void *)stream);
SDLTest_AssertCheck(stream == NULL, "Verify stream value; expected: NULL, got: %p", stream);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
@@ -639,7 +702,7 @@ static int audio_buildAudioStreamNegative(void *arg)
*
* \sa SDL_GetAudioDeviceStatus
*/
static int audio_getAudioStatus(void *arg)
static int SDLCALL audio_getAudioStatus(void *arg)
{
return TEST_COMPLETED; /* no longer a thing in SDL3. */
}
@@ -649,7 +712,7 @@ static int audio_getAudioStatus(void *arg)
*
* \sa SDL_GetAudioStatus
*/
static int audio_openCloseAndGetAudioStatus(void *arg)
static int SDLCALL audio_openCloseAndGetAudioStatus(void *arg)
{
return TEST_COMPLETED; /* not a thing in SDL3. */
}
@@ -660,7 +723,7 @@ static int audio_openCloseAndGetAudioStatus(void *arg)
* \sa SDL_LockAudioDevice
* \sa SDL_UnlockAudioDevice
*/
static int audio_lockUnlockOpenAudioDevice(void *arg)
static int SDLCALL audio_lockUnlockOpenAudioDevice(void *arg)
{
return TEST_COMPLETED; /* not a thing in SDL3 */
}
@@ -670,7 +733,7 @@ static int audio_lockUnlockOpenAudioDevice(void *arg)
*
* \sa SDL_CreateAudioStream
*/
static int audio_convertAudio(void *arg)
static int SDLCALL audio_convertAudio(void *arg)
{
SDL_AudioStream *stream;
SDL_AudioSpec spec1;
@@ -679,6 +742,9 @@ static int audio_convertAudio(void *arg)
char message[128];
int i, ii, j, jj, k, kk;
SDL_zero(spec1);
SDL_zero(spec2);
/* Iterate over bitmask that determines which parameters are modified in the conversion */
for (c = 1; c < 8; c++) {
SDL_strlcpy(message, "Changing:", 128);
@@ -725,7 +791,7 @@ static int audio_convertAudio(void *arg)
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", stream);
if (stream == NULL) {
SDLTest_LogError("%s", SDL_GetError());
} else {
@@ -760,8 +826,8 @@ static int audio_convertAudio(void *arg)
SDLTest_AssertCheck(0 == real_dst_len, "Verify available (pre-put); expected: %i; got: %i", 0, real_dst_len);
/* Run the audio converter */
if (SDL_PutAudioStreamData(stream, src_buf, src_len) < 0 ||
SDL_FlushAudioStream(stream) < 0) {
if (!SDL_PutAudioStreamData(stream, src_buf, src_len) ||
!SDL_FlushAudioStream(stream)) {
return TEST_ABORTED;
}
@@ -804,7 +870,7 @@ static int audio_convertAudio(void *arg)
*
* \sa SDL_AudioDeviceConnected
*/
static int audio_openCloseAudioDeviceConnected(void *arg)
static int SDLCALL audio_openCloseAudioDeviceConnected(void *arg)
{
return TEST_COMPLETED; /* not a thing in SDL3. */
}
@@ -821,6 +887,127 @@ static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64
return SDL_sin(((double)(idx * freq % rate)) / ((double)rate) * (SDL_PI_D * 2) + phase);
}
/* Split the data into randomly sized chunks */
static int put_audio_data_split(SDL_AudioStream* stream, const void* buf, int len)
{
SDL_AudioSpec spec;
int frame_size;
int ret = SDL_GetAudioStreamFormat(stream, &spec, NULL);
if (!ret) {
return -1;
}
frame_size = SDL_AUDIO_FRAMESIZE(spec);
while (len > 0) {
int n = SDLTest_RandomIntegerInRange(1, 10000) * frame_size;
n = SDL_min(n, len);
ret = SDL_PutAudioStreamData(stream, buf, n);
if (!ret) {
return -1;
}
buf = ((const Uint8*) buf) + n;
len -= n;
}
return 0;
}
/* Read the data in randomly sized chunks */
static int get_audio_data_split(SDL_AudioStream* stream, void* buf, int len) {
SDL_AudioSpec spec;
int frame_size;
int ret = SDL_GetAudioStreamFormat(stream, NULL, &spec);
int total = 0;
if (!ret) {
return -1;
}
frame_size = SDL_AUDIO_FRAMESIZE(spec);
while (len > 0) {
int n = SDLTest_RandomIntegerInRange(1, 10000) * frame_size;
n = SDL_min(n, len);
ret = SDL_GetAudioStreamData(stream, buf, n);
if (ret <= 0) {
return total ? total : -1;
}
buf = ((Uint8*) buf) + ret;
total += ret;
len -= ret;
}
return total;
}
/* Convert the data in chunks, putting/getting randomly sized chunks until finished */
static int convert_audio_chunks(SDL_AudioStream* stream, const void* src, int srclen, void* dst, int dstlen)
{
SDL_AudioSpec src_spec, dst_spec;
int src_frame_size, dst_frame_size;
int total_in = 0, total_out = 0;
int ret = SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec);
if (!ret) {
return -1;
}
src_frame_size = SDL_AUDIO_FRAMESIZE(src_spec);
dst_frame_size = SDL_AUDIO_FRAMESIZE(dst_spec);
while ((total_in < srclen) || (total_out < dstlen)) {
/* Make sure we put in more than the padding frames so we get non-zero output */
const int RESAMPLER_MAX_PADDING_FRAMES = 7; /* Should match RESAMPLER_MAX_PADDING_FRAMES in SDL */
int to_put = SDLTest_RandomIntegerInRange(RESAMPLER_MAX_PADDING_FRAMES + 1, 40000) * src_frame_size;
int to_get = SDLTest_RandomIntegerInRange(1, (int)((40000.0f * dst_spec.freq) / src_spec.freq)) * dst_frame_size;
to_put = SDL_min(to_put, srclen - total_in);
to_get = SDL_min(to_get, dstlen - total_out);
if (to_put)
{
ret = put_audio_data_split(stream, (const Uint8*)(src) + total_in, to_put);
if (ret < 0) {
return total_out ? total_out : ret;
}
total_in += to_put;
if (total_in == srclen) {
ret = SDL_FlushAudioStream(stream);
if (!ret) {
return total_out ? total_out : -1;
}
}
}
if (to_get)
{
ret = get_audio_data_split(stream, (Uint8*)(dst) + total_out, to_get);
if ((ret == 0) && (total_in == srclen)) {
ret = -1;
}
if (ret < 0) {
return total_out ? total_out : ret;
}
total_out += ret;
}
}
return total_out;
}
/**
* Check signal-to-noise ratio and maximum error of audio resampling.
*
@@ -830,7 +1017,7 @@ static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64
* \sa https://wiki.libsdl.org/SDL_FlushAudioStream
* \sa https://wiki.libsdl.org/SDL_GetAudioStreamData
*/
static int audio_resampleLoss(void *arg)
static int SDLCALL audio_resampleLoss(void *arg)
{
/* Note: always test long input time (>= 5s from experience) in some test
* cases because an improper implementation may suffer from low resampling
@@ -844,7 +1031,7 @@ static int audio_resampleLoss(void *arg)
double signal_to_noise;
double max_error;
} test_specs[] = {
{ 50, 440, 0, 44100, 48000, 80, 0.0009 },
{ 50, 440, 0, 44100, 48000, 80, 0.0010 },
{ 50, 5000, SDL_PI_D / 2, 20000, 10000, 999, 0.0001 },
{ 50, 440, 0, 22050, 96000, 79, 0.0120 },
{ 50, 440, 0, 96000, 22050, 80, 0.0002 },
@@ -862,13 +1049,13 @@ static int audio_resampleLoss(void *arg)
const int frames_target = spec->time * spec->rate_out;
const int len_in = (frames_in * num_channels) * (int)sizeof(float);
const int len_target = (frames_target * num_channels) * (int)sizeof(float);
const int max_target = len_target * 2;
SDL_AudioSpec tmpspec1, tmpspec2;
Uint64 tick_beg = 0;
Uint64 tick_end = 0;
int i = 0;
int j = 0;
int ret = 0;
SDL_AudioStream *stream = NULL;
float *buf_in = NULL;
float *buf_out = NULL;
@@ -878,6 +1065,9 @@ static int audio_resampleLoss(void *arg)
double sum_squared_value = 0;
double signal_to_noise = 0;
SDL_zero(tmpspec1);
SDL_zero(tmpspec2);
SDLTest_AssertPass("Test resampling of %i s %i Hz %f phase sine wave from sampling rate of %i Hz to %i Hz",
spec->time, spec->freq, spec->phase, spec->rate_in, spec->rate_out);
@@ -888,7 +1078,7 @@ static int audio_resampleLoss(void *arg)
tmpspec2.channels = num_channels;
tmpspec2.freq = spec->rate_out;
stream = SDL_CreateAudioStream(&tmpspec1, &tmpspec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(SDL_AUDIO_F32, 1, %i, SDL_AUDIO_F32, 1, %i)", spec->rate_in, spec->rate_out);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(SDL_AUDIO_F32, %i, %i, SDL_AUDIO_F32, %i, %i)", num_channels, spec->rate_in, num_channels, spec->rate_out);
SDLTest_AssertCheck(stream != NULL, "Expected SDL_CreateAudioStream to succeed.");
if (stream == NULL) {
return TEST_ABORTED;
@@ -910,37 +1100,20 @@ static int audio_resampleLoss(void *arg)
tick_beg = SDL_GetPerformanceCounter();
ret = SDL_PutAudioStreamData(stream, buf_in, len_in);
SDLTest_AssertPass("Call to SDL_PutAudioStreamData(stream, buf_in, %i)", len_in);
SDLTest_AssertCheck(ret == 0, "Expected SDL_PutAudioStreamData to succeed.");
SDL_free(buf_in);
if (ret != 0) {
SDL_DestroyAudioStream(stream);
return TEST_ABORTED;
}
ret = SDL_FlushAudioStream(stream);
SDLTest_AssertPass("Call to SDL_FlushAudioStream(stream)");
SDLTest_AssertCheck(ret == 0, "Expected SDL_FlushAudioStream to succeed");
if (ret != 0) {
SDL_DestroyAudioStream(stream);
return TEST_ABORTED;
}
buf_out = (float *)SDL_malloc(len_target);
buf_out = (float *)SDL_malloc(max_target);
SDLTest_AssertCheck(buf_out != NULL, "Expected output buffer to be created.");
if (buf_out == NULL) {
SDL_DestroyAudioStream(stream);
return TEST_ABORTED;
}
len_out = SDL_GetAudioStreamData(stream, buf_out, len_target);
SDLTest_AssertPass("Call to SDL_GetAudioStreamData(stream, buf_out, %i)", len_target);
SDLTest_AssertCheck(len_out == len_target, "Expected output length to be no larger than %i, got %i.",
len_out = convert_audio_chunks(stream, buf_in, len_in, buf_out, max_target);
SDLTest_AssertPass("Call to convert_audio_chunks(stream, buf_in, %i, buf_out, %i)", len_in, len_target);
SDLTest_AssertCheck(len_out == len_target, "Expected output length to be %i, got %i.",
len_target, len_out);
SDL_DestroyAudioStream(stream);
if (len_out > len_target) {
SDL_free(buf_out);
SDL_free(buf_in);
if (len_out != len_target) {
SDL_DestroyAudioStream(stream);
return TEST_ABORTED;
}
@@ -959,11 +1132,11 @@ static int audio_resampleLoss(void *arg)
}
SDL_free(buf_out);
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
SDLTest_AssertCheck(isfinite(sum_squared_value), "Sum of squared target should be finite.");
SDLTest_AssertCheck(isfinite(sum_squared_error), "Sum of squared error should be finite.");
SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
/* Infinity is theoretically possible when there is very little to no noise */
SDLTest_AssertCheck(!isnan(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
SDLTest_AssertCheck(isfinite(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(signal_to_noise >= spec->signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
signal_to_noise, spec->signal_to_noise);
SDLTest_AssertCheck(max_error <= spec->max_error, "Maximum conversion error %f should be no more than %f.",
@@ -983,7 +1156,7 @@ static int audio_resampleLoss(void *arg)
*
* \sa SDL_ConvertAudioSamples
*/
static int audio_convertAccuracy(void *arg)
static int SDLCALL audio_convertAccuracy(void *arg)
{
static SDL_AudioFormat formats[] = { SDL_AUDIO_S8, SDL_AUDIO_U8, SDL_AUDIO_S16, SDL_AUDIO_S32 };
static const char* format_names[] = { "S8", "U8", "S16", "S32" };
@@ -1047,6 +1220,9 @@ static int audio_convertAccuracy(void *arg)
int tmp_len, dst_len;
int ret;
SDL_zero(src_spec);
SDL_zero(tmp_spec);
SDL_AudioFormat format = formats[i];
const char* format_name = format_names[i];
@@ -1072,8 +1248,8 @@ static int audio_convertAccuracy(void *arg)
tmp_data = NULL;
tmp_len = 0;
ret = SDL_ConvertAudioSamples(&src_spec, (const Uint8*) src_data, src_len, &tmp_spec, &tmp_data, &tmp_len);
SDLTest_AssertCheck(ret == 0, "Expected SDL_ConvertAudioSamples(F32->%s) to succeed", format_name);
if (ret != 0) {
SDLTest_AssertCheck(ret == true, "Expected SDL_ConvertAudioSamples(F32->%s) to succeed", format_name);
if (!ret) {
SDL_free(src_data);
return TEST_ABORTED;
}
@@ -1081,8 +1257,8 @@ static int audio_convertAccuracy(void *arg)
dst_data = NULL;
dst_len = 0;
ret = SDL_ConvertAudioSamples(&tmp_spec, tmp_data, tmp_len, &src_spec, &dst_data, &dst_len);
SDLTest_AssertCheck(ret == 0, "Expected SDL_ConvertAudioSamples(%s->F32) to succeed", format_name);
if (ret != 0) {
SDLTest_AssertCheck(ret == true, "Expected SDL_ConvertAudioSamples(%s->F32) to succeed", format_name);
if (!ret) {
SDL_free(tmp_data);
SDL_free(src_data);
return TEST_ABORTED;
@@ -1118,13 +1294,13 @@ static int audio_convertAccuracy(void *arg)
*
* \sa SDL_SetAudioStreamFormat
*/
static int audio_formatChange(void *arg)
static int SDLCALL audio_formatChange(void *arg)
{
int i;
SDL_AudioSpec spec1, spec2, spec3;
int frames_1, frames_2, frames_3;
int length_1, length_2, length_3;
int retval = 0;
int result = 0;
int status = TEST_ABORTED;
float* buffer_1 = NULL;
float* buffer_2 = NULL;
@@ -1138,6 +1314,10 @@ static int audio_formatChange(void *arg)
double target_signal_to_noise = 75.0;
int sine_freq = 500;
SDL_zero(spec1);
SDL_zero(spec2);
SDL_zero(spec3);
spec1.format = SDL_AUDIO_F32;
spec1.channels = 1;
spec1.freq = 20000;
@@ -1185,53 +1365,53 @@ static int audio_formatChange(void *arg)
goto cleanup;
}
retval = SDL_SetAudioStreamFormat(stream, &spec1, &spec3);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_SetAudioStreamFormat(spec1, spec3) to succeed")) {
result = SDL_SetAudioStreamFormat(stream, &spec1, &spec3);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_SetAudioStreamFormat(spec1, spec3) to succeed")) {
goto cleanup;
}
retval = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_GetAudioStreamAvailable return 0")) {
result = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(result == 0, "Expected SDL_GetAudioStreamAvailable return 0")) {
goto cleanup;
}
retval = SDL_PutAudioStreamData(stream, buffer_1, length_1);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) {
result = SDL_PutAudioStreamData(stream, buffer_1, length_1);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) {
goto cleanup;
}
retval = SDL_FlushAudioStream(stream);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_FlushAudioStream to succeed")) {
result = SDL_FlushAudioStream(stream);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_FlushAudioStream to succeed")) {
goto cleanup;
}
retval = SDL_SetAudioStreamFormat(stream, &spec2, &spec3);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_SetAudioStreamFormat(spec2, spec3) to succeed")) {
result = SDL_SetAudioStreamFormat(stream, &spec2, &spec3);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_SetAudioStreamFormat(spec2, spec3) to succeed")) {
goto cleanup;
}
retval = SDL_PutAudioStreamData(stream, buffer_2, length_2);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) {
result = SDL_PutAudioStreamData(stream, buffer_2, length_2);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) {
goto cleanup;
}
retval = SDL_FlushAudioStream(stream);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_FlushAudioStream to succeed")) {
result = SDL_FlushAudioStream(stream);
if (!SDLTest_AssertCheck(result == true, "Expected SDL_FlushAudioStream to succeed")) {
goto cleanup;
}
retval = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(retval == length_3, "Expected SDL_GetAudioStreamAvailable to return %i, got %i", length_3, retval)) {
result = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(result == length_3, "Expected SDL_GetAudioStreamAvailable to return %i, got %i", length_3, result)) {
goto cleanup;
}
retval = SDL_GetAudioStreamData(stream, buffer_3, length_3);
if (!SDLTest_AssertCheck(retval == length_3, "Expected SDL_GetAudioStreamData to return %i, got %i", length_3, retval)) {
result = SDL_GetAudioStreamData(stream, buffer_3, length_3);
if (!SDLTest_AssertCheck(result == length_3, "Expected SDL_GetAudioStreamData to return %i, got %i", length_3, result)) {
goto cleanup;
}
retval = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_GetAudioStreamAvailable to return 0")) {
result = SDL_GetAudioStreamAvailable(stream);
if (!SDLTest_AssertCheck(result == 0, "Expected SDL_GetAudioStreamAvailable to return 0")) {
goto cleanup;
}
@@ -1245,11 +1425,11 @@ static int audio_formatChange(void *arg)
}
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
SDLTest_AssertCheck(isfinite(sum_squared_value), "Sum of squared target should be finite.");
SDLTest_AssertCheck(isfinite(sum_squared_error), "Sum of squared error should be finite.");
SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
/* Infinity is theoretically possible when there is very little to no noise */
SDLTest_AssertCheck(!isnan(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
SDLTest_AssertCheck(isfinite(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(signal_to_noise >= target_signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
signal_to_noise, target_signal_to_noise);
SDLTest_AssertCheck(max_error <= target_max_error, "Maximum conversion error %f should be no more than %f.",
@@ -1268,8 +1448,12 @@ cleanup:
/* ================= Test Case References ================== */
/* Audio test cases */
static const SDLTest_TestCaseReference audioTestGetAudioFormatName = {
audio_getAudioFormatName, "audio_getAudioFormatName", "Call to SDL_GetAudioFormatName", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest1 = {
audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED
audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (playback and recording)", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest2 = {
@@ -1344,6 +1528,7 @@ static const SDLTest_TestCaseReference audioTest18 = {
/* Sequence of Audio test cases */
static const SDLTest_TestCaseReference *audioTests[] = {
&audioTestGetAudioFormatName,
&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
&audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
&audioTest12, &audioTest13, &audioTest14, &audioTest15, &audioTest16,