19 #define M_LN10 2.30258509299404568402
28#define array_length(a) (sizeof(a)/sizeof(a[0]))
29#define dB_to_linear(x) exp((x) * M_LN10 * 0.05)
30#define midi_to_freq(n) (440 * pow(2,((n)-69)/12.))
31#define FIFO_SIZE_T size_t
32#define FIFO_MIN 0x4000
33#define fifo_read_ptr(f) fifo_read(f, (FIFO_SIZE_T)0, NULL)
34#define lsx_zalloc(var, n) var = (float *)calloc(n, sizeof(*var))
35#define filter_advance(p) if (--(p)->ptr < (p)->buffer) (p)->ptr += (p)->size
36#define filter_delete(p) free((p)->buffer)
66 if (f->
end + n <= f->allocation) {
98 memcpy(data, ret, (
size_t)n);
123 float const * input,
float const * feedback,
float const * hf_damping)
125 float output = *p->
ptr;
126 p->
store = output + (p->
store - output) * *hf_damping;
127 *p->
ptr = *input + p->
store * *feedback;
135 float output = *p->
ptr;
136 *p->
ptr = *input + output * .5;
138 return output - *input;
145 float o0 = i0*p->
b0 + p->
i1*p->
b1 - p->
o1*p->
a1;
161 double fc_highpass,
double fc_lowpass)
165 q->
a1 = -exp(-2 *
M_PI * fc_highpass / rate);
166 q->
b0 = (1 - q->
a1) / 2, q->
b1 = -q->
b0;
170 q->
a1 = -exp(-2 *
M_PI * fc_lowpass / rate);
171 q->
b0 = 1 + q->
a1, q->
b1 = 0;
177 double scale,
double offset)
180 double r = rate * (1 / 44100.);
199 double scale,
double offset)
202 double r = rate * (1 / 44100.);
221 double scale,
double offset)
224 double r = rate * (1 / 44100.);
241 size_t length,
float const * input,
float * output,
242 float const * feedback,
float const * hf_damping,
float const * gain)
245 float out = 0, in = *input++;
257 *output++ = out * *gain;
285 memset(p->
buffer, 0, newSize *
sizeof(
float));
324 const int sizeDiff = ((ssize_t)newSize - (ssize_t)p->
size);
325 const size_t ptrPos = (p->
ptr - p->
buffer);
327 const size_t numSamplesBehindPtr = (p->
size - 1) - ptrPos;
333 if (numSamplesBehindPtr > 0)
336 memcpy(p->
ptr + 1 + sizeDiff, p->
ptr + 1, numSamplesBehindPtr *
sizeof(
float));
340 memset(p->
ptr + 1, 0, sizeDiff *
sizeof(
float));
342 else if (sizeDiff < 0)
346 if (ptrPos < newSize-1)
348 size_t lenOfBlockToShift = newSize - 1 - ptrPos;
349 float* ptrToBlockToShift = p->
buffer + p->
size - lenOfBlockToShift;
350 memcpy(p->
ptr + 1, ptrToBlockToShift, lenOfBlockToShift *
sizeof(
float));
352 else if (ptrPos == newSize - 1)
360 memcpy(p->
buffer, p->
ptr - newSize + 1, newSize *
sizeof(
float));
392 memset(p, 0,
sizeof(*p));
414 double sample_rate_Hz,
423 double a = -1 / log(1 - .3 );
424 double b = 100 / (log(1 - .98) * a + 1);
426 p->
feedback = 1 - exp((reverberance - b) / (a * b));
432 double fc_highpass =
midi_to_freq(72 - tone_low / 100 * 48);
433 double fc_lowpass =
midi_to_freq(72 + tone_high / 100 * 48);
442 double sample_rate_Hz,
455 size_t delay = pre_delay_ms / 1000 * sample_rate_Hz + .5;
461 double scale = room_scale / 100 * .9 + .1;
462 double depth = stereo_depth / 100;
463 for (
size_t i = 0; i <= ceil(depth); ++i)
488 reverb_init(p, sample_rate_Hz, wet_gain_dB, room_scale, reverberance, hf_damping, pre_delay_ms, stereo_depth, tone_low, tone_high);
504 for (i = 0; i < 2 && p->
out[i]; ++i) {
513 for (
size_t c = 0; c < 2; c++)
515 auto& chn = p->
chan[c];
518 chn.one_pole[0].o1 = 0.0;
520 chn.one_pole[1].i1 = 0.0;
521 chn.one_pole[1].o1 = 0.0;
525 auto& comb = chn.comb[combIndex];
527 memset(comb.buffer, 0, comb.size *
sizeof(
float));
534 auto& allpass = chn.allpass[allpassIndex];
536 memset(allpass.buffer, 0, allpass.size *
sizeof(
float));
538 allpass.store = 0.0f;
static void * fifo_read(fifo_t *f, FIFO_SIZE_T n, void *data)
static float one_pole_process(one_pole_t *p, float i0)
static void reverb_init(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double room_scale, double reverberance, double hf_damping, double pre_delay_ms, double stereo_depth, double tone_low, double tone_high)
static void * fifo_reserve(fifo_t *f, FIFO_SIZE_T n)
static const size_t comb_lengths[]
static void fifo_delete(fifo_t *f)
static void fifo_create(fifo_t *f, FIFO_SIZE_T item_size)
static const size_t stereo_adjust
static float allpass_process(filter_t *p, float const *input)
static void filter_t_resize_preserving(filter_t *p, size_t newSize)
static void filter_array_create(filter_array_t *p, double rate, double scale, double offset)
static void filter_array_delete(filter_array_t *p)
static void reverb_set_simple_params(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double reverberance, double hf_damping, double tone_low, double tone_high)
static void filter_array_process(filter_array_t *p, size_t length, float const *input, float *output, float const *feedback, float const *hf_damping, float const *gain)
static void reverb_allocate(reverb_t *p, double sample_rate_Hz, size_t buffer_size, float **out)
static void reverb_process(reverb_t *p, size_t length)
static float comb_process(filter_t *p, float const *input, float const *feedback, float const *hf_damping)
static void one_pole_init(filter_array_t *p, double rate, double fc_highpass, double fc_lowpass)
static void reverb_delete(reverb_t *p)
static void filter_t_resize(filter_t *p, size_t newSize)
static void reverb_clear(reverb_t *p)
static void reverb_create(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double room_scale, double reverberance, double hf_damping, double pre_delay_ms, double stereo_depth, double tone_low, double tone_high, size_t buffer_size, float **out)
static const size_t allpass_lengths[]
#define filter_advance(p)
static void fifo_clear_and_zero(fifo_t *f)
static void fifo_clear(fifo_t *f)
static void filter_array_allocate(filter_array_t *p, double rate, double scale, double offset)
static void filter_array_init(filter_array_t *p, double rate, double scale, double offset)
static void * fifo_write(fifo_t *f, FIFO_SIZE_T n, void const *data)
static void filter_t_resize_resetting(filter_t *p, size_t newSize)
#define lsx_zalloc(var, n)
filter_t comb[array_length(comb_lengths)]
filter_t allpass[array_length(allpass_lengths)]
bool initializedWithZeroDepth