소스 검색

Add freeverb adjustable roomsize & damping

dds
PaulStoffregen 6 년 전
부모
커밋
5337b55819
3개의 변경된 파일59개의 추가작업 그리고 13개의 파일을 삭제
  1. +42
    -12
      effect_freeverb.cpp
  2. +15
    -1
      effect_freeverb.h
  3. +2
    -0
      keywords.txt

+ 42
- 12
effect_freeverb.cpp 파일 보기

@@ -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;

+ 15
- 1
effect_freeverb.h 파일 보기

@@ -32,9 +32,23 @@
class AudioEffectFreeverb : public AudioStream
{
public:
//AudioEffectFreeverb() : AudioStream(1, inputQueueArray);
AudioEffectFreeverb();
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:
audio_block_t *inputQueueArray[2];
int16_t comb1buf[1116];

+ 2
- 0
keywords.txt 파일 보기

@@ -89,6 +89,8 @@ unmuteInput KEYWORD2
enableDither KEYWORD2
disableDither KEYWORD2
reverbTime KEYWORD2
roomsize KEYWORD2
damping KEYWORD2
frequency KEYWORD2
phase KEYWORD2
amplitude KEYWORD2

Loading…
취소
저장