Move the stereo-to-binaural filter to the device
This commit is contained in:
parent
6636131d3b
commit
12f81bcbb9
30
Alc/ALc.c
30
Alc/ALc.c
@ -534,8 +534,6 @@ ALCcontext *GetContextSuspended(void)
|
|||||||
*/
|
*/
|
||||||
static ALvoid InitContext(ALCcontext *pContext)
|
static ALvoid InitContext(ALCcontext *pContext)
|
||||||
{
|
{
|
||||||
int level;
|
|
||||||
|
|
||||||
//Initialise listener
|
//Initialise listener
|
||||||
pContext->Listener.Gain = 1.0f;
|
pContext->Listener.Gain = 1.0f;
|
||||||
pContext->Listener.MetersPerUnit = 1.0f;
|
pContext->Listener.MetersPerUnit = 1.0f;
|
||||||
@ -567,14 +565,6 @@ static ALvoid InitContext(ALCcontext *pContext)
|
|||||||
|
|
||||||
pContext->ExtensionList = "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_EXTX_sample_buffer_object AL_EXTX_source_distance_model AL_LOKI_quadriphonic";
|
pContext->ExtensionList = "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_EXTX_sample_buffer_object AL_EXTX_source_distance_model AL_LOKI_quadriphonic";
|
||||||
|
|
||||||
level = GetConfigValueInt(NULL, "cf_level", 0);
|
|
||||||
if(level > 0 && level <= 6)
|
|
||||||
{
|
|
||||||
pContext->bs2b = calloc(1, sizeof(*pContext->bs2b));
|
|
||||||
bs2b_set_srate(pContext->bs2b, pContext->Frequency);
|
|
||||||
bs2b_set_level(pContext->bs2b, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
aluInitPanning(pContext);
|
aluInitPanning(pContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,9 +579,6 @@ static ALCvoid ExitContext(ALCcontext *pContext)
|
|||||||
//Invalidate context
|
//Invalidate context
|
||||||
pContext->LastError = AL_NO_ERROR;
|
pContext->LastError = AL_NO_ERROR;
|
||||||
pContext->InUse = AL_FALSE;
|
pContext->InUse = AL_FALSE;
|
||||||
|
|
||||||
free(pContext->bs2b);
|
|
||||||
pContext->bs2b = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
@ -1174,6 +1161,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint
|
|||||||
// Check for attributes
|
// Check for attributes
|
||||||
if (attrList)
|
if (attrList)
|
||||||
{
|
{
|
||||||
|
ALCint level = device->Bs2bLevel;
|
||||||
ALCuint freq = device->Frequency;
|
ALCuint freq = device->Frequency;
|
||||||
ALCint numMono = device->lNumMonoSources;
|
ALCint numMono = device->lNumMonoSources;
|
||||||
ALCint numStereo = device->lNumStereoSources;
|
ALCint numStereo = device->lNumStereoSources;
|
||||||
@ -1213,12 +1201,22 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint
|
|||||||
ulAttributeIndex += 2;
|
ulAttributeIndex += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", level);
|
||||||
device->Frequency = GetConfigValueInt(NULL, "frequency", freq);
|
device->Frequency = GetConfigValueInt(NULL, "frequency", freq);
|
||||||
device->lNumMonoSources = numMono;
|
device->lNumMonoSources = numMono;
|
||||||
device->lNumStereoSources = numStereo;
|
device->lNumStereoSources = numStereo;
|
||||||
device->NumAuxSends = numSends;
|
device->NumAuxSends = numSends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(device->Bs2b);
|
||||||
|
device->Bs2b = NULL;
|
||||||
|
if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
|
||||||
|
{
|
||||||
|
device->Bs2b = calloc(1, sizeof(*device->Bs2b));
|
||||||
|
bs2b_set_srate(device->Bs2b, device->Frequency);
|
||||||
|
bs2b_set_level(device->Bs2b, device->Bs2bLevel);
|
||||||
|
}
|
||||||
|
|
||||||
if(ALCdevice_StartContext(device, ALContext) == ALC_FALSE)
|
if(ALCdevice_StartContext(device, ALContext) == ALC_FALSE)
|
||||||
{
|
{
|
||||||
alcDestroyContext(ALContext);
|
alcDestroyContext(ALContext);
|
||||||
@ -1476,6 +1474,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
|
|||||||
device->Connected = ALC_TRUE;
|
device->Connected = ALC_TRUE;
|
||||||
device->IsCaptureDevice = AL_FALSE;
|
device->IsCaptureDevice = AL_FALSE;
|
||||||
|
|
||||||
|
device->Bs2b = NULL;
|
||||||
device->szDeviceName = NULL;
|
device->szDeviceName = NULL;
|
||||||
|
|
||||||
//Set output format
|
//Set output format
|
||||||
@ -1505,6 +1504,8 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
|
|||||||
if(device->NumAuxSends > MAX_SENDS)
|
if(device->NumAuxSends > MAX_SENDS)
|
||||||
device->NumAuxSends = MAX_SENDS;
|
device->NumAuxSends = MAX_SENDS;
|
||||||
|
|
||||||
|
device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
|
||||||
|
|
||||||
// Find a playback device to open
|
// Find a playback device to open
|
||||||
SuspendContext(NULL);
|
SuspendContext(NULL);
|
||||||
for(i = 0;BackendList[i].Init;i++)
|
for(i = 0;BackendList[i].Init;i++)
|
||||||
@ -1598,6 +1599,9 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
|
|||||||
ReleaseALDatabuffers(pDevice);
|
ReleaseALDatabuffers(pDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(pDevice->Bs2b);
|
||||||
|
pDevice->Bs2b = NULL;
|
||||||
|
|
||||||
free(pDevice->szDeviceName);
|
free(pDevice->szDeviceName);
|
||||||
|
|
||||||
//Release device structure
|
//Release device structure
|
||||||
|
@ -1258,14 +1258,14 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma
|
|||||||
} \
|
} \
|
||||||
break; \
|
break; \
|
||||||
case AL_FORMAT_STEREO##bits: \
|
case AL_FORMAT_STEREO##bits: \
|
||||||
if(ALContext && ALContext->bs2b) \
|
if(ALContext && ALContext->Device->Bs2b) \
|
||||||
{ \
|
{ \
|
||||||
for(i = 0;i < SamplesToDo;i++) \
|
for(i = 0;i < SamplesToDo;i++) \
|
||||||
{ \
|
{ \
|
||||||
float samples[2]; \
|
float samples[2]; \
|
||||||
samples[0] = DryBuffer[i][FRONT_LEFT]; \
|
samples[0] = DryBuffer[i][FRONT_LEFT]; \
|
||||||
samples[1] = DryBuffer[i][FRONT_RIGHT]; \
|
samples[1] = DryBuffer[i][FRONT_RIGHT]; \
|
||||||
bs2b_cross_feed(ALContext->bs2b, samples); \
|
bs2b_cross_feed(ALContext->Device->Bs2b, samples); \
|
||||||
((type*)buffer)[0] = (func)(samples[0]); \
|
((type*)buffer)[0] = (func)(samples[0]); \
|
||||||
((type*)buffer)[1] = (func)(samples[1]); \
|
((type*)buffer)[1] = (func)(samples[1]); \
|
||||||
buffer = ((type*)buffer) + 2; \
|
buffer = ((type*)buffer) + 2; \
|
||||||
|
@ -240,6 +240,10 @@ struct ALCdevice_struct
|
|||||||
struct ALdatabuffer *Databuffers;
|
struct ALdatabuffer *Databuffers;
|
||||||
ALuint DatabufferCount;
|
ALuint DatabufferCount;
|
||||||
|
|
||||||
|
// Stereo-to-binaural filter
|
||||||
|
struct bs2b *Bs2b;
|
||||||
|
ALCint Bs2bLevel;
|
||||||
|
|
||||||
// Context created on this device
|
// Context created on this device
|
||||||
ALCcontext *Context;
|
ALCcontext *Context;
|
||||||
|
|
||||||
@ -292,8 +296,6 @@ struct ALCcontext_struct
|
|||||||
ALCdevice *Device;
|
ALCdevice *Device;
|
||||||
const ALCchar *ExtensionList;
|
const ALCchar *ExtensionList;
|
||||||
|
|
||||||
struct bs2b *bs2b;
|
|
||||||
|
|
||||||
ALCcontext *next;
|
ALCcontext *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user