From 9c155a57fb37e3869f16e2f6502ee7d95d7d6a75 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 22 Nov 2018 07:54:29 -0800 Subject: [PATCH] Use unique_ptr for DirectHrtfState --- Alc/alc.cpp | 2 -- Alc/alu.cpp | 2 +- Alc/hrtf.h | 3 +++ Alc/panning.cpp | 9 ++++----- OpenAL32/Include/alMain.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 10b4c007..42856dbf 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2418,8 +2418,6 @@ ALCdevice_struct::~ALCdevice_struct() if(HrtfHandle) Hrtf_DecRef(HrtfHandle); HrtfHandle = nullptr; - al_free(mHrtfState); - mHrtfState = nullptr; } diff --git a/Alc/alu.cpp b/Alc/alu.cpp index c67e8705..fc386908 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -119,7 +119,7 @@ void ProcessHrtf(ALCdevice *device, ALsizei SamplesToDo) int ridx{GetChannelIdxByName(&device->RealOut, FrontRight)}; assert(lidx != -1 && ridx != -1); - DirectHrtfState *state{device->mHrtfState}; + DirectHrtfState *state{device->mHrtfState.get()}; for(ALsizei c{0};c < device->Dry.NumChannels;c++) { MixDirectHrtf(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx], diff --git a/Alc/hrtf.h b/Alc/hrtf.h index d73faca7..1409ffa8 100644 --- a/Alc/hrtf.h +++ b/Alc/hrtf.h @@ -7,6 +7,7 @@ #include "alMain.h" #include "atomic.h" #include "vector.h" +#include "almalloc.h" #define HRTF_HISTORY_BITS (6) @@ -55,6 +56,8 @@ struct DirectHrtfState { alignas(16) ALfloat Values[HRIR_LENGTH][2]; alignas(16) ALfloat Coeffs[HRIR_LENGTH][2]; } Chan[]; + + DEF_PLACE_NEWDEL() }; struct AngularPoint { diff --git a/Alc/panning.cpp b/Alc/panning.cpp index e0677600..a67234ec 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -857,8 +857,8 @@ static void InitHrtfPanning(ALCdevice *device) count = COUNTOF(IndexMap); } - device->mHrtfState = reinterpret_cast( - al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count))); + device->mHrtfState.reset( + new (al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count))) DirectHrtfState{}); for(i = 0;i < count;i++) { @@ -892,8 +892,8 @@ static void InitHrtfPanning(ALCdevice *device) device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->mAmbiOrder); BuildBFormatHrtf(device->HrtfHandle, - device->mHrtfState, device->Dry.NumChannels, AmbiPoints, AmbiMatrix, COUNTOF(AmbiPoints), - AmbiOrderHFGain + device->mHrtfState.get(), device->Dry.NumChannels, AmbiPoints, AmbiMatrix, + COUNTOF(AmbiPoints), AmbiOrderHFGain ); InitNearFieldCtrl(device, device->HrtfHandle->distance, device->AmbiUp ? 2 : 1, @@ -930,7 +930,6 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf int bs2blevel; size_t i; - al_free(device->mHrtfState); device->mHrtfState = nullptr; device->HrtfHandle = nullptr; device->HrtfName.clear(); diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 3a8e28fc..744e3609 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -666,7 +666,7 @@ struct ALCdevice_struct { POSTPROCESS PostProcess{}; /* HRTF state and info */ - DirectHrtfState *mHrtfState{nullptr}; + std::unique_ptr mHrtfState; std::string HrtfName; Hrtf *HrtfHandle{nullptr}; al::vector HrtfList; -- 2.11.4.GIT