Use a unique_ptr for Uhj2Encoder

This commit is contained in:
Chris Robinson 2018-11-21 15:31:32 -08:00
parent dfcc98afbf
commit eefc379a23
5 changed files with 14 additions and 20 deletions

View File

@ -48,6 +48,7 @@
#include "alError.h" #include "alError.h"
#include "mastering.h" #include "mastering.h"
#include "bformatdec.h" #include "bformatdec.h"
#include "uhjfilter.h"
#include "alu.h" #include "alu.h"
#include "alconfig.h" #include "alconfig.h"
#include "ringbuffer.h" #include "ringbuffer.h"
@ -1987,7 +1988,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if((device->Flags&DEVICE_RUNNING)) if((device->Flags&DEVICE_RUNNING))
return ALC_NO_ERROR; return ALC_NO_ERROR;
al_free(device->Uhj_Encoder);
device->Uhj_Encoder = nullptr; device->Uhj_Encoder = nullptr;
al_free(device->Bs2b); al_free(device->Bs2b);
@ -2428,9 +2428,6 @@ ALCdevice_struct::~ALCdevice_struct()
al_free(Bs2b); al_free(Bs2b);
Bs2b = nullptr; Bs2b = nullptr;
al_free(Uhj_Encoder);
Uhj_Encoder = nullptr;
bformatdec_free(&AmbiDecoder); bformatdec_free(&AmbiDecoder);
ambiup_free(&AmbiUp); ambiup_free(&AmbiUp);

View File

@ -162,7 +162,7 @@ void ProcessUhj(ALCdevice *device, ALsizei SamplesToDo)
assert(lidx != -1 && ridx != -1); assert(lidx != -1 && ridx != -1);
/* Encode to stereo-compatible 2-channel UHJ output. */ /* 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->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
device->Dry.Buffer, SamplesToDo device->Dry.Buffer, SamplesToDo
); );

View File

@ -1199,7 +1199,7 @@ no_hrtf:
} }
if(device->Render_Mode == NormalRender) 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"); TRACE("UHJ enabled\n");
InitUhjPanning(device); InitUhjPanning(device);
return; return;

View File

@ -4,14 +4,12 @@
#include "AL/al.h" #include "AL/al.h"
#include "alMain.h" #include "alMain.h"
#include "almalloc.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct AllPassState { struct AllPassState {
ALfloat z[2]; ALfloat z[2]{0.0f, 0.0f};
} AllPassState; };
/* Encoding 2-channel UHJ from B-Format is done as: /* Encoding 2-channel UHJ from B-Format is done as:
* *
@ -38,20 +36,18 @@ typedef struct AllPassState {
* other inputs. * other inputs.
*/ */
typedef struct Uhj2Encoder { struct Uhj2Encoder {
AllPassState Filter1_Y[4]; AllPassState Filter1_Y[4];
AllPassState Filter2_WX[4]; AllPassState Filter2_WX[4];
AllPassState Filter1_WX[4]; AllPassState Filter1_WX[4];
ALfloat LastY, LastWX; ALfloat LastY{0.0f}, LastWX{0.0f};
} Uhj2Encoder;
DEF_NEWDEL(Uhj2Encoder)
};
/* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input /* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
* signal. The input must use FuMa channel ordering and scaling. * 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); void EncodeUhj2(Uhj2Encoder *enc, ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* UHJFILTER_H */ #endif /* UHJFILTER_H */

View File

@ -207,6 +207,7 @@ struct ALbuffer;
struct ALeffect; struct ALeffect;
struct ALfilter; struct ALfilter;
struct EffectState; struct EffectState;
struct Uhj2Encoder;
#define DEFAULT_OUTPUT_RATE (44100) #define DEFAULT_OUTPUT_RATE (44100)
@ -669,7 +670,7 @@ struct ALCdevice_struct {
ALCenum HrtfStatus{ALC_FALSE}; ALCenum HrtfStatus{ALC_FALSE};
/* UHJ encoder state */ /* UHJ encoder state */
struct Uhj2Encoder *Uhj_Encoder{nullptr}; std::unique_ptr<Uhj2Encoder> Uhj_Encoder;
/* High quality Ambisonic decoder */ /* High quality Ambisonic decoder */
struct BFormatDec *AmbiDecoder{nullptr}; struct BFormatDec *AmbiDecoder{nullptr};