aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorJan Niklas Hasse <[email protected]>2018-03-08 20:39:15 +0100
committerJan Niklas Hasse <[email protected]>2018-03-08 20:42:47 +0100
commit2eb29d538b0e90a48f45f55eaf110fa114b17f35 (patch)
treef2b38fb93b90495eadcf144877b616f0d88bd064 /Alc
parent0af075b5ffb98e9093cd174862d4289ef4d98252 (diff)
SDL2 backend: Reset device parameters
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/sdl2.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c
index 414dbe19..9bd42cdf 100644
--- a/Alc/backends/sdl2.c
+++ b/Alc/backends/sdl2.c
@@ -36,7 +36,9 @@ typedef struct ALCsdl2Backend {
SDL_AudioDeviceID deviceID;
ALCboolean quit;
- althrd_t thread;
+ ALuint Frequency;
+ enum DevFmtChannels FmtChans;
+ enum DevFmtType FmtType;
} ALCsdl2Backend;
static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device);
@@ -62,6 +64,9 @@ static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device)
SET_VTABLE2(ALCsdl2Backend, ALCbackend, self);
self->quit = ALC_FALSE;
+ self->Frequency = device->Frequency;
+ self->FmtChans = device->FmtChans;
+ self->FmtType = device->FmtType;
if(SDL_WasInit(0) == 0) // Is SDL2 initialized at all?
{
SDL_Init(SDL_INIT_AUDIO);
@@ -92,7 +97,7 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name)
SDL_zero(want);
want.freq = device->Frequency;
want.format = AUDIO_F32;
- want.channels = 2;
+ want.channels = (device->FmtChans == DevFmtMono) ? 1 : 2;
want.samples = device->UpdateSize;
want.callback = ALCsdl2Backend_audioCallback;
want.userdata = self;
@@ -101,6 +106,11 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name)
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_ANY_CHANGE);
+ if(self->deviceID == 0)
+ {
+ ERR("Could not open device\n");
+ return ALC_INVALID_VALUE;
+ }
if(want.freq != have.freq)
{
TRACE("Frequency changed by SDL2\n");
@@ -127,10 +137,9 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name)
ERR("Unsupported format\n");
return ALC_INVALID_VALUE;
}
- if(self->deviceID == 0) {
- ERR("Could not open device\n");
- return ALC_INVALID_VALUE;
- }
+ self->Frequency = device->Frequency;
+ self->FmtChans = device->FmtChans;
+ self->FmtType = device->FmtType;
if(!name)
name = defaultDeviceName;
alstr_copy_cstr(&STATIC_CAST(ALCbackend, self)->mDevice->DeviceName, name);
@@ -140,7 +149,11 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name)
static ALCboolean ALCsdl2Backend_reset(ALCsdl2Backend *self)
{
- SetDefaultWFXChannelOrder(STATIC_CAST(ALCbackend, self)->mDevice);
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ device->Frequency = self->Frequency;
+ device->FmtChans = self->FmtChans;
+ device->FmtType = self->FmtType;
+ SetDefaultWFXChannelOrder(device);
return ALC_TRUE;
}