diff options
author | Chris Robinson <[email protected]> | 2018-11-21 15:31:32 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-21 15:31:32 -0800 |
commit | eefc379a239820a0711683455f5fadb20c8dbaf9 (patch) | |
tree | 1e9dbc8f266682cb176d35e235913181f261e025 | |
parent | dfcc98afbf574205e11826753f0a2c2abc7b922e (diff) |
Use a unique_ptr for Uhj2Encoder
-rw-r--r-- | Alc/alc.cpp | 5 | ||||
-rw-r--r-- | Alc/alu.cpp | 2 | ||||
-rw-r--r-- | Alc/panning.cpp | 2 | ||||
-rw-r--r-- | Alc/uhjfilter.h | 22 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 3 |
5 files changed, 14 insertions, 20 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index d9fa549a..2ad6c887 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -48,6 +48,7 @@ #include "alError.h" #include "mastering.h" #include "bformatdec.h" +#include "uhjfilter.h" #include "alu.h" #include "alconfig.h" #include "ringbuffer.h" @@ -1987,7 +1988,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if((device->Flags&DEVICE_RUNNING)) return ALC_NO_ERROR; - al_free(device->Uhj_Encoder); device->Uhj_Encoder = nullptr; al_free(device->Bs2b); @@ -2428,9 +2428,6 @@ ALCdevice_struct::~ALCdevice_struct() al_free(Bs2b); Bs2b = nullptr; - al_free(Uhj_Encoder); - Uhj_Encoder = nullptr; - bformatdec_free(&AmbiDecoder); ambiup_free(&AmbiUp); diff --git a/Alc/alu.cpp b/Alc/alu.cpp index b3ffd24b..a87be0b6 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -162,7 +162,7 @@ void ProcessUhj(ALCdevice *device, ALsizei SamplesToDo) assert(lidx != -1 && ridx != -1); /* Encode to stereo-compatible 2-channel UHJ output. */ - EncodeUhj2(device->Uhj_Encoder, + EncodeUhj2(device->Uhj_Encoder.get(), device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx], device->Dry.Buffer, SamplesToDo ); diff --git a/Alc/panning.cpp b/Alc/panning.cpp index f538e347..c167c227 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -1199,7 +1199,7 @@ no_hrtf: } if(device->Render_Mode == NormalRender) { - device->Uhj_Encoder = reinterpret_cast<Uhj2Encoder*>(al_calloc(16, sizeof(Uhj2Encoder))); + device->Uhj_Encoder.reset(new Uhj2Encoder{}); TRACE("UHJ enabled\n"); InitUhjPanning(device); return; diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h index 211425ed..c6335af3 100644 --- a/Alc/uhjfilter.h +++ b/Alc/uhjfilter.h @@ -4,14 +4,12 @@ #include "AL/al.h" #include "alMain.h" +#include "almalloc.h" -#ifdef __cplusplus -extern "C" { -#endif -typedef struct AllPassState { - ALfloat z[2]; -} AllPassState; +struct AllPassState { + ALfloat z[2]{0.0f, 0.0f}; +}; /* Encoding 2-channel UHJ from B-Format is done as: * @@ -38,20 +36,18 @@ typedef struct AllPassState { * other inputs. */ -typedef struct Uhj2Encoder { +struct Uhj2Encoder { AllPassState Filter1_Y[4]; AllPassState Filter2_WX[4]; AllPassState Filter1_WX[4]; - ALfloat LastY, LastWX; -} Uhj2Encoder; + ALfloat LastY{0.0f}, LastWX{0.0f}; + + DEF_NEWDEL(Uhj2Encoder) +}; /* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input * signal. The input must use FuMa channel ordering and scaling. */ void EncodeUhj2(Uhj2Encoder *enc, ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo); -#ifdef __cplusplus -} // extern "C" -#endif - #endif /* UHJFILTER_H */ diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index e6ad849e..06ccd574 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -207,6 +207,7 @@ struct ALbuffer; struct ALeffect; struct ALfilter; struct EffectState; +struct Uhj2Encoder; #define DEFAULT_OUTPUT_RATE (44100) @@ -669,7 +670,7 @@ struct ALCdevice_struct { ALCenum HrtfStatus{ALC_FALSE}; /* UHJ encoder state */ - struct Uhj2Encoder *Uhj_Encoder{nullptr}; + std::unique_ptr<Uhj2Encoder> Uhj_Encoder; /* High quality Ambisonic decoder */ struct BFormatDec *AmbiDecoder{nullptr}; |