From 0af075b5ffb98e9093cd174862d4289ef4d98252 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Thu, 8 Mar 2018 20:26:31 +0100 Subject: SDL2 backend: Allow changes to channels and format --- Alc/backends/sdl2.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'Alc') diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c index a52b22c8..414dbe19 100644 --- a/Alc/backends/sdl2.c +++ b/Alc/backends/sdl2.c @@ -100,12 +100,33 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name) if (name && strcmp(name, defaultDeviceName) == 0) name = NULL; // Passing NULL to SDL_OpenAudioDevice is special and will NOT select the first // device in the list. - self->deviceID = SDL_OpenAudioDevice(name, 0, &want, &have, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); + self->deviceID = SDL_OpenAudioDevice(name, 0, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE); if(want.freq != have.freq) { TRACE("Frequency changed by SDL2\n"); device->Frequency = have.freq; } + if(have.channels == 1) + device->FmtChans = DevFmtMono; + else if(have.channels == 2) + device->FmtChans = DevFmtStereo; + else + { + ERR("Invalid number of channels\n"); + return ALC_INVALID_VALUE; + } + switch(have.format) + { + case AUDIO_U8: device->FmtType = DevFmtUByte; break; + case AUDIO_S8: device->FmtType = DevFmtByte; break; + case AUDIO_U16SYS: device->FmtType = DevFmtUShort; break; + case AUDIO_S16SYS: device->FmtType = DevFmtShort; break; + case AUDIO_S32SYS: device->FmtType = DevFmtInt; break; + case AUDIO_F32SYS: device->FmtType = DevFmtFloat; break; + default: + ERR("Unsupported format\n"); + return ALC_INVALID_VALUE; + } if(self->deviceID == 0) { ERR("Could not open device\n"); return ALC_INVALID_VALUE; -- cgit v1.2.3