From 7b3a2085aac8eac47f9968f331d3991167793e85 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 15 Nov 2018 06:23:01 -0800 Subject: Use a regular char* for the device's name --- Alc/alc.cpp | 35 ++++++++++++++++++----------------- Alc/backends/alsa.cpp | 10 ++++++---- Alc/backends/coreaudio.cpp | 6 ++++-- Alc/backends/dsound.cpp | 6 ++++-- Alc/backends/jack.cpp | 7 ++++--- Alc/backends/loopback.cpp | 3 ++- Alc/backends/null.cpp | 3 ++- Alc/backends/opensl.cpp | 6 ++++-- Alc/backends/oss.cpp | 6 ++++-- Alc/backends/portaudio.cpp | 6 ++++-- Alc/backends/pulseaudio.cpp | 16 ++++++++++------ Alc/backends/qsa.cpp | 6 ++++-- Alc/backends/sdl2.cpp | 3 ++- Alc/backends/sndio.cpp | 6 ++++-- Alc/backends/solaris.cpp | 3 ++- Alc/backends/wasapi.cpp | 22 ++++++++++++---------- Alc/backends/wave.cpp | 3 ++- Alc/backends/winmm.cpp | 6 ++++-- Alc/helpers.cpp | 9 +++++++++ Alc/hrtf.cpp | 12 ++---------- Alc/panning.cpp | 26 +++++++++----------------- OpenAL32/Include/alMain.h | 4 +++- 22 files changed, 115 insertions(+), 89 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index dab2a70d..159e3bc8 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1910,7 +1910,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } #undef TRACE_ATTR - ConfigValueUInt(alstr_get_cstr(device->DeviceName), nullptr, "frequency", &freq); + ConfigValueUInt(device->DeviceName, nullptr, "frequency", &freq); freq = maxu(freq, MIN_OUTPUT_RATE); device->UpdateSize = (ALuint64)device->UpdateSize * freq / @@ -1924,7 +1924,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(numMono > INT_MAX-numStereo) numMono = INT_MAX-numStereo; numMono += numStereo; - if(ConfigValueInt(alstr_get_cstr(device->DeviceName), nullptr, "sources", &numMono)) + if(ConfigValueInt(device->DeviceName, nullptr, "sources", &numMono)) { if(numMono <= 0) numMono = 256; @@ -1938,7 +1938,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->NumMonoSources = numMono; device->NumStereoSources = numStereo; - if(ConfigValueInt(alstr_get_cstr(device->DeviceName), nullptr, "sends", &new_sends)) + if(ConfigValueInt(device->DeviceName, nullptr, "sends", &new_sends)) new_sends = mini(numSends, clampi(new_sends, 0, MAX_SENDS)); else new_sends = numSends; @@ -1980,7 +1980,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(device->Type != Loopback) { const char *hrtf; - if(ConfigValueStr(alstr_get_cstr(device->DeviceName), nullptr, "hrtf", &hrtf)) + if(ConfigValueStr(device->DeviceName, nullptr, "hrtf", &hrtf)) { if(strcasecmp(hrtf, "true") == 0) hrtf_userreq = Hrtf_Enable; @@ -1996,7 +1996,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(VECTOR_SIZE(device->HrtfList) == 0) { VECTOR_DEINIT(device->HrtfList); - device->HrtfList = EnumerateHrtf(alstr_get_cstr(device->DeviceName)); + device->HrtfList = EnumerateHrtf(device->DeviceName); } if(VECTOR_SIZE(device->HrtfList) > 0) { @@ -2108,10 +2108,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->AuxiliaryEffectSlotMax, device->NumAuxSends); device->DitherDepth = 0.0f; - if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), nullptr, "dither", 1)) + if(GetConfigValueBool(device->DeviceName, nullptr, "dither", 1)) { ALint depth = 0; - ConfigValueInt(alstr_get_cstr(device->DeviceName), nullptr, "dither-depth", &depth); + ConfigValueInt(device->DeviceName, nullptr, "dither-depth", &depth); if(depth <= 0) { switch(device->FmtType) @@ -2144,7 +2144,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->DitherDepth); device->LimiterState = gainLimiter; - if(ConfigValueBool(alstr_get_cstr(device->DeviceName), nullptr, "output-limiter", &val)) + if(ConfigValueBool(device->DeviceName, nullptr, "output-limiter", &val)) gainLimiter = val ? ALC_TRUE : ALC_FALSE; /* Valid values for gainLimiter are ALC_DONT_CARE_SOFT, ALC_TRUE, and @@ -2381,7 +2381,7 @@ static void InitDevice(ALCdevice *device, enum DeviceType type) device->RealOut.Buffer = nullptr; device->RealOut.NumChannels = 0; - AL_STRING_INIT(device->DeviceName); + device->DeviceName = nullptr; for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { @@ -2486,7 +2486,8 @@ static ALCvoid FreeDevice(ALCdevice *device) device->ChannelDelay[i].Buffer = nullptr; } - AL_STRING_DEINIT(device->DeviceName); + al_free(device->DeviceName); + device->DeviceName = nullptr; al_free(device->Dry.Buffer); device->Dry.Buffer = nullptr; @@ -3068,7 +3069,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para case ALC_ALL_DEVICES_SPECIFIER: if(VerifyDevice(&Device)) { - value = alstr_get_cstr(Device->DeviceName); + value = Device->DeviceName; ALCdevice_DecRef(Device); } else @@ -3081,7 +3082,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para case ALC_CAPTURE_DEVICE_SPECIFIER: if(VerifyDevice(&Device)) { - value = alstr_get_cstr(Device->DeviceName); + value = Device->DeviceName; ALCdevice_DecRef(Device); } else @@ -3448,7 +3449,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC case ALC_NUM_HRTF_SPECIFIERS_SOFT: almtx_lock(&device->BackendLock); FreeHrtfList(&device->HrtfList); - device->HrtfList = EnumerateHrtf(alstr_get_cstr(device->DeviceName)); + device->HrtfList = EnumerateHrtf(device->DeviceName); values[0] = (ALCint)VECTOR_SIZE(device->HrtfList); almtx_unlock(&device->BackendLock); return 1; @@ -3810,7 +3811,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALCdevice_IncRef(ALContext->Device); InitContext(ALContext); - if(ConfigValueFloat(alstr_get_cstr(device->DeviceName), nullptr, "volume-adjust", &valf)) + if(ConfigValueFloat(device->DeviceName, nullptr, "volume-adjust", &valf)) { if(!isfinite(valf)) ERR("volume-adjust must be finite: %f\n", valf); @@ -4131,7 +4132,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) return nullptr; } - if(ConfigValueStr(alstr_get_cstr(device->DeviceName), nullptr, "ambi-format", &fmt)) + if(ConfigValueStr(device->DeviceName, nullptr, "ambi-format", &fmt)) { if(strcasecmp(fmt, "fuma") == 0) { @@ -4159,7 +4160,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) } while(!DeviceList.compare_exchange_weak(head, device)); } - TRACE("Created device %p, \"%s\"\n", device, alstr_get_cstr(device->DeviceName)); + TRACE("Created device %p, \"%s\"\n", device, device->DeviceName); return device; } @@ -4295,7 +4296,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, } while(!DeviceList.compare_exchange_weak(head, device)); } - TRACE("Created device %p, \"%s\"\n", device, alstr_get_cstr(device->DeviceName)); + TRACE("Created device %p, \"%s\"\n", device, device->DeviceName); return device; } diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index 5a389eab..23e33e6b 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -684,7 +684,8 @@ static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name) snd_config_update_free_global(); ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -719,7 +720,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self) break; } - bool allowmmap{!!GetConfigValueBool(alstr_get_cstr(device->DeviceName), "alsa", "mmap", 1)}; + bool allowmmap{!!GetConfigValueBool(device->DeviceName, "alsa", "mmap", 1)}; ALuint periods{device->NumUpdates}; ALuint periodLen{static_cast(device->UpdateSize * U64(1000000) / device->Frequency)}; ALuint bufferLen{periodLen * periods}; @@ -790,7 +791,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self) } CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder))); /* set rate (implicitly constrains period/buffer parameters) */ - if(!GetConfigValueBool(alstr_get_cstr(device->DeviceName), "alsa", "allow-resampler", 0) || + if(!GetConfigValueBool(device->DeviceName, "alsa", "allow-resampler", 0) || !(device->Flags&DEVICE_FREQUENCY_REQUEST)) { if(snd_pcm_hw_params_set_rate_resample(self->pcmHandle, hp, 0) < 0) @@ -1082,7 +1083,8 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name) } } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; diff --git a/Alc/backends/coreaudio.cpp b/Alc/backends/coreaudio.cpp index 83ea4d5f..1a3f2ab1 100644 --- a/Alc/backends/coreaudio.cpp +++ b/Alc/backends/coreaudio.cpp @@ -143,7 +143,8 @@ static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCch return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -673,7 +674,8 @@ static ALCenum ALCcoreAudioCapture_open(ALCcoreAudioCapture *self, const ALCchar ); if(!self->ring) goto error; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; diff --git a/Alc/backends/dsound.cpp b/Alc/backends/dsound.cpp index 50e956ea..478bdf9a 100644 --- a/Alc/backends/dsound.cpp +++ b/Alc/backends/dsound.cpp @@ -396,7 +396,8 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, deviceName); + al_free(device->DeviceName); + device->DeviceName = alstrdup(deviceName); return ALC_NO_ERROR; } @@ -862,7 +863,8 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi self->BufferBytes = DSCBDescription.dwBufferBytes; SetDefaultWFXChannelOrder(device); - alstr_copy_cstr(&device->DeviceName, deviceName); + al_free(device->DeviceName); + device->DeviceName = alstrdup(deviceName); return ALC_NO_ERROR; } diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp index 4aa6cd78..9db75537 100644 --- a/Alc/backends/jack.cpp +++ b/Alc/backends/jack.cpp @@ -224,7 +224,7 @@ static int ALCjackPlayback_bufferSizeNotify(jack_nframes_t numframes, void *arg) device->NumUpdates = 2; bufsize = device->UpdateSize; - if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize)) + if(ConfigValueUInt(device->DeviceName, "jack", "buffer-size", &bufsize)) bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize); device->NumUpdates = (bufsize+device->UpdateSize) / device->UpdateSize; @@ -368,7 +368,8 @@ static ALCenum ALCjackPlayback_open(ALCjackPlayback *self, const ALCchar *name) jack_set_process_callback(self->Client, ALCjackPlayback_process, self); jack_set_buffer_size_callback(self->Client, ALCjackPlayback_bufferSizeNotify, self); - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -394,7 +395,7 @@ static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self) device->NumUpdates = 2; bufsize = device->UpdateSize; - if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize)) + if(ConfigValueUInt(device->DeviceName, "jack", "buffer-size", &bufsize)) bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize); device->NumUpdates = (bufsize+device->UpdateSize) / device->UpdateSize; diff --git a/Alc/backends/loopback.cpp b/Alc/backends/loopback.cpp index 3726463c..2eb4c935 100644 --- a/Alc/backends/loopback.cpp +++ b/Alc/backends/loopback.cpp @@ -62,7 +62,8 @@ static ALCenum ALCloopback_open(ALCloopback *self, const ALCchar *name) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/null.cpp b/Alc/backends/null.cpp index c8523c88..30d80b76 100644 --- a/Alc/backends/null.cpp +++ b/Alc/backends/null.cpp @@ -141,7 +141,8 @@ static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name) return ALC_INVALID_VALUE; device = STATIC_CAST(ALCbackend, self)->mDevice; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 9d938ba4..689c02af 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -375,7 +375,8 @@ static ALCenum ALCopenslPlayback_open(ALCopenslPlayback *self, const ALCchar *na return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -900,7 +901,8 @@ static ALCenum ALCopenslCapture_open(ALCopenslCapture *self, const ALCchar *name return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/oss.cpp b/Alc/backends/oss.cpp index 618730b3..4f320b69 100644 --- a/Alc/backends/oss.cpp +++ b/Alc/backends/oss.cpp @@ -391,7 +391,8 @@ static ALCenum ALCplaybackOSS_open(ALCplaybackOSS *self, const ALCchar *name) return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -722,7 +723,8 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name) return ALC_OUT_OF_MEMORY; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/portaudio.cpp b/Alc/backends/portaudio.cpp index 03194c05..7b21669a 100644 --- a/Alc/backends/portaudio.cpp +++ b/Alc/backends/portaudio.cpp @@ -249,7 +249,8 @@ retry_open: return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; @@ -440,7 +441,8 @@ static ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name) return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index 77719e3c..4569b91a 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -800,7 +800,8 @@ static void PulsePlayback_sinkNameCallback(pa_context *UNUSED(context), const pa } ALCdevice *device{STATIC_CAST(ALCbackend,self)->mDevice}; - alstr_copy_cstr(&device->DeviceName, info->description); + al_free(device->DeviceName); + device->DeviceName = alstrdup(info->description); } @@ -980,7 +981,8 @@ static ALCenum PulsePlayback_open(PulsePlayback *self, const ALCchar *name) else { ALCdevice *device{STATIC_CAST(ALCbackend,self)->mDevice}; - alstr_copy_cstr(&device->DeviceName, dev_name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(dev_name); } return ALC_NO_ERROR; @@ -1011,7 +1013,7 @@ static ALCboolean PulsePlayback_reset(PulsePlayback *self) PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE}; if(!GetConfigValueBool(nullptr, "pulse", "allow-moves", 0)) flags |= PA_STREAM_DONT_MOVE; - if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) || + if(GetConfigValueBool(device->DeviceName, "pulse", "fix-rate", 0) || !(device->Flags&DEVICE_FREQUENCY_REQUEST)) flags |= PA_STREAM_FIX_RATE; @@ -1418,7 +1420,8 @@ static void PulseCapture_sourceNameCallback(pa_context *UNUSED(context), const p } ALCdevice *device{STATIC_CAST(ALCbackend,self)->mDevice}; - alstr_copy_cstr(&device->DeviceName, info->description); + al_free(device->DeviceName); + device->DeviceName = alstrdup(info->description); } @@ -1490,7 +1493,8 @@ static ALCenum PulseCapture_open(PulseCapture *self, const ALCchar *name) if(iter == CaptureDevices.cend()) return ALC_INVALID_VALUE; pulse_name = iter->device_name.c_str(); - alstr_copy_cstr(&device->DeviceName, iter->name.c_str()); + al_free(device->DeviceName); + device->DeviceName = alstrdup(iter->name.c_str()); } std::tie(self->loop, self->context) = pulse_open(PulseCapture_contextStateCallback, self); @@ -1593,7 +1597,7 @@ static ALCenum PulseCapture_open(PulseCapture *self, const ALCchar *name) pa_stream_set_state_callback(self->stream, PulseCapture_streamStateCallback, self); self->device_name = pa_stream_get_device_name(self->stream); - if(alstr_empty(device->DeviceName)) + if(!device->DeviceName || device->DeviceName[0] == 0) { pa_operation *op{pa_context_get_source_info_by_name(self->context, self->device_name.c_str(), PulseCapture_sourceNameCallback, self diff --git a/Alc/backends/qsa.cpp b/Alc/backends/qsa.cpp index 7afd3214..3a99d71e 100644 --- a/Alc/backends/qsa.cpp +++ b/Alc/backends/qsa.cpp @@ -328,7 +328,8 @@ static ALCenum qsa_open_playback(PlaybackWrapper *self, const ALCchar* deviceNam return ALC_INVALID_DEVICE; } - alstr_copy_cstr(&device->DeviceName, deviceName); + al_free(device->DeviceName); + device->DeviceName = alstrdup(deviceName); self->ExtraData = data; return ALC_NO_ERROR; @@ -735,7 +736,8 @@ static ALCenum qsa_open_capture(CaptureWrapper *self, const ALCchar *deviceName) return ALC_INVALID_DEVICE; } - alstr_copy_cstr(&device->DeviceName, deviceName); + al_free(device->DeviceName); + device->DeviceName = alstrdup(deviceName); self->ExtraData = data; switch (device->FmtType) diff --git a/Alc/backends/sdl2.cpp b/Alc/backends/sdl2.cpp index 82c350e1..c918b57c 100644 --- a/Alc/backends/sdl2.cpp +++ b/Alc/backends/sdl2.cpp @@ -174,7 +174,8 @@ static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name) self->FmtType = device->FmtType; self->UpdateSize = device->UpdateSize; - alstr_copy_cstr(&device->DeviceName, name ? name : defaultDeviceName); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name ? name : defaultDeviceName); return ALC_NO_ERROR; } diff --git a/Alc/backends/sndio.cpp b/Alc/backends/sndio.cpp index c97226a6..f1e678cf 100644 --- a/Alc/backends/sndio.cpp +++ b/Alc/backends/sndio.cpp @@ -148,7 +148,8 @@ static ALCenum SndioPlayback_open(SndioPlayback *self, const ALCchar *name) return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } @@ -488,7 +489,8 @@ static ALCenum SndioCapture_open(SndioCapture *self, const ALCchar *name) SetDefaultChannelOrder(device); - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/solaris.cpp b/Alc/backends/solaris.cpp index b63a85e8..20dda617 100644 --- a/Alc/backends/solaris.cpp +++ b/Alc/backends/solaris.cpp @@ -188,7 +188,8 @@ static ALCenum ALCsolarisBackend_open(ALCsolarisBackend *self, const ALCchar *na } device = STATIC_CAST(ALCbackend,self)->mDevice; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index 64e7d43c..4fb0f317 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -719,7 +719,8 @@ static ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *de { ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; self->mDevId = iter->devid; - alstr_copy_range(&device->DeviceName, &*iter->name.cbegin(), &*iter->name.cend()); + al_free(device->DeviceName); + device->DeviceName = alstrdup(iter->name.c_str()); hr = S_OK; } } @@ -775,11 +776,11 @@ HRESULT ALCwasapiPlayback::openProxy() if(SUCCEEDED(hr)) { mClient = reinterpret_cast(ptr); - if(alstr_empty(device->DeviceName)) + if(!device->DeviceName || device->DeviceName[0] == 0) { - std::string devname; - std::tie(devname, std::ignore) = get_device_name_and_guid(mMMDev); - alstr_copy_range(&device->DeviceName, &*devname.cbegin(), &*devname.cend()); + std::string devname{get_device_name_and_guid(mMMDev).first}; + al_free(device->DeviceName); + device->DeviceName = alstrdup(devname.c_str()); } } @@ -1385,7 +1386,8 @@ static ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *devi { ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; self->mDevId = iter->devid; - alstr_copy_range(&device->DeviceName, &*iter->name.cbegin(), &*iter->name.cend()); + al_free(device->DeviceName); + device->DeviceName = alstrdup(iter->name.c_str()); hr = S_OK; } } @@ -1460,11 +1462,11 @@ HRESULT ALCwasapiCapture::openProxy() if(SUCCEEDED(hr)) { mClient = reinterpret_cast(ptr); - if(alstr_empty(device->DeviceName)) + if(!device->DeviceName || device->DeviceName[0] == 0) { - std::string devname; - std::tie(devname, std::ignore) = get_device_name_and_guid(mMMDev); - alstr_copy_range(&device->DeviceName, &*devname.cbegin(), &*devname.cend()); + std::string devname{get_device_name_and_guid(mMMDev).first}; + al_free(device->DeviceName); + device->DeviceName = alstrdup(devname.c_str()); } } diff --git a/Alc/backends/wave.cpp b/Alc/backends/wave.cpp index 48b3e911..ea4af146 100644 --- a/Alc/backends/wave.cpp +++ b/Alc/backends/wave.cpp @@ -242,7 +242,8 @@ static ALCenum ALCwaveBackend_open(ALCwaveBackend *self, const ALCchar *name) } ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice}; - alstr_copy_cstr(&device->DeviceName, name); + al_free(device->DeviceName); + device->DeviceName = alstrdup(name); return ALC_NO_ERROR; } diff --git a/Alc/backends/winmm.cpp b/Alc/backends/winmm.cpp index 6e43ff79..0c625e27 100644 --- a/Alc/backends/winmm.cpp +++ b/Alc/backends/winmm.cpp @@ -286,7 +286,8 @@ retry_open: return ALC_INVALID_VALUE; } - alstr_copy_cstr(&device->DeviceName, PlaybackDevices[DeviceID].c_str()); + al_free(device->DeviceName); + device->DeviceName = alstrdup(PlaybackDevices[DeviceID].c_str()); return ALC_NO_ERROR; } @@ -606,7 +607,8 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *device self->WaveBuffer[i].dwBufferLength = self->WaveBuffer[i-1].dwBufferLength; } - alstr_copy_cstr(&device->DeviceName, CaptureDevices[DeviceID].c_str()); + al_free(device->DeviceName); + device->DeviceName = alstrdup(CaptureDevices[DeviceID].c_str()); return ALC_NO_ERROR; } diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp index 468df505..89f60380 100644 --- a/Alc/helpers.cpp +++ b/Alc/helpers.cpp @@ -729,6 +729,15 @@ void SetRTPriority(void) #endif +char *alstrdup(const char *str) +{ + const size_t len{strlen(str)}; + char *ret{static_cast(al_calloc(DEF_ALIGN, len+1))}; + memcpy(ret, str, len); + return ret; +} + + void alstr_clear(al_string *str) { if(!alstr_empty(*str)) diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 4bc1305d..783686d5 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -82,14 +82,6 @@ std::mutex LoadedHrtfLock; HrtfEntry *LoadedHrtfs{nullptr}; -char *alstrdup(const std::string &str) -{ - const size_t len{str.length()}; - char *ret{static_cast(al_calloc(DEF_ALIGN, len+1))}; - memcpy(ret, str.data(), len); - return ret; -} - class databuf final : public std::streambuf { int_type underflow() override { return traits_type::eof(); } @@ -1016,7 +1008,7 @@ void AddFileEntry(vector_EnumeratedHrtf *list, const std::string &filename) VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_NAME); #undef MATCH_NAME } while(iter != VECTOR_END(*list)); - EnumeratedHrtf entry{ alstrdup(newname), loaded_entry }; + EnumeratedHrtf entry{ alstrdup(newname.c_str()), loaded_entry }; TRACE("Adding file entry \"%s\"\n", entry.name); VECTOR_PUSH_BACK(*list, entry); @@ -1082,7 +1074,7 @@ void AddBuiltInEntry(vector_EnumeratedHrtf *list, const std::string &filename, A VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_NAME); #undef MATCH_NAME } while(iter != VECTOR_END(*list)); - EnumeratedHrtf entry{ alstrdup(newname), loaded_entry }; + EnumeratedHrtf entry{ alstrdup(newname.c_str()), loaded_entry }; TRACE("Adding built-in entry \"%s\"\n", entry.name); VECTOR_PUSH_BACK(*list, entry); diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 6507cec5..9bde25a0 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -63,14 +63,6 @@ constexpr ALsizei ACN2ACN[MAX_AMBI_COEFFS] = { 8, 9, 10, 11, 12, 13, 14, 15 }; -char *alstrdup(const char *str) -{ - const size_t len{strlen(str)}; - char *ret{static_cast(al_calloc(DEF_ALIGN, len+1))}; - memcpy(ret, str, len); - return ret; -} - } // namespace void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread, @@ -388,7 +380,7 @@ static const ChannelMap MonoCfg[1] = { static void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, const ALsizei *RESTRICT chans_per_order) { - const char *devname = alstr_get_cstr(device->DeviceName); + const char *devname = device->DeviceName; ALsizei i; if(GetConfigValueBool(devname, "decoder", "nfc", 1) && ctrl_dist > 0.0f) @@ -408,7 +400,7 @@ static void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei orde static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS]) { - const char *devname = alstr_get_cstr(device->DeviceName); + const char *devname = device->DeviceName; ALfloat maxdist = 0.0f; size_t total = 0; ALsizei i; @@ -521,7 +513,7 @@ static void InitPanning(ALCdevice *device) if(device->FmtChans == DevFmtAmbi3D) { - const char *devname = alstr_get_cstr(device->DeviceName); + const char *devname = device->DeviceName; const ALsizei *acnmap = (device->AmbiLayout == AmbiLayout_FuMa) ? FuMa2ACN : ACN2ACN; const ALfloat *n3dscale = (device->AmbiScale == AmbiNorm_FuMa) ? FuMa2N3DScale : (device->AmbiScale == AmbiNorm_SN3D) ? SN3D2N3DScale : @@ -975,7 +967,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf if(hrtf_appreq == Hrtf_Enable) device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT; - devname = alstr_get_cstr(device->DeviceName); + devname = device->DeviceName; switch(device->FmtChans) { case DevFmtQuad: layout = "quad"; break; @@ -1081,7 +1073,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf if(device->Type != Loopback) { const char *mode; - if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode)) + if(ConfigValueStr(device->DeviceName, NULL, "stereo-mode", &mode)) { if(strcasecmp(mode, "headphones") == 0) headphones = true; @@ -1116,7 +1108,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf if(VECTOR_SIZE(device->HrtfList) == 0) { VECTOR_DEINIT(device->HrtfList); - device->HrtfList = EnumerateHrtf(alstr_get_cstr(device->DeviceName)); + device->HrtfList = EnumerateHrtf(device->DeviceName); } if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->HrtfList)) @@ -1152,7 +1144,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf old_hrtf = NULL; device->Render_Mode = HrtfRender; - if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode)) + if(ConfigValueStr(device->DeviceName, NULL, "hrtf-mode", &mode)) { if(strcasecmp(mode, "full") == 0) device->Render_Mode = HrtfRender; @@ -1196,7 +1188,7 @@ no_hrtf: bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) || (hrtf_appreq == Hrtf_Enable)) ? 5 : 0; if(device->Type != Loopback) - ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel); + ConfigValueInt(device->DeviceName, NULL, "cf_level", &bs2blevel); if(bs2blevel > 0 && bs2blevel <= 6) { device->Bs2b = reinterpret_cast(al_calloc(16, sizeof(*device->Bs2b))); @@ -1208,7 +1200,7 @@ no_hrtf: TRACE("BS2B disabled\n"); - if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-encoding", &mode)) + if(ConfigValueStr(device->DeviceName, NULL, "stereo-encoding", &mode)) { if(strcasecmp(mode, "uhj") == 0) device->Render_Mode = NormalRender; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index b9ace4db..ee20d5be 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -634,7 +634,7 @@ struct ALCdevice_struct { ALCenum LimiterState; - al_string DeviceName; + char *DeviceName; ATOMIC(ALCenum) LastError; @@ -920,6 +920,8 @@ inline void UnlockEffectSlotList(ALCcontext *context) int EventThread(void *arg); +char *alstrdup(const char *str); + #ifdef __cplusplus } // extern "C" -- cgit v1.2.3