aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-09-18 16:16:55 -0700
committerChris Robinson <[email protected]>2011-09-18 16:16:55 -0700
commit7e06a10f73d5955de7bba35da09e5941cee56dc8 (patch)
tree4e2394246a4912ee762c7a01fa365cceade58e50 /Alc
parentd46db2f648e7d00ae138fb98bd0ee49014c501a6 (diff)
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.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c117
-rw-r--r--Alc/alcConfig.c25
-rw-r--r--Alc/backends/portaudio.c8
3 files changed, 85 insertions, 65 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 07d6fe3d..987b5fa6 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -559,6 +559,7 @@ static void alc_deinit(void)
static void alc_initconfig(void)
{
const char *devs, *str;
+ float valf;
int i, n;
str = getenv("ALSOFT_LOGLEVEL");
@@ -582,14 +583,17 @@ static void alc_initconfig(void)
InitHrtf();
#ifdef _WIN32
- RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 1);
+ RTPrioLevel = 1;
#else
- RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
+ RTPrioLevel = 0;
#endif
+ ConfigValueInt(NULL, "rt-prio", &RTPrioLevel);
- DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
- if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
- DefaultResampler = RESAMPLER_DEFAULT;
+ if(ConfigValueInt(NULL, "resampler", &n))
+ {
+ if(n < RESAMPLER_MAX && n > RESAMPLER_MIN)
+ DefaultResampler = n;
+ }
if(!TrapALCError)
TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", ALC_FALSE);
@@ -597,8 +601,9 @@ static void alc_initconfig(void)
if(!TrapALError)
TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE);
- ReverbBoost *= aluPow(10.0f, GetConfigValueFloat("reverb", "boost", 0.0f) /
- 20.0f);
+ if(ConfigValueFloat("reverb", "boost", &valf))
+ ReverbBoost *= aluPow(10.0f, valf / 20.0f);
+
EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
devs = GetConfigValue(NULL, "drivers", "");
@@ -1080,9 +1085,6 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numStereo = device->NumStereoSources;
numSends = device->NumAuxSends;
- freq = GetConfigValueInt(NULL, "frequency", freq);
- if(freq < 8000) freq = 8000;
-
attrIdx = 0;
while(attrList[attrIdx])
{
@@ -1121,10 +1123,9 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
return ALC_FALSE;
}
}
- else if(!ConfigValueExists(NULL, "frequency"))
+ else
{
freq = attrList[attrIdx + 1];
- if(freq < 8000) freq = 8000;
device->Flags |= DEVICE_FREQUENCY_REQUEST;
}
}
@@ -1138,17 +1139,20 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numMono = device->MaxNoOfSources - numStereo;
}
- if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
- !ConfigValueExists(NULL, "sends"))
- {
+ if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
numSends = attrList[attrIdx + 1];
- if(numSends > MAX_SENDS)
- numSends = MAX_SENDS;
- }
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->Frequency;
@@ -2459,50 +2463,52 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->Flags = 0;
device->Bs2b = NULL;
+ device->Bs2bLevel = 0;
device->szDeviceName = NULL;
device->ContextList = NULL;
+ device->MaxNoOfSources = 256;
+ device->AuxiliaryEffectSlotMax = 4;
+ device->NumAuxSends = MAX_SENDS;
+
InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
//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->Frequency = GetConfigValueInt(NULL, "frequency", DEFAULT_OUTPUT_RATE);
- if(device->Frequency < 8000)
- device->Frequency = 8000;
+ device->Frequency = maxu(device->Frequency, 8000);
if(ConfigValueExists(NULL, "format"))
device->Flags |= DEVICE_CHANNELS_REQUEST;
fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
GetFormatFromString(fmt, &device->FmtChans, &device->FmtType);
- device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
- if(device->NumUpdates < 2)
- device->NumUpdates = 4;
+ ConfigValueUInt(NULL, "periods", &device->NumUpdates);
+ if(device->NumUpdates < 2) device->NumUpdates = 4;
- device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
- if(device->UpdateSize <= 0)
- device->UpdateSize = 1024;
+ ConfigValueUInt(NULL, "period_size", &device->UpdateSize);
+ if(device->UpdateSize == 0) device->UpdateSize = 1024;
- device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
- if(device->MaxNoOfSources <= 0)
- device->MaxNoOfSources = 256;
+ ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
+ if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
- device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
- if(device->AuxiliaryEffectSlotMax <= 0)
- device->AuxiliaryEffectSlotMax = 4;
+ ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
+ if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
- device->NumStereoSources = 1;
- device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
+ ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
+ if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
- device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
- if(device->NumAuxSends > MAX_SENDS)
- device->NumAuxSends = MAX_SENDS;
+ ConfigValueInt(NULL, "cf_level", &device->Bs2bLevel);
- device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
+ device->NumStereoSources = 1;
+ device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
// Find a playback device to open
LockLists();
@@ -2592,44 +2598,47 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
device->Flags = 0;
device->Bs2b = NULL;
+ device->Bs2bLevel = 0;
device->szDeviceName = NULL;
device->ContextList = NULL;
+ device->MaxNoOfSources = 256;
+ device->AuxiliaryEffectSlotMax = 4;
+ device->NumAuxSends = MAX_SENDS;
+
InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
//Set output format
+ device->NumUpdates = 0;
+ device->UpdateSize = 0;
+
device->Frequency = 44100;
device->FmtChans = DevFmtStereo;
device->FmtType = DevFmtShort;
- device->NumUpdates = 0;
- device->UpdateSize = 0;
+ ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
+ if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
+
+ ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
+ if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
- device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
- if(device->MaxNoOfSources <= 0)
- device->MaxNoOfSources = 256;
+ ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
+ if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
- device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
- if(device->AuxiliaryEffectSlotMax <= 0)
- device->AuxiliaryEffectSlotMax = 4;
+ ConfigValueInt(NULL, "cf_level", &device->Bs2bLevel);
device->NumStereoSources = 1;
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"
ALCdevice_OpenPlayback(device, "Loopback");
do {
device->next = DeviceList;
} while(!CompExchangePtr((void**)&DeviceList, device->next, device));
+
return device;
}
diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c
index b8c04743..60fb733a 100644
--- a/Alc/alcConfig.c
+++ b/Alc/alcConfig.c
@@ -313,24 +313,35 @@ int ConfigValueExists(const char *blockName, const char *keyName)
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, "");
+ if(!val[0]) return 0;
- if(!val[0]) return def;
- return strtol(val, NULL, 0);
+ *ret = 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, "");
+ 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
- return strtof(val, NULL);
+ *ret = strtof(val, NULL);
#else
- return (float)strtod(val, NULL);
+ *ret = (float)strtod(val, NULL);
#endif
+ return 1;
}
int GetConfigValueBool(const char *blockName, const char *keyName, int def)
diff --git a/Alc/backends/portaudio.c b/Alc/backends/portaudio.c
index 2345a282..8070942c 100644
--- a/Alc/backends/portaudio.c
+++ b/Alc/backends/portaudio.c
@@ -168,8 +168,8 @@ static ALCenum pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
device->ExtraData = data;
- outParams.device = GetConfigValueInt("port", "device", -1);
- if(outParams.device < 0)
+ outParams.device = -1;
+ if(!ConfigValueInt("port", "device", &outParams.device) || outParams.device < 0)
outParams.device = Pa_GetDefaultOutputDevice();
outParams.suggestedLatency = (device->UpdateSize*device->NumUpdates) /
(float)device->Frequency;
@@ -299,8 +299,8 @@ static ALCenum pa_open_capture(ALCdevice *device, const ALCchar *deviceName)
if(data->ring == NULL)
goto error;
- inParams.device = GetConfigValueInt("port", "capture", -1);
- if(inParams.device < 0)
+ inParams.device = -1;
+ if(!ConfigValueInt("port", "capture", &inParams.device) || inParams.device < 0)
inParams.device = Pa_GetDefaultOutputDevice();
inParams.suggestedLatency = 0.0f;
inParams.hostApiSpecificStreamInfo = NULL;