Move the InitRenderer method to panning.c

This commit is contained in:
Chris Robinson 2016-04-14 15:25:12 -07:00
parent 221281688f
commit 65a9b97e46
3 changed files with 187 additions and 187 deletions

187
Alc/ALc.c
View File

@ -35,10 +35,7 @@
#include "alBuffer.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "bs2b.h"
#include "uhjfilter.h"
#include "bformatdec.h"
#include "ambdec.h"
#include "alu.h"
#include "compat.h"
@ -1409,11 +1406,6 @@ DECL_CONST static ALCboolean IsValidALCChannels(ALCenum channels)
/************************************************
* Miscellaneous ALC helpers
************************************************/
enum HrtfRequestMode {
Hrtf_Default = 0,
Hrtf_Enable = 1,
Hrtf_Disable = 2,
};
extern inline void LockContext(ALCcontext *context);
extern inline void UnlockContext(ALCcontext *context);
@ -1654,173 +1646,6 @@ static inline void UpdateClockBase(ALCdevice *device)
device->SamplesDone = 0;
}
/* InitRenderer
*
* Set up the appropriate panning method and mixing method given the device
* properties.
*/
static void InitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
{
ALCenum hrtf_status;
const char *mode;
bool headphones;
int bs2blevel;
int usehrtf;
size_t i;
device->Hrtf = NULL;
al_string_clear(&device->Hrtf_Name);
device->Render_Mode = NormalRender;
if(device->FmtChans != DevFmtStereo)
{
if(hrtf_appreq == Hrtf_Enable)
device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "decoder", "hq-mode", 0))
{
if(!device->AmbiDecoder)
device->AmbiDecoder = bformatdec_alloc();
}
else
{
bformatdec_free(device->AmbiDecoder);
device->AmbiDecoder = NULL;
}
aluInitPanning(device);
return;
}
bformatdec_free(device->AmbiDecoder);
device->AmbiDecoder = NULL;
hrtf_status = device->Hrtf_Status;
headphones = device->IsHeadphones;
if(device->Type != Loopback)
{
const char *mode;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode))
{
if(strcasecmp(mode, "headphones") == 0)
headphones = true;
else if(strcasecmp(mode, "speakers") == 0)
headphones = false;
else if(strcasecmp(mode, "auto") != 0)
ERR("Unexpected stereo-mode: %s\n", mode);
}
}
if(hrtf_userreq == Hrtf_Default)
{
usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
(hrtf_appreq == Hrtf_Enable);
if(headphones && hrtf_appreq != Hrtf_Disable)
hrtf_status = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
else if(usehrtf)
hrtf_status = ALC_HRTF_ENABLED_SOFT;
}
else
{
usehrtf = (hrtf_userreq == Hrtf_Enable);
if(!usehrtf)
hrtf_status = ALC_HRTF_DENIED_SOFT;
else
hrtf_status = ALC_HRTF_REQUIRED_SOFT;
}
if(!usehrtf)
{
device->Hrtf_Status = hrtf_status;
goto no_hrtf;
}
device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
if(VECTOR_SIZE(device->Hrtf_List) == 0)
{
VECTOR_DEINIT(device->Hrtf_List);
device->Hrtf_List = EnumerateHrtf(device->DeviceName);
}
if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
{
const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, hrtf_id);
if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
{
device->Hrtf = entry->hrtf;
al_string_copy(&device->Hrtf_Name, entry->name);
}
}
for(i = 0;!device->Hrtf && i < VECTOR_SIZE(device->Hrtf_List);i++)
{
const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, i);
if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
{
device->Hrtf = entry->hrtf;
al_string_copy(&device->Hrtf_Name, entry->name);
}
}
if(device->Hrtf)
{
device->Hrtf_Status = hrtf_status;
device->Render_Mode = NormalRender;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
{
if(strcasecmp(mode, "full") == 0)
device->Render_Mode = HrtfRender;
else if(strcasecmp(mode, "basic") == 0)
device->Render_Mode = NormalRender;
else
ERR("Unexpected hrtf-mode: %s\n", mode);
}
TRACE("HRTF enabled, \"%s\"\n", al_string_get_cstr(device->Hrtf_Name));
aluInitHrtfPanning(device);
return;
}
no_hrtf:
TRACE("HRTF disabled\n");
bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) ||
(hrtf_appreq == Hrtf_Enable)) ? 5 : 0;
if(device->Type != Loopback)
ConfigValueInt(al_string_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel);
if(bs2blevel > 0 && bs2blevel <= 6)
{
device->Bs2b = al_calloc(16, sizeof(*device->Bs2b));
bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
device->Render_Mode = StereoPair;
TRACE("BS2B enabled\n");
aluInitPanning(device);
return;
}
TRACE("BS2B disabled\n");
device->Render_Mode = NormalRender;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "stereo-panning", &mode))
{
if(strcasecmp(mode, "paired") == 0)
device->Render_Mode = StereoPair;
else if(strcasecmp(mode, "uhj") != 0)
ERR("Unexpected stereo-panning: %s\n", mode);
}
if(device->Render_Mode == NormalRender)
{
device->Uhj_Encoder = al_calloc(16, sizeof(Uhj2Encoder));
TRACE("UHJ enabled\n");
aluInitUhjPanning(device);
return;
}
TRACE("UHJ disabled\n");
aluInitPanning(device);
}
/* UpdateDeviceParams
*
* Updates device parameters according to the attribute list (caller is
@ -2139,11 +1964,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
}
TRACE("Post-reset: %s, %s, %uhz, %u update size x%d\n",
DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
device->Frequency, device->UpdateSize, device->NumUpdates
);
if((device->UpdateSize&3) != 0)
{
if((CPUCapFlags&CPU_CAP_SSE))
@ -2152,7 +1972,12 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
WARN("NEON performs best with multiple of 4 update sizes (%u)\n", device->UpdateSize);
}
InitRenderer(device, hrtf_id, hrtf_appreq, hrtf_userreq);
TRACE("Post-reset: %s, %s, %uhz, %u update size x%d\n",
DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
device->Frequency, device->UpdateSize, device->NumUpdates
);
aluInitRenderer(device, hrtf_id, hrtf_appreq, hrtf_userreq);
/* Allocate extra channels for any post-filter output. */
size = device->Dry.NumChannels * sizeof(device->Dry.Buffer[0]);

View File

@ -32,6 +32,8 @@
#include "bool.h"
#include "ambdec.h"
#include "bformatdec.h"
#include "uhjfilter.h"
#include "bs2b.h"
extern inline void CalcXYZCoeffs(ALfloat x, ALfloat y, ALfloat z, ALfloat coeffs[MAX_AMBI_COEFFS]);
@ -625,7 +627,7 @@ static const ChannelMap MonoCfg[1] = {
{ Aux3, { 0.0f, 0.0f, 0.0f, 1.0f } },
};
ALvoid aluInitPanning(ALCdevice *device)
static void InitPanning(ALCdevice *device)
{
const ChannelMap *chanmap = NULL;
ALfloat ambiscale;
@ -715,7 +717,7 @@ ALvoid aluInitPanning(ALCdevice *device)
}
}
ALvoid aluInitHrtfPanning(ALCdevice *device)
static void InitHrtfPanning(ALCdevice *device)
{
static const struct {
enum Channel Channel;
@ -756,7 +758,7 @@ ALvoid aluInitHrtfPanning(ALCdevice *device)
}
}
ALvoid aluInitUhjPanning(ALCdevice *device)
static void InitUhjPanning(ALCdevice *device)
{
const ChannelMap *chanmap = BFormat2D;
size_t count = COUNTOF(BFormat2D);
@ -776,6 +778,169 @@ ALvoid aluInitUhjPanning(ALCdevice *device)
sizeof(device->FOAOut.AmbiCoeffs));
}
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
{
ALCenum hrtf_status;
const char *mode;
bool headphones;
int bs2blevel;
int usehrtf;
size_t i;
device->Hrtf = NULL;
al_string_clear(&device->Hrtf_Name);
device->Render_Mode = NormalRender;
if(device->FmtChans != DevFmtStereo)
{
if(hrtf_appreq == Hrtf_Enable)
device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "decoder", "hq-mode", 0))
{
if(!device->AmbiDecoder)
device->AmbiDecoder = bformatdec_alloc();
}
else
{
bformatdec_free(device->AmbiDecoder);
device->AmbiDecoder = NULL;
}
InitPanning(device);
return;
}
bformatdec_free(device->AmbiDecoder);
device->AmbiDecoder = NULL;
hrtf_status = device->Hrtf_Status;
headphones = device->IsHeadphones;
if(device->Type != Loopback)
{
const char *mode;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode))
{
if(strcasecmp(mode, "headphones") == 0)
headphones = true;
else if(strcasecmp(mode, "speakers") == 0)
headphones = false;
else if(strcasecmp(mode, "auto") != 0)
ERR("Unexpected stereo-mode: %s\n", mode);
}
}
if(hrtf_userreq == Hrtf_Default)
{
usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
(hrtf_appreq == Hrtf_Enable);
if(headphones && hrtf_appreq != Hrtf_Disable)
hrtf_status = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
else if(usehrtf)
hrtf_status = ALC_HRTF_ENABLED_SOFT;
}
else
{
usehrtf = (hrtf_userreq == Hrtf_Enable);
if(!usehrtf)
hrtf_status = ALC_HRTF_DENIED_SOFT;
else
hrtf_status = ALC_HRTF_REQUIRED_SOFT;
}
if(!usehrtf)
{
device->Hrtf_Status = hrtf_status;
goto no_hrtf;
}
device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
if(VECTOR_SIZE(device->Hrtf_List) == 0)
{
VECTOR_DEINIT(device->Hrtf_List);
device->Hrtf_List = EnumerateHrtf(device->DeviceName);
}
if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
{
const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, hrtf_id);
if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
{
device->Hrtf = entry->hrtf;
al_string_copy(&device->Hrtf_Name, entry->name);
}
}
for(i = 0;!device->Hrtf && i < VECTOR_SIZE(device->Hrtf_List);i++)
{
const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, i);
if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
{
device->Hrtf = entry->hrtf;
al_string_copy(&device->Hrtf_Name, entry->name);
}
}
if(device->Hrtf)
{
device->Hrtf_Status = hrtf_status;
device->Render_Mode = NormalRender;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
{
if(strcasecmp(mode, "full") == 0)
device->Render_Mode = HrtfRender;
else if(strcasecmp(mode, "basic") == 0)
device->Render_Mode = NormalRender;
else
ERR("Unexpected hrtf-mode: %s\n", mode);
}
TRACE("HRTF enabled, \"%s\"\n", al_string_get_cstr(device->Hrtf_Name));
InitHrtfPanning(device);
return;
}
no_hrtf:
TRACE("HRTF disabled\n");
bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) ||
(hrtf_appreq == Hrtf_Enable)) ? 5 : 0;
if(device->Type != Loopback)
ConfigValueInt(al_string_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel);
if(bs2blevel > 0 && bs2blevel <= 6)
{
device->Bs2b = al_calloc(16, sizeof(*device->Bs2b));
bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
device->Render_Mode = StereoPair;
TRACE("BS2B enabled\n");
InitPanning(device);
return;
}
TRACE("BS2B disabled\n");
device->Render_Mode = NormalRender;
if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "stereo-panning", &mode))
{
if(strcasecmp(mode, "paired") == 0)
device->Render_Mode = StereoPair;
else if(strcasecmp(mode, "uhj") != 0)
ERR("Unexpected stereo-panning: %s\n", mode);
}
if(device->Render_Mode == NormalRender)
{
device->Uhj_Encoder = al_calloc(16, sizeof(Uhj2Encoder));
TRACE("UHJ enabled\n");
InitUhjPanning(device);
return;
}
TRACE("UHJ disabled\n");
InitPanning(device);
}
void aluInitEffectPanning(ALeffectslot *slot)
{
static const ChannelMap FirstOrderN3D[4] = {

View File

@ -278,11 +278,21 @@ inline ALfloat resample_fir8(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat v
}
enum HrtfRequestMode {
Hrtf_Default = 0,
Hrtf_Enable = 1,
Hrtf_Disable = 2,
};
void aluInitMixer(void);
ALvoid aluInitPanning(ALCdevice *Device);
ALvoid aluInitHrtfPanning(ALCdevice *device);
ALvoid aluInitUhjPanning(ALCdevice *device);
/* aluInitRenderer
*
* Set up the appropriate panning method and mixing method given the device
* properties.
*/
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq);
void aluInitEffectPanning(struct ALeffectslot *slot);