From f77437cd4ba6d122e2e3dead8f31a626eb805a67 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Fri, 20 Apr 2018 18:23:42 +0200 Subject: [PATCH] Switch: Enable more audio formats with resampling (#12) Instead of erroring out, just tell SDL2 we want a different format, so it will do the necessary steps (configuring the resampler) and still feed us with a format known supported by the hardware. --- src/audio/switch/SDL_switchaudio.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/audio/switch/SDL_switchaudio.c b/src/audio/switch/SDL_switchaudio.c index b3568a427..961c2cf0d 100644 --- a/src/audio/switch/SDL_switchaudio.c +++ b/src/audio/switch/SDL_switchaudio.c @@ -36,7 +36,11 @@ static int SWITCHAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) { - Result res = audoutInitialize(); + Result res; + SDL_bool supported_format = SDL_FALSE; + SDL_AudioFormat test_format; + + res = audoutInitialize(); if (res != 0) { return SDL_SetError("audoutInitialize failed (0x%x)", res); } @@ -53,15 +57,19 @@ SWITCHAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) } SDL_zerop(this->hidden); - switch (this->spec.format & 0xff) { - case 8: - case 16: - this->spec.format = AUDIO_S16LSB; - break; - default: - return SDL_SetError("Unsupported audio format"); + test_format = SDL_FirstAudioFormat(this->spec.format); + while ((!supported_format) && (test_format)) { + if (test_format == AUDIO_S16LSB) { + supported_format = SDL_TRUE; + } else { + test_format = SDL_NextAudioFormat(); + } + } + if (!supported_format) { + return SDL_SetError("Unsupported audio format"); } + this->spec.format = test_format; this->spec.freq = 48000; this->spec.channels = 2;