Return int and float config values through a parameter

This allows the getter functions to return whether or not the option exists
without a separate call and check.
This commit is contained in:
Chris Robinson 2011-09-18 16:16:55 -07:00
parent d46db2f648
commit 7e06a10f73
5 changed files with 89 additions and 68 deletions

117
Alc/ALc.c
View File

@ -559,6 +559,7 @@ static void alc_deinit(void)
static void alc_initconfig(void) static void alc_initconfig(void)
{ {
const char *devs, *str; const char *devs, *str;
float valf;
int i, n; int i, n;
str = getenv("ALSOFT_LOGLEVEL"); str = getenv("ALSOFT_LOGLEVEL");
@ -582,14 +583,17 @@ static void alc_initconfig(void)
InitHrtf(); InitHrtf();
#ifdef _WIN32 #ifdef _WIN32
RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 1); RTPrioLevel = 1;
#else #else
RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0); RTPrioLevel = 0;
#endif #endif
ConfigValueInt(NULL, "rt-prio", &RTPrioLevel);
DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT); if(ConfigValueInt(NULL, "resampler", &n))
if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN) {
DefaultResampler = RESAMPLER_DEFAULT; if(n < RESAMPLER_MAX && n > RESAMPLER_MIN)
DefaultResampler = n;
}
if(!TrapALCError) if(!TrapALCError)
TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", ALC_FALSE); TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", ALC_FALSE);
@ -597,8 +601,9 @@ static void alc_initconfig(void)
if(!TrapALError) if(!TrapALError)
TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE); TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE);
ReverbBoost *= aluPow(10.0f, GetConfigValueFloat("reverb", "boost", 0.0f) / if(ConfigValueFloat("reverb", "boost", &valf))
20.0f); ReverbBoost *= aluPow(10.0f, valf / 20.0f);
EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE); EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
devs = GetConfigValue(NULL, "drivers", ""); devs = GetConfigValue(NULL, "drivers", "");
@ -1080,9 +1085,6 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numStereo = device->NumStereoSources; numStereo = device->NumStereoSources;
numSends = device->NumAuxSends; numSends = device->NumAuxSends;
freq = GetConfigValueInt(NULL, "frequency", freq);
if(freq < 8000) freq = 8000;
attrIdx = 0; attrIdx = 0;
while(attrList[attrIdx]) while(attrList[attrIdx])
{ {
@ -1121,10 +1123,9 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
return ALC_FALSE; return ALC_FALSE;
} }
} }
else if(!ConfigValueExists(NULL, "frequency")) else
{ {
freq = attrList[attrIdx + 1]; freq = attrList[attrIdx + 1];
if(freq < 8000) freq = 8000;
device->Flags |= DEVICE_FREQUENCY_REQUEST; device->Flags |= DEVICE_FREQUENCY_REQUEST;
} }
} }
@ -1138,17 +1139,20 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numMono = device->MaxNoOfSources - numStereo; numMono = device->MaxNoOfSources - numStereo;
} }
if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS && if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
!ConfigValueExists(NULL, "sends"))
{
numSends = attrList[attrIdx + 1]; numSends = attrList[attrIdx + 1];
if(numSends > MAX_SENDS)
numSends = MAX_SENDS;
}
attrIdx += 2; attrIdx += 2;
} }
if(!device->IsLoopbackDevice)
{
ConfigValueUInt(NULL, "frequency", &freq);
freq = maxu(freq, 8000);
}
ConfigValueUInt(NULL, "sends", &numSends);
numSends = minu(MAX_SENDS, numSends);
device->UpdateSize = (ALuint64)device->UpdateSize * freq / device->UpdateSize = (ALuint64)device->UpdateSize * freq /
device->Frequency; device->Frequency;
@ -2459,51 +2463,53 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->Flags = 0; device->Flags = 0;
device->Bs2b = NULL; device->Bs2b = NULL;
device->Bs2bLevel = 0;
device->szDeviceName = NULL; device->szDeviceName = NULL;
device->ContextList = NULL; device->ContextList = NULL;
device->MaxNoOfSources = 256;
device->AuxiliaryEffectSlotMax = 4;
device->NumAuxSends = MAX_SENDS;
InitUIntMap(&device->BufferMap, ~0); InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0); InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0); InitUIntMap(&device->FilterMap, ~0);
//Set output format //Set output format
if(ConfigValueExists(NULL, "frequency")) device->NumUpdates = 4;
device->UpdateSize = 1024;
device->Frequency = DEFAULT_OUTPUT_RATE;
if(ConfigValueUInt(NULL, "frequency", &device->Frequency))
device->Flags |= DEVICE_FREQUENCY_REQUEST; device->Flags |= DEVICE_FREQUENCY_REQUEST;
device->Frequency = GetConfigValueInt(NULL, "frequency", DEFAULT_OUTPUT_RATE); device->Frequency = maxu(device->Frequency, 8000);
if(device->Frequency < 8000)
device->Frequency = 8000;
if(ConfigValueExists(NULL, "format")) if(ConfigValueExists(NULL, "format"))
device->Flags |= DEVICE_CHANNELS_REQUEST; device->Flags |= DEVICE_CHANNELS_REQUEST;
fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16"); fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
GetFormatFromString(fmt, &device->FmtChans, &device->FmtType); GetFormatFromString(fmt, &device->FmtChans, &device->FmtType);
device->NumUpdates = GetConfigValueInt(NULL, "periods", 4); ConfigValueUInt(NULL, "periods", &device->NumUpdates);
if(device->NumUpdates < 2) if(device->NumUpdates < 2) device->NumUpdates = 4;
device->NumUpdates = 4;
device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024); ConfigValueUInt(NULL, "period_size", &device->UpdateSize);
if(device->UpdateSize <= 0) if(device->UpdateSize == 0) device->UpdateSize = 1024;
device->UpdateSize = 1024;
device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256); ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
if(device->MaxNoOfSources <= 0) if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
device->MaxNoOfSources = 256;
device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4); ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
if(device->AuxiliaryEffectSlotMax <= 0) if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
device->AuxiliaryEffectSlotMax = 4;
ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
ConfigValueInt(NULL, "cf_level", &device->Bs2bLevel);
device->NumStereoSources = 1; device->NumStereoSources = 1;
device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources; device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
if(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
LockLists(); LockLists();
if((err=ALCdevice_OpenPlayback(device, deviceName)) != ALC_NO_ERROR) if((err=ALCdevice_OpenPlayback(device, deviceName)) != ALC_NO_ERROR)
@ -2592,44 +2598,47 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
device->Flags = 0; device->Flags = 0;
device->Bs2b = NULL; device->Bs2b = NULL;
device->Bs2bLevel = 0;
device->szDeviceName = NULL; device->szDeviceName = NULL;
device->ContextList = NULL; device->ContextList = NULL;
device->MaxNoOfSources = 256;
device->AuxiliaryEffectSlotMax = 4;
device->NumAuxSends = MAX_SENDS;
InitUIntMap(&device->BufferMap, ~0); InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0); InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0); InitUIntMap(&device->FilterMap, ~0);
//Set output format //Set output format
device->NumUpdates = 0;
device->UpdateSize = 0;
device->Frequency = 44100; device->Frequency = 44100;
device->FmtChans = DevFmtStereo; device->FmtChans = DevFmtStereo;
device->FmtType = DevFmtShort; device->FmtType = DevFmtShort;
device->NumUpdates = 0; ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
device->UpdateSize = 0; if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256); ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
if(device->MaxNoOfSources <= 0) if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
device->MaxNoOfSources = 256;
device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4); ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
if(device->AuxiliaryEffectSlotMax <= 0) if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
device->AuxiliaryEffectSlotMax = 4;
ConfigValueInt(NULL, "cf_level", &device->Bs2bLevel);
device->NumStereoSources = 1; device->NumStereoSources = 1;
device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources; device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
if(device->NumAuxSends > MAX_SENDS)
device->NumAuxSends = MAX_SENDS;
device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
// Open the "backend" // Open the "backend"
ALCdevice_OpenPlayback(device, "Loopback"); ALCdevice_OpenPlayback(device, "Loopback");
do { do {
device->next = DeviceList; device->next = DeviceList;
} while(!CompExchangePtr((void**)&DeviceList, device->next, device)); } while(!CompExchangePtr((void**)&DeviceList, device->next, device));
return device; return device;
} }

View File

@ -313,24 +313,35 @@ int ConfigValueExists(const char *blockName, const char *keyName)
return !!val[0]; return !!val[0];
} }
int GetConfigValueInt(const char *blockName, const char *keyName, int def) int ConfigValueInt(const char *blockName, const char *keyName, int *ret)
{ {
const char *val = GetConfigValue(blockName, keyName, ""); const char *val = GetConfigValue(blockName, keyName, "");
if(!val[0]) return 0;
if(!val[0]) return def; *ret = strtol(val, NULL, 0);
return strtol(val, NULL, 0); return 1;
} }
float GetConfigValueFloat(const char *blockName, const char *keyName, float def) int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret)
{ {
const char *val = GetConfigValue(blockName, keyName, ""); const char *val = GetConfigValue(blockName, keyName, "");
if(!val[0]) return 0;
*ret = strtoul(val, NULL, 0);
return 1;
}
int ConfigValueFloat(const char *blockName, const char *keyName, float *ret)
{
const char *val = GetConfigValue(blockName, keyName, "");
if(!val[0]) return 0;
if(!val[0]) return def;
#ifdef HAVE_STRTOF #ifdef HAVE_STRTOF
return strtof(val, NULL); *ret = strtof(val, NULL);
#else #else
return (float)strtod(val, NULL); *ret = (float)strtod(val, NULL);
#endif #endif
return 1;
} }
int GetConfigValueBool(const char *blockName, const char *keyName, int def) int GetConfigValueBool(const char *blockName, const char *keyName, int def)

View File

@ -168,8 +168,8 @@ static ALCenum pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
device->ExtraData = data; device->ExtraData = data;
outParams.device = GetConfigValueInt("port", "device", -1); outParams.device = -1;
if(outParams.device < 0) if(!ConfigValueInt("port", "device", &outParams.device) || outParams.device < 0)
outParams.device = Pa_GetDefaultOutputDevice(); outParams.device = Pa_GetDefaultOutputDevice();
outParams.suggestedLatency = (device->UpdateSize*device->NumUpdates) / outParams.suggestedLatency = (device->UpdateSize*device->NumUpdates) /
(float)device->Frequency; (float)device->Frequency;
@ -299,8 +299,8 @@ static ALCenum pa_open_capture(ALCdevice *device, const ALCchar *deviceName)
if(data->ring == NULL) if(data->ring == NULL)
goto error; goto error;
inParams.device = GetConfigValueInt("port", "capture", -1); inParams.device = -1;
if(inParams.device < 0) if(!ConfigValueInt("port", "capture", &inParams.device) || inParams.device < 0)
inParams.device = Pa_GetDefaultOutputDevice(); inParams.device = Pa_GetDefaultOutputDevice();
inParams.suggestedLatency = 0.0f; inParams.suggestedLatency = 0.0f;
inParams.hostApiSpecificStreamInfo = NULL; inParams.hostApiSpecificStreamInfo = NULL;

View File

@ -669,9 +669,10 @@ void ReadALConfig(void);
void FreeALConfig(void); void FreeALConfig(void);
int ConfigValueExists(const char *blockName, const char *keyName); int ConfigValueExists(const char *blockName, const char *keyName);
const char *GetConfigValue(const char *blockName, const char *keyName, const char *def); const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
int GetConfigValueInt(const char *blockName, const char *keyName, int def);
float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
int GetConfigValueBool(const char *blockName, const char *keyName, int def); int GetConfigValueBool(const char *blockName, const char *keyName, int def);
int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
void SetRTPriority(void); void SetRTPriority(void);

View File

@ -33,7 +33,7 @@
#include "alAuxEffectSlot.h" #include "alAuxEffectSlot.h"
enum Resampler DefaultResampler; enum Resampler DefaultResampler = RESAMPLER_DEFAULT;
const ALsizei ResamplerPadding[RESAMPLER_MAX] = { const ALsizei ResamplerPadding[RESAMPLER_MAX] = {
0, /* Point */ 0, /* Point */
1, /* Linear */ 1, /* Linear */