diff options
author | Chris Robinson <[email protected]> | 2021-07-30 06:13:54 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-07-30 06:13:54 -0700 |
commit | 3b3df06195ad94588b4b1d2d9a8ddb3d9eba84c6 (patch) | |
tree | 121988f4b6ce3698d635e70ca994113f7dd7f5c8 /alc/backends/sdl2.cpp | |
parent | 1fd4c865fc084f134363db5155361d5483679235 (diff) |
Be more robust with unexpected channel counts
Diffstat (limited to 'alc/backends/sdl2.cpp')
-rw-r--r-- | alc/backends/sdl2.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index b1f9cf12..c0726033 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -28,6 +28,7 @@ #include <string> #include "almalloc.h" +#include "alnumeric.h" #include "core/device.h" #include "core/logging.h" @@ -98,7 +99,7 @@ void Sdl2Backend::open(const char *name) case DevFmtFloat: want.format = AUDIO_F32; break; } want.channels = (mDevice->FmtChans == DevFmtMono) ? 1 : 2; - want.samples = static_cast<Uint16>(mDevice->UpdateSize); + want.samples = static_cast<Uint16>(minu(mDevice->UpdateSize, 8192)); want.callback = &Sdl2Backend::audioCallbackC; want.userdata = this; @@ -121,10 +122,10 @@ void Sdl2Backend::open(const char *name) throw al::backend_exception{al::backend_error::NoDevice, "%s", SDL_GetError()}; DevFmtChannels devchans{}; - if(have.channels == 1) - devchans = DevFmtMono; - else if(have.channels == 2) + if(have.channels >= 2) devchans = DevFmtStereo; + else if(have.channels == 1) + devchans = DevFmtMono; else { SDL_CloseAudioDevice(devid); @@ -151,7 +152,7 @@ void Sdl2Backend::open(const char *name) SDL_CloseAudioDevice(mDeviceID); mDeviceID = devid; - mFrameSize = FrameSizeFromDevFmt(devchans, devtype, 0); + mFrameSize = BytesFromDevFmt(devtype) * have.channels; mFrequency = static_cast<uint>(have.freq); mFmtChans = devchans; mFmtType = devtype; |