Bladeren bron

Add freeverb adjustable roomsize & damping

dds
PaulStoffregen 7 jaren geleden
bovenliggende
commit
5337b55819
3 gewijzigde bestanden met toevoegingen van 59 en 13 verwijderingen
  1. +42
    -12
      effect_freeverb.cpp
  2. +15
    -1
      effect_freeverb.h
  3. +2
    -0
      keywords.txt

+ 42
- 12
effect_freeverb.cpp Bestand weergeven

* THE SOFTWARE. * 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 <Arduino.h>
#include "effect_freeverb.h" #include "effect_freeverb.h"
#include "utility/dspinst.h" #include "utility/dspinst.h"
} }
#endif #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() void AudioEffectFreeverb::update()
{ {
#if defined(KINETISK) #if defined(KINETISK)
audio_block_t *block, *outblock;
const audio_block_t *block;
audio_block_t *outblock;
int i; int i;
int16_t input, bufout, output; int16_t input, bufout, output;
int32_t sum; int32_t sum;


outblock = allocate(); outblock = allocate();
if (!outblock) { if (!outblock) {
block = receiveReadOnly(0);
if (block) release(block);
audio_block_t *tmp = receiveReadOnly(0);
if (tmp) release(tmp);
return; return;
} }
block = receiveReadOnly(0); 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; sum = 0;


bufout = comb1buf[comb1index]; bufout = comb1buf[comb1index];
output = sat16(bufout - output, 1); output = sat16(bufout - output, 1);
if (++allpass4index >= sizeof(allpass4buf)/sizeof(int16_t)) allpass4index = 0; 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); transmit(outblock);
release(outblock); release(outblock);
release(block);
if (block != &zeroblock) release((audio_block_t *)block);


#elif defined(KINETISL) #elif defined(KINETISL)
audio_block_t *block; audio_block_t *block;

+ 15
- 1
effect_freeverb.h Bestand weergeven

class AudioEffectFreeverb : public AudioStream class AudioEffectFreeverb : public AudioStream
{ {
public: public:
//AudioEffectFreeverb() : AudioStream(1, inputQueueArray);
AudioEffectFreeverb(); AudioEffectFreeverb();
virtual void update(); virtual void update();
void roomsize(float n) {
if (n > 1.0f) n = 1.0f;
else if (n < 0.0) n = 0.0f;
combfeeback = (int)(n * 9175.04f) + 22937;
}
void damping(float n) {
if (n > 1.0f) n = 1.0f;
else if (n < 0.0) n = 0.0f;
int x1 = (int)(n * 13107.2f);
int x2 = 32768 - x1;
__disable_irq();
combdamp1 = x1;
combdamp2 = x2;
__enable_irq();
}
private: private:
audio_block_t *inputQueueArray[2]; audio_block_t *inputQueueArray[2];
int16_t comb1buf[1116]; int16_t comb1buf[1116];

+ 2
- 0
keywords.txt Bestand weergeven

enableDither KEYWORD2 enableDither KEYWORD2
disableDither KEYWORD2 disableDither KEYWORD2
reverbTime KEYWORD2 reverbTime KEYWORD2
roomsize KEYWORD2
damping KEYWORD2
frequency KEYWORD2 frequency KEYWORD2
phase KEYWORD2 phase KEYWORD2
amplitude KEYWORD2 amplitude KEYWORD2

Laden…
Annuleren
Opslaan