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.
This commit is contained in:
Carsten Teibes 2018-04-20 18:23:42 +02:00 committed by Dave Murphy
parent bf248dd581
commit f77437cd4b
1 changed files with 16 additions and 8 deletions

View File

@ -36,7 +36,11 @@
static int static int
SWITCHAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) 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) { if (res != 0) {
return SDL_SetError("audoutInitialize failed (0x%x)", res); 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); SDL_zerop(this->hidden);
switch (this->spec.format & 0xff) { test_format = SDL_FirstAudioFormat(this->spec.format);
case 8: while ((!supported_format) && (test_format)) {
case 16: if (test_format == AUDIO_S16LSB) {
this->spec.format = AUDIO_S16LSB; supported_format = SDL_TRUE;
break; } else {
default: test_format = SDL_NextAudioFormat();
return SDL_SetError("Unsupported audio format"); }
}
if (!supported_format) {
return SDL_SetError("Unsupported audio format");
} }
this->spec.format = test_format;
this->spec.freq = 48000; this->spec.freq = 48000;
this->spec.channels = 2; this->spec.channels = 2;