audio: Add channel remapping to SDL_AudioSpec and SDL_AudioStream.

Fixes #8367.
This commit is contained in:
Ryan C. Gordon 2024-07-03 03:19:00 -04:00
parent 0367f1af19
commit 16e7fdc4f2
12 changed files with 254 additions and 193 deletions

View file

@ -109,6 +109,7 @@ static void queue_audio()
int retval = 0;
SDL_AudioSpec new_spec;
SDL_zero(new_spec);
new_spec.format = spec.format;
new_spec.channels = (int) sliders[2].value;
new_spec.freq = (int) sliders[1].value;

View file

@ -181,7 +181,7 @@ static int audio_initOpenCloseQuitAudio(void *arg)
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
SDL_zero(desired);
switch (j) {
case 0:
/* Set standard desired spec */
@ -272,7 +272,7 @@ static int audio_pauseUnpauseAudio(void *arg)
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
SDL_zero(desired);
switch (j) {
case 0:
/* Set standard desired spec */
@ -496,6 +496,9 @@ static int audio_buildAudioStream(void *arg)
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)");
@ -567,6 +570,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;
@ -678,6 +684,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);
@ -995,6 +1004,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);
@ -1147,6 +1159,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];
@ -1238,6 +1253,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;

View file

@ -1167,7 +1167,7 @@ static AVCodecContext *OpenAudioStream(AVFormatContext *ic, int stream, const AV
return NULL;
}
SDL_AudioSpec spec = { SDL_AUDIO_F32, codecpar->ch_layout.nb_channels, codecpar->sample_rate };
SDL_AudioSpec spec = { SDL_AUDIO_F32, codecpar->ch_layout.nb_channels, codecpar->sample_rate, SDL_FALSE };
audio = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
if (audio) {
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(audio));
@ -1240,7 +1240,7 @@ static void InterleaveAudio(AVFrame *frame, const SDL_AudioSpec *spec)
static void HandleAudioFrame(AVFrame *frame)
{
if (audio) {
SDL_AudioSpec spec = { GetAudioFormat(frame->format), frame->ch_layout.nb_channels, frame->sample_rate };
SDL_AudioSpec spec = { GetAudioFormat(frame->format), frame->ch_layout.nb_channels, frame->sample_rate, SDL_FALSE };
SDL_SetAudioStreamFormat(audio, &spec, NULL);
if (frame->ch_layout.nb_channels > 1 && IsPlanarAudioFormat(frame->format)) {