diff options
-rw-r--r-- | Alc/ALc.c | 10 | ||||
-rw-r--r-- | Alc/alcConfig.c | 9 | ||||
-rw-r--r-- | Alc/backends/alsa.c | 24 | ||||
-rw-r--r-- | Alc/hrtf.c | 7 | ||||
-rw-r--r-- | Alc/panning.c | 14 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 1 |
6 files changed, 39 insertions, 26 deletions
@@ -606,8 +606,7 @@ static void alc_initconfig(void) EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE); - devs = GetConfigValue(NULL, "drivers", ""); - if(devs[0]) + if(ConfigValueStr(NULL, "drivers", &devs)) { int n; size_t len; @@ -690,8 +689,7 @@ static void alc_initconfig(void) } BackendLoopback.Init(&BackendLoopback.Funcs); - str = GetConfigValue(NULL, "excludefx", ""); - if(str[0]) + if(ConfigValueStr(NULL, "excludefx", &str)) { size_t len; const char *next = str; @@ -2453,9 +2451,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->Flags |= DEVICE_FREQUENCY_REQUEST; device->Frequency = maxu(device->Frequency, 8000); - if(ConfigValueExists(NULL, "format")) + fmt = "AL_FORMAT_STEREO16"; + if(ConfigValueStr(NULL, "format", &fmt)) device->Flags |= DEVICE_CHANNELS_REQUEST; - fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16"); GetFormatFromString(fmt, &device->FmtChans, &device->FmtType); ConfigValueUInt(NULL, "periods", &device->NumUpdates); diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c index 60fb733a..0024b948 100644 --- a/Alc/alcConfig.c +++ b/Alc/alcConfig.c @@ -313,6 +313,15 @@ int ConfigValueExists(const char *blockName, const char *keyName) return !!val[0]; } +int ConfigValueStr(const char *blockName, const char *keyName, const char **ret) +{ + const char *val = GetConfigValue(blockName, keyName, ""); + if(!val[0]) return 0; + + *ret = val; + return 1; +} + int ConfigValueInt(const char *blockName, const char *keyName, int *ret) { const char *val = GetConfigValue(blockName, keyName, ""); diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 6d4528c1..b99fd147 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -525,12 +525,12 @@ static ALuint ALSANoMMapProc(ALvoid *ptr) static ALCenum alsa_open_playback(ALCdevice *device, const ALCchar *deviceName) { + const char *driver = "default"; alsa_data *data; - char driver[128]; + char str[128]; int i; - strncpy(driver, GetConfigValue("alsa", "device", "default"), sizeof(driver)-1); - driver[sizeof(driver)-1] = 0; + ConfigValueStr("alsa", "device", &driver); if(!deviceName) deviceName = alsaDevice; @@ -547,8 +547,11 @@ static ALCenum alsa_open_playback(ALCdevice *device, const ALCchar *deviceName) strcmp(deviceName, allDevNameMap[idx].name) == 0) { if(idx > 0) - snprintf(driver, sizeof(driver), "%sCARD=%s,DEV=%d", device_prefix, - allDevNameMap[idx].card, allDevNameMap[idx].dev); + { + snprintf(str, sizeof(str), "%sCARD=%s,DEV=%d", device_prefix, + allDevNameMap[idx].card, allDevNameMap[idx].dev); + driver = str; + } break; } } @@ -801,18 +804,18 @@ static void alsa_stop_playback(ALCdevice *device) static ALCenum alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceName) { + const char *driver = "default"; snd_pcm_hw_params_t *p; snd_pcm_uframes_t bufferSizeInFrames; snd_pcm_uframes_t periodSizeInFrames; snd_pcm_format_t format; ALuint frameSize; alsa_data *data; - char driver[128]; + char str[128]; char *err; int i; - strncpy(driver, GetConfigValue("alsa", "capture", "default"), sizeof(driver)-1); - driver[sizeof(driver)-1] = 0; + ConfigValueStr("alsa", "capture", &driver); if(!allCaptureDevNameMap) allCaptureDevNameMap = probe_devices(SND_PCM_STREAM_CAPTURE, &numCaptureDevNames); @@ -829,8 +832,11 @@ static ALCenum alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceName) strcmp(deviceName, allCaptureDevNameMap[idx].name) == 0) { if(idx > 0) - snprintf(driver, sizeof(driver), "%sCARD=%s,DEV=%d", capture_prefix, + { + snprintf(str, sizeof(str), "%sCARD=%s,DEV=%d", capture_prefix, allCaptureDevNameMap[idx].card, allCaptureDevNameMap[idx].dev); + driver = str; + } break; } } @@ -315,10 +315,11 @@ const struct Hrtf *GetHrtf(ALCdevice *device) void InitHrtf(void) { - char *fnamelist, *next; + char *fnamelist=NULL, *next=NULL; + const char *val; - fnamelist = strdup(GetConfigValue(NULL, "hrtf_tables", "")); - next = fnamelist; + if(ConfigValueStr(NULL, "hrtf_tables", &val)) + next = fnamelist = strdup(val); while(next && *next) { const ALubyte maxDelay = SRC_HISTORY_LENGTH-1; diff --git a/Alc/panning.c b/Alc/panning.c index b225e3ec..983d3ef6 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -34,21 +34,17 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MAXCHANNELS], enum Channel Speaker2Chan[MAXCHANNELS], ALint chans) { - char layout_str[256]; char *confkey, *next; + char *layout_str; char *sep, *end; enum Channel val; + const char *str; int i; - if(!ConfigValueExists(NULL, name)) - name = "layout"; - - strncpy(layout_str, GetConfigValue(NULL, name, ""), sizeof(layout_str)); - layout_str[sizeof(layout_str)-1] = 0; - - if(!layout_str[0]) + if(!ConfigValueStr(NULL, name, &str) && !ConfigValueStr(NULL, "layout", &str)) return; + layout_str = strdup(str); next = confkey = layout_str; while(next && *next) { @@ -113,6 +109,8 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MAXCHAN } } } + free(layout_str); + layout_str = NULL; for(i = 0;i < chans;i++) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 185123cf..5ee90db6 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -670,6 +670,7 @@ void FreeALConfig(void); int ConfigValueExists(const char *blockName, const char *keyName); const char *GetConfigValue(const char *blockName, const char *keyName, const char *def); int GetConfigValueBool(const char *blockName, const char *keyName, int def); +int ConfigValueStr(const char *blockName, const char *keyName, const char **ret); 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); |