From e9f689d5f66ff524f51618c1ddc7b515ba5a7450 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 9 Jun 2019 11:15:43 +0200 Subject: [PATCH] SMaller fixes and tests. --- MicroMDAEPiano.ino | 13 +++++++------ config.h | 8 ++++---- effect_modulated_delay.cpp | 15 ++++++--------- effect_modulated_delay.h | 4 ---- mdaEPiano.cpp | 2 +- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 9c2ed69..8f3893b 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -158,6 +158,7 @@ elapsedMillis cpu_mem_millis; short l_delayline[CHORUS_DELAY_LENGTH_SAMPLES]; short r_delayline[CHORUS_DELAY_LENGTH_SAMPLES]; +enum { VOL_MAIN, VOL_REVERB, VOL_CHORUS }; //************************************************************************************************* //* SETUP FUNCTION //************************************************************************************************* @@ -244,12 +245,12 @@ void setup() inverter.gain(-1.0); // change phase for second moduleated delay // internal mixing of original signal(0), reverb(1) and chorus(2) - mixer_r.gain(0, 0.5); - mixer_l.gain(0, 0.5); - mixer_r.gain(1, 0.2); - mixer_l.gain(1, 0.2); - mixer_r.gain(2, 0.3); - mixer_l.gain(2, 0.3); + mixer_r.gain(VOL_MAIN, 0.4); + mixer_l.gain(VOL_MAIN, 0.4); + mixer_r.gain(VOL_REVERB, 0.2); + mixer_l.gain(VOL_REVERB, 0.2); + mixer_r.gain(VOL_CHORUS, 0.2); + mixer_l.gain(VOL_CHORUS, 0.2); // set master volume set_master_volume(master_volume); diff --git a/config.h b/config.h index 1384677..009c441 100644 --- a/config.h +++ b/config.h @@ -62,9 +62,9 @@ #define USE_XFADE_DATA 1 // CHORUS parameters #define INTERPOLATION_WINDOW_SIZE 7 // use only odd numbers!!! -#define INTERPOLATE Catmull -#define CHORUS_WAVEFORM WAVEFORM_SINE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE -#define CHORUS_DELAY_LENGTH_SAMPLES (14*AUDIO_BLOCK_SAMPLES) // one AUDIO_BLOCK_SAMPLES = 2.902ms; you need doubled length, e.g. delay point is 20ms, so you need up to 40ms delay! +#define INTERPOLATE_MODE 11 +#define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE +#define CHORUS_DELAY_LENGTH_SAMPLES (15*AUDIO_BLOCK_SAMPLES) // one AUDIO_BLOCK_SAMPLES = 2.902ms; you need doubled length, e.g. delay point is 20ms, so you need up to 40ms delay! //************************************************************************************************* //* DEBUG OUTPUT SETTINGS @@ -101,7 +101,7 @@ 30: 1.22 Volts p-p 31: 1.16 Volts p-p */ -#define SGTL5000_LINEOUT_LEVEL 29 +#define SGTL5000_LINEOUT_LEVEL 26 //#define SDCARD_CS_PIN 10 //#define SDCARD_MOSI_PIN 7 //#define SDCARD_SCK_PIN 14 diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index f62ae2b..0280a05 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -78,11 +78,11 @@ void AudioEffectModulatedDelay::update(void) block = receiveWritable(0); modulation = receiveReadOnly(1); -#ifdef INTERPOLATE +#ifdef INTERPOLATE_MODE int8_t j; float x[INTERPOLATION_WINDOW_SIZE]; float y[INTERPOLATION_WINDOW_SIZE]; - Spline s(x, y, INTERPOLATION_WINDOW_SIZE, INTERPOLATE); + Spline s(x, y, INTERPOLATION_WINDOW_SIZE, INTERPOLATE_MODE); #endif bp = block->data; @@ -100,28 +100,25 @@ void AudioEffectModulatedDelay::update(void) // calculate modulation index mod_idx = float(*mp) / SHRT_MAX * float(_delay_length / 2); // calculate an index with modulation as a float(!!!) -#ifdef INTERPOLATE +#ifdef INTERPOLATE_MODE // get x/y values around mod_idx uint8_t c = 0; int16_t c_mod_idx = int(mod_idx + 0.5) + _circ_idx; - int32_t avg=0; for (j = INTERPOLATION_WINDOW_SIZE / -2; j <= INTERPOLATION_WINDOW_SIZE / 2; j++) { - int16_t jc_mod_idx = (c_mod_idx + j) % _delay_length - 1; + int16_t jc_mod_idx = (c_mod_idx + j) % (_delay_length - 1); if (jc_mod_idx < 0) y[c] = float(_delayline[_delay_length - 1 + jc_mod_idx]); else y[c] = float(_delayline[jc_mod_idx]); x[c] = float(c); - avg += y[c]; c++; // because 42 is the answer! ;-) } - //*bp = int(s.value(mod_idx - int(mod_idx + 0.5)) + 0.5); - *bp = avg / INTERPOLATION_WINDOW_SIZE; + *bp = int(s.value(mod_idx - int(mod_idx + 0.5)) + 0.5); #else // No interpolation - should sound really bad... - int16_t c_mod_idx = (int(mod_idx + 0.5) + _circ_idx) % _delay_length - 1; + int16_t c_mod_idx = (int(mod_idx + 0.5) + _circ_idx) % (_delay_length - 1); if (c_mod_idx < 0) *bp = _delayline[_delay_length - 1 + c_mod_idx]; else diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index 2940e26..54803a0 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -35,8 +35,6 @@ // 140219 - correct storage class (not static) // 190527 - added modulation input handling (by Holger Wirtz) -#define CHORUS_DELAY_PASSTHRU -1 - class AudioEffectModulatedDelay : public AudioStream { @@ -50,8 +48,6 @@ class AudioEffectModulatedDelay : virtual void setDelay(float milliseconds); private: - void _spline_interpolation(float* x, float* a, uint8_t n); - int16_t interpolate(int16_t x1, int16_t y1, int16_t x2, int16_t y2); audio_block_t *inputQueueArray[2]; int16_t *_delayline; int16_t _circ_idx; diff --git a/mdaEPiano.cpp b/mdaEPiano.cpp index 91d2740..b966250 100644 --- a/mdaEPiano.cpp +++ b/mdaEPiano.cpp @@ -253,7 +253,7 @@ void mdaEPiano::setOverdrive(float value) void mdaEPiano::setLoudness(float value) { //volume = value * 0.32258; // 0.00002 * 127^2 - volume = value * 0.2f; + volume = value * 0.18f; } void mdaEPiano::setParameter(int32_t index, float value)