From fd409c2be3036fa84badac18e5b8edc3337fb7f1 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 4 Jun 2019 13:19:38 +0200 Subject: [PATCH] Fixing types. Enabling chorus in etup() again. Small fixes. --- MicroMDAEPiano.ino | 30 ++++++++++----------- config.h | 2 +- effect_modulated_chorus.cpp | 54 ++++++++++++++++++++----------------- effect_modulated_chorus.h | 8 +++--- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index d4fe8bc..96c46d3 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -227,22 +227,22 @@ void setup() Serial.print(audio_block_time_us); Serial.println(F("ms)")); - /* - if (!modchorus_r.begin(r_delayline, CHORUS_DELAY_LENGTH)) { - Serial.println(F("AudioEffectModulatedDelay - right channel begin failed")); - while (1); - } - if (!modchorus_l.begin(l_delayline, CHORUS_DELAY_LENGTH)) { - Serial.println(F("AudioEffectModulatedDelay - left channel begin failed")); - while (1); - } + if (!modchorus_r.begin(r_delayline, CHORUS_DELAY_LENGTH)) { + Serial.println(F("AudioEffectModulatedDelay - right channel begin failed")); + while (1); + } + if (!modchorus_l.begin(l_delayline, CHORUS_DELAY_LENGTH)) { + Serial.println(F("AudioEffectModulatedDelay - left channel begin failed")); + while (1); + } - // chorus modulation fixed - modulator.begin(CHORUS_WAVEFORM); - modulator.amplitude(0.1); - modulator.frequency(1.0); - modulator.phase(0); - */ + // chorus modulation fixed + modulator.begin(CHORUS_WAVEFORM); + modulator.amplitude(1.0); + modulator.frequency(1.0); + modulator.phase(0); + modulator.offset(0.0); + // internal mixing of original signal(0), reverb(1) and chorus(2) mixer_r.gain(0, 1.0); mixer_l.gain(0, 1.0); diff --git a/config.h b/config.h index c171b99..a6718a9 100644 --- a/config.h +++ b/config.h @@ -62,7 +62,7 @@ #define USE_XFADE_DATA 1 // CHORUS parameters #define INTERPOLATION_WINDOW_SIZE 7 // For chorus, only odd numbers,please! -#define INTERPOLATE LAGRANGE // LINEAR QUADRATIC COSINE CUBIC LAGRANGE +#define INTERPOLATE QUADRATIC // LINEAR QUADRATIC COSINE CUBIC LAGRANGE #define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE WAVEFORM_SQUARE WAVEFORM_TRIANGLE #define CHORUS_DELAY_LENGTH (16*AUDIO_BLOCK_SAMPLES) diff --git a/effect_modulated_chorus.cpp b/effect_modulated_chorus.cpp index 8059488..1a2c03b 100644 --- a/effect_modulated_chorus.cpp +++ b/effect_modulated_chorus.cpp @@ -58,7 +58,7 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length) _delay_length = d_length; _delay_length_half = d_length / 2; - memset(_delayline, 0, sizeof(short)*_delay_length); + memset(_delayline, 0, sizeof(int16_t)*_delay_length); return (true); } @@ -69,8 +69,8 @@ void AudioEffectModulatedDelay::update(void) audio_block_t *block; audio_block_t *modulation; - short *bp; - short *mp; + int16_t *bp; + int16_t *mp; float mod_idx; if (_delayline == NULL) @@ -83,24 +83,24 @@ void AudioEffectModulatedDelay::update(void) block = receiveWritable(0); modulation = receiveReadOnly(1); - if (block && modulation) - { #ifdef INTERPOLATE - int8_t j; - float x[INTERPOLATION_WINDOW_SIZE]; - float y[INTERPOLATION_WINDOW_SIZE]; - modulation_interpolate.valuelenXY(INTERPOLATION_WINDOW_SIZE); - modulation_interpolate.valueX(x); - modulation_interpolate.valueY(y); - - for (j = 0; j < INTERPOLATION_WINDOW_SIZE; j++) - x[j] = j; + int8_t j; + float x[INTERPOLATION_WINDOW_SIZE]; + float y[INTERPOLATION_WINDOW_SIZE]; + modulation_interpolate.valuelenXY(INTERPOLATION_WINDOW_SIZE); + modulation_interpolate.valueX(x); + modulation_interpolate.valueY(y); + + for (j = 0; j < INTERPOLATION_WINDOW_SIZE; j++) + x[j] = float(j); #endif - bp = block->data; - mp = modulation->data; + bp = block->data; + mp = modulation->data; - for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) + if (block && modulation) + { + for (uint16_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { // write data into circular buffer if (_circ_idx >= _delay_length) @@ -117,15 +117,17 @@ void AudioEffectModulatedDelay::update(void) #ifdef INTERPOLATE // get x/y values around mod_idx uint16_t i_mod_idx = int(mod_idx + 0.5); + uint8_t c = 0; for (j = INTERPOLATION_WINDOW_SIZE / -2; j <= INTERPOLATION_WINDOW_SIZE / 2; j++) { int16_t ji_mod_idx = i_mod_idx + j; if (ji_mod_idx > _delay_length) - y[j] = _delayline[ji_mod_idx - _delay_length - 1]; + y[c] = float(_delayline[ji_mod_idx - _delay_length - 1]); else if (ji_mod_idx < 0) - y[j] = _delayline[_delay_length + j + 1]; + y[c] = float(_delayline[_delay_length + j + 1]); else - y[j] = _delayline[ji_mod_idx]; + y[c] = float(_delayline[ji_mod_idx]); + c++; // ;-) } modulation_interpolate.valueI(mod_idx); @@ -155,8 +157,12 @@ void AudioEffectModulatedDelay::update(void) } } - // transmit the block - transmit(block, 0); - release(block); - release(modulation); + if (block) + { + transmit(block, 0); + release(block); + } + + if (modulation) + release(modulation); } diff --git a/effect_modulated_chorus.h b/effect_modulated_chorus.h index 6c26759..445d9fd 100644 --- a/effect_modulated_chorus.h +++ b/effect_modulated_chorus.h @@ -50,10 +50,10 @@ class AudioEffectModulatedDelay : private: audio_block_t *inputQueueArray[2]; - short *_delayline; - short _circ_idx; - int _delay_length; - int _delay_length_half; + int16_t *_delayline; + int16_t _circ_idx; + uint16_t _delay_length; + uint16_t _delay_length_half; }; #endif