aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alc.cpp150
-rw-r--r--Alc/alconfig.cpp5
-rw-r--r--Alc/alconfig.h1
-rw-r--r--Alc/alu.cpp37
-rw-r--r--Alc/hrtf.cpp15
-rw-r--r--Alc/hrtf.h2
6 files changed, 50 insertions, 160 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 1d36dcbd..b19ed410 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -800,7 +800,14 @@ constexpr ALchar alExtList[] =
std::atomic<ALCenum> LastNullDeviceError{ALC_NO_ERROR};
/* Thread-local current context */
-std::atomic<void(*)(ALCcontext*)> ThreadCtxProc{nullptr};
+void ReleaseThreadCtx(ALCcontext *context)
+{
+ auto ref = DecrementRef(&context->ref);
+ TRACEREF("%p decreasing refcount to %u\n", context, ref);
+ ERR("Context %p current for thread being destroyed, possible leak!\n", context);
+}
+
+std::atomic<void(*)(ALCcontext*)> ThreadCtxProc{ReleaseThreadCtx};
class ThreadCtx {
ALCcontext *ctx{nullptr};
@@ -865,94 +872,34 @@ std::recursive_mutex ListLock;
/* Mixing thread piority level */
ALint RTPrioLevel;
-FILE *LogFile;
+FILE *LogFile{stderr};
#ifdef _DEBUG
-enum LogLevel LogLevel = LogWarning;
+enum LogLevel LogLevel{LogWarning};
#else
-enum LogLevel LogLevel = LogError;
+enum LogLevel LogLevel{LogError};
#endif
/************************************************
* Library initialization
************************************************/
-#if defined(_WIN32)
-static void alc_init(void);
-static void alc_deinit(void);
-static void alc_deinit_safe(void);
-
-#ifndef AL_LIBTYPE_STATIC
-BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD reason, LPVOID lpReserved)
+#if defined(_WIN32) && !defined(AL_LIBTYPE_STATIC)
+BOOL APIENTRY DllMain(HINSTANCE module, DWORD reason, LPVOID /*reserved*/)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
/* Pin the DLL so we won't get unloaded until the process terminates */
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
- (WCHAR*)hModule, &hModule);
- alc_init();
+ (WCHAR*)module, &module);
break;
case DLL_PROCESS_DETACH:
- if(!lpReserved)
- alc_deinit();
- else
- alc_deinit_safe();
break;
}
return TRUE;
}
-#elif defined(_MSC_VER)
-#pragma section(".CRT$XCU",read)
-static void alc_constructor(void);
-static void alc_destructor(void);
-__declspec(allocate(".CRT$XCU")) void (__cdecl* alc_constructor_)(void) = alc_constructor;
-
-static void alc_constructor(void)
-{
- atexit(alc_destructor);
- alc_init();
-}
-
-static void alc_destructor(void)
-{
- alc_deinit();
-}
-#elif defined(HAVE_GCC_DESTRUCTOR)
-static void alc_init(void) __attribute__((constructor));
-static void alc_deinit(void) __attribute__((destructor));
-#else
-#error "No static initialization available on this platform!"
-#endif
-
-#elif defined(HAVE_GCC_DESTRUCTOR)
-
-static void alc_init(void) __attribute__((constructor));
-static void alc_deinit(void) __attribute__((destructor));
-
-#else
-#error "No global initialization available on this platform!"
#endif
-static void ReleaseThreadCtx(ALCcontext *ctx);
-static void alc_init(void)
-{
- LogFile = stderr;
-
- const char *str{getenv("__ALSOFT_HALF_ANGLE_CONES")};
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
- ConeScale *= 0.5f;
-
- str = getenv("__ALSOFT_REVERSE_Z");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
- ZScale *= -1.0f;
-
- str = getenv("__ALSOFT_REVERB_IGNORES_SOUND_SPEED");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
- OverrideReverbSpeedOfSound = AL_TRUE;
-
- ThreadCtxProc = ReleaseThreadCtx;
-}
-
static void alc_initconfig(void)
{
const char *devs, *str;
@@ -1027,9 +974,7 @@ static void alc_initconfig(void)
capfilter = 0;
else
{
- size_t len;
const char *next = str;
-
do {
str = next;
while(isspace(str[0]))
@@ -1039,7 +984,7 @@ static void alc_initconfig(void)
if(!str[0] || str[0] == ',')
continue;
- len = (next ? ((size_t)(next-str)) : strlen(str));
+ size_t len{next ? (size_t)(next-str) : strlen(str)};
while(len > 0 && isspace(str[len-1]))
len--;
if(len == 3 && strncasecmp(str, "sse", len) == 0)
@@ -1193,9 +1138,7 @@ static void alc_initconfig(void)
if(ConfigValueStr(nullptr, nullptr, "excludefx", &str))
{
- size_t len;
const char *next = str;
-
do {
str = next;
next = strchr(str, ',');
@@ -1203,7 +1146,7 @@ static void alc_initconfig(void)
if(!str[0] || next == str)
continue;
- len = (next ? ((size_t)(next-str)) : strlen(str));
+ size_t len{next ? (size_t)(next-str) : strlen(str)};
for(n = 0;n < EFFECTLIST_SIZE;n++)
{
if(len == strlen(EffectList[n].name) &&
@@ -1222,60 +1165,6 @@ static void alc_initconfig(void)
/************************************************
- * Library deinitialization
- ************************************************/
-static void alc_cleanup(void)
-{
- alcAllDevicesList.clear();
- alcCaptureDeviceList.clear();
-
- alcDefaultAllDevicesSpecifier.clear();
- alcCaptureDefaultDeviceSpecifier.clear();
-
- if(ALCdevice *dev{DeviceList.exchange(nullptr)})
- {
- ALCuint num = 0;
- do {
- num++;
- dev = dev->next.load(std::memory_order_relaxed);
- } while(dev != nullptr);
- ERR("%u device%s not closed\n", num, (num>1)?"s":"");
- }
-}
-
-static void alc_deinit_safe(void)
-{
- alc_cleanup();
-
- FreeHrtfs();
- FreeALConfig();
-
- ThreadCtxProc = nullptr;
-
- if(LogFile != stderr)
- fclose(LogFile);
- LogFile = nullptr;
-}
-
-static void alc_deinit(void)
-{
- int i;
-
- alc_cleanup();
-
- PlaybackBackend = BackendInfo{};
- CaptureBackend = BackendInfo{};
-
- for(i = 0;i < BackendListSize;i++)
- BackendList[i].getFactory().deinit();
-
- LoopbackBackendFactory::getFactory().deinit();
-
- alc_deinit_safe();
-}
-
-
-/************************************************
* Device enumeration
************************************************/
static void ProbeDevices(std::string *list, struct BackendInfo *backendinfo, enum DevProbe type)
@@ -2714,13 +2603,6 @@ void ALCcontext_DecRef(ALCcontext *context)
if(ref == 0) delete context;
}
-static void ReleaseThreadCtx(ALCcontext *context)
-{
- auto ref = DecrementRef(&context->ref);
- TRACEREF("%p decreasing refcount to %u\n", context, ref);
- ERR("Context %p current for thread being destroyed, possible leak!\n", context);
-}
-
/* VerifyContext
*
* Checks if the given context is valid, returning a new reference to it if so.
diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp
index a6304ce7..4acbba5e 100644
--- a/Alc/alconfig.cpp
+++ b/Alc/alconfig.cpp
@@ -443,11 +443,6 @@ void ReadALConfig(void) noexcept
}
#endif
-void FreeALConfig(void)
-{
- ConfOpts.clear();
-}
-
const char *GetConfigValue(const char *devName, const char *blockName, const char *keyName, const char *def)
{
if(!keyName)
diff --git a/Alc/alconfig.h b/Alc/alconfig.h
index 627ef48a..0e9bcec3 100644
--- a/Alc/alconfig.h
+++ b/Alc/alconfig.h
@@ -9,7 +9,6 @@ extern "C" {
#endif
void ReadALConfig(void) NOEXCEPT;
-void FreeALConfig(void);
int ConfigValueExists(const char *devName, const char *blockName, const char *keyName);
const char *GetConfigValue(const char *devName, const char *blockName, const char *keyName, const char *def);
diff --git a/Alc/alu.cpp b/Alc/alu.cpp
index 34634983..f7640d71 100644
--- a/Alc/alu.cpp
+++ b/Alc/alu.cpp
@@ -49,14 +49,45 @@
#include "bsinc_inc.h"
+namespace {
+
+ALfloat InitConeScale()
+{
+ ALfloat ret{1.0f};
+ const char *str{getenv("__ALSOFT_HALF_ANGLE_CONES")};
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
+ ret *= 0.5f;
+ return ret;
+}
+
+ALfloat InitZScale()
+{
+ ALfloat ret{1.0f};
+ const char *str{getenv("__ALSOFT_REVERSE_Z")};
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
+ ret *= -1.0f;
+ return ret;
+}
+
+ALboolean InitReverbSOS()
+{
+ ALboolean ret{AL_FALSE};
+ const char *str{getenv("__ALSOFT_REVERB_IGNORES_SOUND_SPEED")};
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, nullptr, 0) == 1))
+ ret = AL_TRUE;
+ return ret;
+}
+
+} // namespace
+
/* Cone scalar */
-ALfloat ConeScale = 1.0f;
+const ALfloat ConeScale{InitConeScale()};
/* Localized Z scalar for mono sources */
-ALfloat ZScale = 1.0f;
+const ALfloat ZScale{InitZScale()};
/* Force default speed of sound for distance-related reverb decay. */
-ALboolean OverrideReverbSpeedOfSound = AL_FALSE;
+const ALboolean OverrideReverbSpeedOfSound{InitReverbSOS()};
namespace {
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp
index 9b645b05..7ca2e3c7 100644
--- a/Alc/hrtf.cpp
+++ b/Alc/hrtf.cpp
@@ -1286,18 +1286,3 @@ void Hrtf_DecRef(struct Hrtf *hrtf)
}
}
}
-
-
-void FreeHrtfs(void)
-{
- struct HrtfEntry *Hrtf{LoadedHrtfs};
- LoadedHrtfs = nullptr;
-
- while(Hrtf != nullptr)
- {
- struct HrtfEntry *next{Hrtf->next};
- al_free(Hrtf->handle);
- al_free(Hrtf);
- Hrtf = next;
- }
-}
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index cbec2fc7..b814c282 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -68,8 +68,6 @@ struct AngularPoint {
};
-void FreeHrtfs(void);
-
al::vector<EnumeratedHrtf> EnumerateHrtf(const char *devname);
struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
void Hrtf_IncRef(struct Hrtf *hrtf);