From 30267eb805a9e105b9efcd62a93c9199993dea38 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 6 Jun 2019 14:48:14 +0200 Subject: [PATCH] Added inverter for second modulated delay as stereo chorus simulation. --- MicroMDAEPiano.ino | 51 +++++++++++++++++++------------------- config.h | 2 +- effect_modulated_delay.cpp | 2 +- effect_modulated_delay.h | 4 +-- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index b30c4d4..0cc1605 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -53,6 +53,7 @@ AudioMixer4 mixer_r; AudioMixer4 mixer_l; AudioAmplifier volume_r; AudioAmplifier volume_l; +AudioAmplifier inverter; AudioEffectModulatedDelay modchorus_r; AudioEffectModulatedDelay modchorus_l; AudioSynthWaveform modulator; @@ -63,24 +64,25 @@ AudioConnection patchCord3(queue_l, freeverb_l); AudioConnection patchCord4(queue_r, 0, modchorus_r, 0); AudioConnection patchCord5(queue_l, 0, modchorus_l, 0); AudioConnection patchCord6(modulator, 0, modchorus_r, 1); -AudioConnection patchCord7(modulator, 0, modchorus_l, 1); -AudioConnection patchCord8(queue_r, 0, mixer_r, 0); -AudioConnection patchCord9(queue_l, 0, mixer_l, 0); -AudioConnection patchCord10(modchorus_r, 0, mixer_r, 2); -AudioConnection patchCord11(modchorus_l, 0, mixer_l, 2); -AudioConnection patchCord12(freeverb_r, 0, mixer_r, 1); -AudioConnection patchCord13(freeverb_l, 0, mixer_l, 1); -AudioConnection patchCord14(mixer_r, volume_r); -AudioConnection patchCord15(mixer_l, volume_l); +AudioConnection patchCord7(modulator, inverter); +AudioConnection patchCord8(inverter, 0, modchorus_l, 1); +AudioConnection patchCord9(queue_r, 0, mixer_r, 0); +AudioConnection patchCord10(queue_l, 0, mixer_l, 0); +AudioConnection patchCord11(modchorus_r, 0, mixer_r, 2); +AudioConnection patchCord12(modchorus_l, 0, mixer_l, 2); +AudioConnection patchCord13(freeverb_r, 0, mixer_r, 1); +AudioConnection patchCord14(freeverb_l, 0, mixer_l, 1); +AudioConnection patchCord15(mixer_r, volume_r); +AudioConnection patchCord16(mixer_l, volume_l); #if defined(TEENSY_AUDIO_BOARD) AudioOutputI2S i2s1; -AudioConnection patchCord16(volume_r, 0, i2s1, 0); -AudioConnection patchCord17(volume_l, 0, i2s1, 1); +AudioConnection patchCord17(volume_r, 0, i2s1, 0); +AudioConnection patchCord18(volume_l, 0, i2s1, 1); AudioControlSGTL5000 sgtl5000_1; #elif defined(TGA_AUDIO_BOARD) AudioOutputI2S i2s1; -AudioConnection patchCord16(volume_r, 0, i2s1, 1); -AudioConnection patchCord17(volume_l, 0, i2s1, 0); +AudioConnection patchCord17(volume_r, 0, i2s1, 1); +AudioConnection patchCord18(volume_l, 0, i2s1, 0); AudioControlWM8731master wm8731_1; #else AudioOutputPT8211 pt8211_1; @@ -153,8 +155,8 @@ elapsedMillis cpu_mem_millis; #endif // Allocate the delay lines for left and right channels -short l_delayline[CHORUS_DELAY_LENGTH_BYTES]; -short r_delayline[CHORUS_DELAY_LENGTH_BYTES]; +short l_delayline[CHORUS_DELAY_LENGTH_SAMPLES]; +short r_delayline[CHORUS_DELAY_LENGTH_SAMPLES]; //************************************************************************************************* //* SETUP FUNCTION @@ -226,11 +228,11 @@ void setup() Serial.print(audio_block_time_us); Serial.println(F("us)")); - if (!modchorus_r.begin(r_delayline, CHORUS_DELAY_LENGTH_BYTES)) { + if (!modchorus_r.begin(r_delayline, CHORUS_DELAY_LENGTH_SAMPLES)) { Serial.println(F("AudioEffectModulatedDelay - right channel begin failed")); while (1); } - if (!modchorus_l.begin(l_delayline, CHORUS_DELAY_LENGTH_BYTES)) { + if (!modchorus_l.begin(l_delayline, CHORUS_DELAY_LENGTH_SAMPLES)) { Serial.println(F("AudioEffectModulatedDelay - left channel begin failed")); while (1); } @@ -241,16 +243,15 @@ void setup() modulator.frequency(1.0); modulator.phase(0); modulator.offset(0.0); + 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, 1.0); - //mixer_l.gain(0, 1.0); - mixer_r.gain(0, 0.0); - mixer_l.gain(0, 0.0); - mixer_r.gain(1, 0.0); - mixer_l.gain(1, 0.0); - mixer_r.gain(2, 1.0); - mixer_l.gain(2, 1.0); + mixer_r.gain(0, 1.0); + mixer_l.gain(0, 1.0); + mixer_r.gain(1, 0.5); + mixer_l.gain(1, 0.5); + mixer_r.gain(2, 0.5); + mixer_l.gain(2, 0.5); // set master volume set_master_volume(master_volume); diff --git a/config.h b/config.h index 3fd7f42..312f54e 100644 --- a/config.h +++ b/config.h @@ -64,7 +64,7 @@ #define INTERPOLATION_WINDOW_SIZE 7 // use only odd numbers!!! #define INTERPOLATE QUADRATIC // LINEAR QUADRATIC COSINE CUBIC LAGRANGE #define CHORUS_WAVEFORM WAVEFORM_SINE // WAVEFORM_SINE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE WAVEFORM_SQUARE WAVEFORM_TRIANGLE -#define CHORUS_DELAY_LENGTH_BYTES (16*AUDIO_BLOCK_SAMPLES) +#define CHORUS_DELAY_LENGTH_SAMPLES (16*AUDIO_BLOCK_SAMPLES) //************************************************************************************************* //* DEBUG OUTPUT SETTINGS diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 284b984..d2b44dd 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -30,7 +30,7 @@ /******************************************************************/ -// Based on; A u d i o E f f e c t C h o r u s +// Based on; A u d i o E f f e c t D e l a y // Written by Pete (El Supremo) Jan 2014 // 140529 - change to handle mono stream - change modify() to voices() // 140219 - correct storage class (not static) diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index aac2736..833444d 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -27,9 +27,9 @@ #include "Arduino.h" #include "AudioStream.h" -/******************************************************************/ +/*************************************************************************/ -// A u d i o E f f e c t C h o r u s +// A u d i o E f f e c t M o d u l a t e d D e l a y // Written by Pete (El Supremo) Jan 2014 // 140219 - correct storage class (not static) // 190527 - added modulation input handling (by Holger Wirtz)