1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

Fix uninitialized variables in Reverb...

... but bringing back some naked calloc and free that weren't replaced quite
right, and I'll figure out why later.

This reverts commit e94fa1d65e5555b78cae164f7b9ca5a6f363d8b8.
This reverts commit 0c7e467a081fb998d183bdc169cd8ddd69648b25.
This commit is contained in:
Paul Licameli 2017-08-31 20:25:24 -04:00
parent 7423a2c232
commit fd8b76dd80
4 changed files with 45 additions and 80 deletions

View File

@ -1,10 +1,5 @@
#ifndef __BIQUAD_H__
#define __BIQUAD_H__
#if 0
//initialisations not supported in MSVC 2013.
//Gives error C2905
// Do not make conditional on compiler.
typedef struct {
float* pfIn {};
float* pfOut {};
@ -15,22 +10,6 @@ typedef struct {
float fPrevOut {};
float fPrevPrevOut {};
} BiquadStruct;
#else
// WARNING: This structure may need initialisation.
typedef struct {
float* pfIn;
float* pfOut;
float fNumerCoeffs [3]; // B0 B1 B2
float fDenomCoeffs [2]; // A1 A2
float fPrevIn;
float fPrevPrevIn;
float fPrevOut;
float fPrevPrevOut;
} BiquadStruct;
#endif
void Biquad_Process (BiquadStruct* pBQ, int iNumSamples);
void ComplexDiv (float fNumerR, float fNumerI, float fDenomR, float fDenomI, float* pfQuotientR, float* pfQuotientI);
bool BilinTransform (float fSX, float fSY, float* pfZX, float* pfZY);

View File

@ -75,25 +75,12 @@ FactoryPresets[] =
{ XO("Cathedral"), { 90, 16, 90, 50, 100, 0, 0, -20, 100, false } },
};
#if 0
//initialisations not supported in MSVC 2013.
//Gives error C2905
// Do not make conditional on compiler.
struct Reverb_priv_t
{
reverb_t reverb;
float *dry {};
float *wet[2] { {}, {} };
};
#else
// WARNING: This structure may need initialisation.
struct Reverb_priv_t
{
reverb_t reverb;
float *dry;
float *wet[2];
};
#endif
//
// EffectReverb
@ -189,7 +176,7 @@ bool EffectReverb::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelName
mNumChans = 2;
}
mP.reinit(mNumChans, true);
mP = (Reverb_priv_t *) calloc(sizeof(*mP), mNumChans);
for (int i = 0; i < mNumChans; i++)
{
@ -212,7 +199,12 @@ bool EffectReverb::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelName
bool EffectReverb::ProcessFinalize()
{
mP.reset();
for (int i = 0; i < mNumChans; i++)
{
reverb_delete(&mP[i].reverb);
}
free(mP);
return true;
}

View File

@ -98,7 +98,7 @@ private:
private:
unsigned mNumChans {};
ArrayOf<Reverb_priv_t> mP;
Reverb_priv_t *mP;
Params mParams;

View File

@ -29,38 +29,23 @@ using std::max;
#define FIFO_SIZE_T size_t
#define FIFO_MIN 0x4000
#define fifo_read_ptr(f) fifo_read(f, (FIFO_SIZE_T)0, NULL)
#define lsx_zalloc(var, n) (var.reinit(n, true), var.get())
#define filter_advance(p) if (--(p)->ptr < (p)->buffer.get()) (p)->ptr += (p)->size
#define lsx_zalloc(var, n) var = (float *)calloc(n, sizeof(*var))
#define filter_advance(p) if (--(p)->ptr < (p)->buffer) (p)->ptr += (p)->size
#define filter_delete(p) free((p)->buffer)
#if 0
//initialisations not supported in MSVC 2013.
//Gives error C2905
// Do not make conditional on compiler.
typedef struct {
ArrayOf<char> data;
size_t allocation {}; /* Number of bytes allocated for data. */
size_t item_size {}; /* Size of each item in data */
size_t begin {}; /* Offset of the first byte to read. */
size_t end {}; /* 1 + Offset of the last byte byte to read. */
} fifo_t;
#else
// WARNING: This structure may need initialisation.
typedef struct {
ArrayOf<char> data;
char * data;
size_t allocation; /* Number of bytes allocated for data. */
size_t item_size; /* Size of each item in data */
size_t begin; /* Offset of the first byte to read. */
size_t end; /* 1 + Offset of the last byte byte to read. */
} fifo_t;
#endif
static void fifo_clear(fifo_t * f)
{
f->end = f->begin = 0;
}
static void * fifo_reserve(fifo_t * f, FIFO_SIZE_T n)
{
n *= f->item_size;
@ -70,19 +55,19 @@ static void * fifo_reserve(fifo_t * f, FIFO_SIZE_T n)
while (1) {
if (f->end + n <= f->allocation) {
void *p = f->data.get() + f->end;
void *p = f->data + f->end;
f->end += n;
return p;
}
if (f->begin > FIFO_MIN) {
memmove(f->data.get(), f->data.get() + f->begin, f->end - f->begin);
memmove(f->data, f->data + f->begin, f->end - f->begin);
f->end -= f->begin;
f->begin = 0;
continue;
}
f->allocation += n;
f->data.reinit(f->allocation);
f->data = (char *)realloc(f->data, f->allocation);
}
}
@ -96,7 +81,7 @@ static void * fifo_write(fifo_t * f, FIFO_SIZE_T n, void const * data)
static void * fifo_read(fifo_t * f, FIFO_SIZE_T n, void * data)
{
char * ret = f->data.get() + f->begin;
char * ret = f->data + f->begin;
n *= f->item_size;
if (n > (FIFO_SIZE_T)(f->end - f->begin))
return NULL;
@ -106,18 +91,22 @@ static void * fifo_read(fifo_t * f, FIFO_SIZE_T n, void * data)
return ret;
}
static void fifo_delete(fifo_t * f)
{
free(f->data);
}
static void fifo_create(fifo_t * f, FIFO_SIZE_T item_size)
{
f->item_size = item_size;
f->allocation = FIFO_MIN;
f->data.reinit(f->allocation);
f->data = (char *)malloc(f->allocation);
fifo_clear(f);
}
typedef struct {
size_t size;
ArrayOf<float> buffer;
float * ptr;
float * buffer, * ptr;
float store;
} filter_t;
@ -210,29 +199,24 @@ static void filter_array_process(filter_array_t * p,
}
}
#if 0
//initialisations not supported in MSVC 2013.
//Gives error C2905
// Do not make conditional on compiler.
typedef struct {
float feedback {};
float hf_damping {};
float gain {};
fifo_t input_fifo {};
filter_array_t chan[2];
ArrayOf<float> out[2];
} reverb_t;
#else
// WARNING: This structure may need initialisation.
static void filter_array_delete(filter_array_t * p)
{
size_t i;
for (i = 0; i < array_length(allpass_lengths); ++i)
filter_delete(&p->allpass[i]);
for (i = 0; i < array_length(comb_lengths); ++i)
filter_delete(&p->comb[i]);
}
typedef struct {
float feedback;
float hf_damping;
float gain;
fifo_t input_fifo;
filter_array_t chan[2];
ArrayOf<float> out[2];
float * out[2];
} reverb_t;
#endif
static void reverb_create(reverb_t * p, double sample_rate_Hz,
double wet_gain_dB,
@ -270,7 +254,17 @@ static void reverb_process(reverb_t * p, size_t length)
{
size_t i;
for (i = 0; i < 2 && p->out[i]; ++i)
filter_array_process(p->chan + i, length, (float *) fifo_read_ptr(&p->input_fifo), p->out[i].get(), &p->feedback, &p->hf_damping, &p->gain);
filter_array_process(p->chan + i, length, (float *) fifo_read_ptr(&p->input_fifo), p->out[i], &p->feedback, &p->hf_damping, &p->gain);
fifo_read(&p->input_fifo, length, NULL);
}
static void reverb_delete(reverb_t * p)
{
size_t i;
for (i = 0; i < 2 && p->out[i]; ++i) {
free(p->out[i]);
filter_array_delete(p->chan + i);
}
fifo_delete(&p->input_fifo);
}