|
|
@@ -24,6 +24,10 @@ |
|
|
|
* THE SOFTWARE. |
|
|
|
*/ |
|
|
|
|
|
|
|
// A fixed point implementation of Freeverb by Jezar at Dreampoint |
|
|
|
// http://blog.bjornroche.com/2012/06/freeverb-original-public-domain-code-by.html |
|
|
|
// https://music.columbia.edu/pipermail/music-dsp/2001-October/045433.html |
|
|
|
|
|
|
|
#include <Arduino.h> |
|
|
|
#include "effect_freeverb.h" |
|
|
|
#include "utility/dspinst.h" |
|
|
@@ -83,28 +87,54 @@ static int16_t sat16(int32_t n, int rshift) |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// TODO: move this to one of the data files, use in output_adat.cpp, output_tdm.cpp, etc |
|
|
|
static const audio_block_t zeroblock = { |
|
|
|
0, 0, 0, { |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 16 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 32 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 48 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 64 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 80 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 96 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
#if AUDIO_BLOCK_SAMPLES > 112 |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
#endif |
|
|
|
} }; |
|
|
|
|
|
|
|
void AudioEffectFreeverb::update() |
|
|
|
{ |
|
|
|
#if defined(KINETISK) |
|
|
|
audio_block_t *block, *outblock; |
|
|
|
const audio_block_t *block; |
|
|
|
audio_block_t *outblock; |
|
|
|
int i; |
|
|
|
int16_t input, bufout, output; |
|
|
|
int32_t sum; |
|
|
|
|
|
|
|
outblock = allocate(); |
|
|
|
if (!outblock) { |
|
|
|
block = receiveReadOnly(0); |
|
|
|
if (block) release(block); |
|
|
|
audio_block_t *tmp = receiveReadOnly(0); |
|
|
|
if (tmp) release(tmp); |
|
|
|
return; |
|
|
|
} |
|
|
|
block = receiveReadOnly(0); |
|
|
|
if (!block) { |
|
|
|
release(outblock); |
|
|
|
return; |
|
|
|
// TODO: pointer to zero block |
|
|
|
} |
|
|
|
for (i=0; i < 128; i++) { |
|
|
|
input = sat16(block->data[i] * 21845, 17); // div by 6, for numerical headroom |
|
|
|
if (!block) block = &zeroblock; |
|
|
|
|
|
|
|
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) { |
|
|
|
// TODO: scale numerical range depending on roomsize & damping |
|
|
|
input = sat16(block->data[i] * 8738, 17); // for numerical headroom |
|
|
|
sum = 0; |
|
|
|
|
|
|
|
bufout = comb1buf[comb1index]; |
|
|
@@ -177,11 +207,11 @@ void AudioEffectFreeverb::update() |
|
|
|
output = sat16(bufout - output, 1); |
|
|
|
if (++allpass4index >= sizeof(allpass4buf)/sizeof(int16_t)) allpass4index = 0; |
|
|
|
|
|
|
|
outblock->data[i] = sat16(output * 12, 0); |
|
|
|
outblock->data[i] = sat16(output * 30, 0); |
|
|
|
} |
|
|
|
transmit(outblock); |
|
|
|
release(outblock); |
|
|
|
release(block); |
|
|
|
if (block != &zeroblock) release((audio_block_t *)block); |
|
|
|
|
|
|
|
#elif defined(KINETISL) |
|
|
|
audio_block_t *block; |