Use unique_ptr for bs2b

This commit is contained in:
Chris Robinson
2018-11-22 06:49:37 -08:00
parent b3b4220182
commit 9d73e03aaa
5 changed files with 16 additions and 23 deletions
+1 -5
View File
@@ -53,6 +53,7 @@
#include "alconfig.h"
#include "ringbuffer.h"
#include "filters/splitter.h"
#include "bs2b.h"
#include "fpu_modes.h"
#include "cpu_caps.h"
@@ -1990,8 +1991,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
return ALC_NO_ERROR;
device->Uhj_Encoder = nullptr;
al_free(device->Bs2b);
device->Bs2b = nullptr;
device->ChannelDelay.clear();
@@ -2421,9 +2420,6 @@ ALCdevice_struct::~ALCdevice_struct()
HrtfHandle = nullptr;
al_free(Hrtf);
Hrtf = nullptr;
al_free(Bs2b);
Bs2b = nullptr;
}
+1 -1
View File
@@ -175,7 +175,7 @@ void ProcessBs2b(ALCdevice *device, ALsizei SamplesToDo)
assert(lidx != -1 && ridx != -1);
/* Apply binaural/crossfeed filter */
bs2b_cross_feed(device->Bs2b, device->RealOut.Buffer[lidx],
bs2b_cross_feed(device->Bs2b.get(), device->RealOut.Buffer[lidx],
device->RealOut.Buffer[ridx], SamplesToDo);
}
+3 -3
View File
@@ -1163,7 +1163,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf
no_hrtf:
if(old_hrtf)
Hrtf_DecRef(old_hrtf);
old_hrtf = NULL;
old_hrtf = nullptr;
TRACE("HRTF disabled\n");
device->Render_Mode = StereoPair;
@@ -1176,8 +1176,8 @@ no_hrtf:
ConfigValueInt(device->DeviceName.c_str(), NULL, "cf_level", &bs2blevel);
if(bs2blevel > 0 && bs2blevel <= 6)
{
device->Bs2b = reinterpret_cast<struct bs2b*>(al_calloc(16, sizeof(*device->Bs2b)));
bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
device->Bs2b.reset(new bs2b{});
bs2b_set_params(device->Bs2b.get(), bs2blevel, device->Frequency);
TRACE("BS2B enabled\n");
InitPanning(device);
return;
+2 -1
View File
@@ -210,6 +210,7 @@ struct EffectState;
struct Uhj2Encoder;
struct BFormatDec;
struct AmbiUpsampler;
struct bs2b;
#define DEFAULT_OUTPUT_RATE (44100)
@@ -678,7 +679,7 @@ struct ALCdevice_struct {
std::unique_ptr<BFormatDec> AmbiDecoder;
/* Stereo-to-binaural filter */
struct bs2b *Bs2b{nullptr};
std::unique_ptr<bs2b> Bs2b;
/* First-order ambisonic upsampler for higher-order output */
std::unique_ptr<AmbiUpsampler> AmbiUp;
+9 -13
View File
@@ -24,6 +24,8 @@
#ifndef BS2B_H
#define BS2B_H
#include "almalloc.h"
/* Number of crossfeed levels */
#define BS2B_CLEVELS 3
@@ -42,10 +44,6 @@
/* Default sample rate (Hz) */
#define BS2B_DEFAULT_SRATE 44100
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct bs2b {
int level; /* Crossfeed level */
int srate; /* Sample rate (Hz) */
@@ -67,6 +65,8 @@ struct bs2b {
float lo;
float hi;
} last_sample[2];
DEF_NEWDEL(bs2b)
};
/* Clear buffers and set new coefficients with new crossfeed level and sample
@@ -74,21 +74,17 @@ struct bs2b {
* level - crossfeed level of *LEVEL values.
* srate - sample rate by Hz.
*/
void bs2b_set_params(struct bs2b *bs2b, int level, int srate);
void bs2b_set_params(bs2b *bs2b, int level, int srate);
/* Return current crossfeed level value */
int bs2b_get_level(struct bs2b *bs2b);
int bs2b_get_level(bs2b *bs2b);
/* Return current sample rate value */
int bs2b_get_srate(struct bs2b *bs2b);
int bs2b_get_srate(bs2b *bs2b);
/* Clear buffer */
void bs2b_clear(struct bs2b *bs2b);
void bs2b_clear(bs2b *bs2b);
void bs2b_cross_feed(struct bs2b *bs2b, float *RESTRICT Left, float *RESTRICT Right, int SamplesToDo);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
void bs2b_cross_feed(bs2b *bs2b, float *RESTRICT Left, float *RESTRICT Right, int SamplesToDo);
#endif /* BS2B_H */