From 4a1ed44e75d5a9c670d3d036c1e86317e6ddbc91 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sat, 26 Jan 2019 11:03:23 +0100 Subject: [PATCH] Works but with a clicking sound in the background. --- MicroMDAEPiano.ino | 45 ++++++++++++----------------- mod-delay-gain.cpp => mod-delay.cpp | 35 +++++----------------- mod-delay-gain.h => mod-delay.h | 14 ++++----- 3 files changed, 31 insertions(+), 63 deletions(-) rename mod-delay-gain.cpp => mod-delay.cpp (81%) rename mod-delay-gain.h => mod-delay.h (90%) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index f2027ee..3f4af8b 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -28,7 +28,7 @@ #include #include #include -#include "mod-delay-gain.h" +#include "mod-delay.h" #include "mdaEPiano.h" #ifdef USE_XFADE_DATA #include "mdaEPianoDataXfade.h" @@ -46,7 +46,6 @@ #include "LiquidCrystalPlus_I2C.h" #include "UI.h" - //************************************************************************************************* //* GLOBAL VARIABLES //************************************************************************************************* @@ -61,11 +60,9 @@ AudioEffectFreeverb freeverb_l; AudioMixer4 mixer_r; AudioMixer4 mixer_l; AudioSynthWaveform delaySweep_r; -AudioSynthWaveform envelope_r; AudioSynthWaveform delaySweep_l; -AudioSynthWaveform envelope_l; -AudioEffectModDelayGain modulatedDelay_r; -AudioEffectModDelayGain modulatedDelay_l; +AudioEffectModDelay modulatedDelay_r; +AudioEffectModDelay modulatedDelay_l; AudioConnection patchCord0(queue_r, peak_r); AudioConnection patchCord1(queue_l, peak_l); AudioConnection patchCord4(queue_r, freeverb_r); @@ -80,8 +77,6 @@ AudioConnection patchCord12(modulatedDelay_r, 0, mixer_r, 2); AudioConnection patchCord13(modulatedDelay_l, 0, mixer_l, 2); AudioConnection patchCord14(delaySweep_r, 0, modulatedDelay_r, 1); AudioConnection patchCord15(delaySweep_l, 0, modulatedDelay_l, 1); -AudioConnection patchCord16(envelope_r, 0, modulatedDelay_r, 2); -AudioConnection patchCord17(envelope_l, 0, modulatedDelay_l, 2); #ifdef TEENSY_AUDIO_BOARD AudioOutputI2S i2s1; AudioConnection patchCord18(mixer_r, 0, i2s1, 0); @@ -97,10 +92,6 @@ AudioConnection patchCord20(volume_r, 0, pt8211_1, 1); AudioConnection patchCord21(volume_l, 0, pt8211_1, 0); #endif -const int32_t delayBufferLength = 4500; -int16_t delayBuf1[delayBufferLength]; -int16_t delayBuf2[delayBufferLength]; - // Objects mdaEPiano* ep; @@ -132,10 +123,13 @@ const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLE #ifdef SHOW_CPU_LOAD_MSEC elapsedMillis cpu_mem_millis; #endif -float modFreq = 2.0; -enum MDA_EP_PARAM { DECAY, RELEASE, HARDNESS, TREBLE, PAN_TREM, LFO_RATE, VELOCITY_SENSE, STEREO, MAX_POLY, TUNE, DETUNE, OVERDRIVE }; +const int32_t delayBufferLength = 1000; +int16_t delayBuf_r[delayBufferLength]; +int16_t delayBuf_l[delayBufferLength]; +float modFreq = 0.7; +enum MDA_EP_PARAM { DECAY, RELEASE, HARDNESS, TREBLE, PAN_TREM, LFO_RATE, VELOCITY_SENSE, STEREO, MAX_POLY, TUNE, DETUNE, OVERDRIVE }; //************************************************************************************************* //* SETUP FUNCTION @@ -204,7 +198,7 @@ void setup() // start audio card AudioNoInterrupts(); - + AudioMemory(AUDIO_MEM); #ifdef TEENSY_AUDIO_BOARD @@ -246,17 +240,16 @@ void setup() freeverb_r.damping(0.5); freeverb_l.damping(0.5); - delaySweep_r.begin(1, modFreq, WAVEFORM_SINE); - delaySweep_l.begin(1, modFreq, WAVEFORM_SINE); - delaySweep_l.phase(180.0); - envelope_r.begin(1, modFreq, WAVEFORM_SINE); - envelope_l.begin(1, modFreq, WAVEFORM_SINE); - envelope_l.phase(180.0); - - mixer_r.gain(0, 0.7); - mixer_l.gain(0, 0.7); - mixer_r.gain(1, 0.3); - mixer_l.gain(1, 0.3); + modulatedDelay_r.setbuf(delayBufferLength, delayBuf_r); + modulatedDelay_l.setbuf(delayBufferLength, delayBuf_l); + delaySweep_r.begin(0.1, modFreq, WAVEFORM_SINE); + delaySweep_l.begin(0.1, modFreq, WAVEFORM_SINE); + //delaySweep_l.phase(180.0); + + 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.5); mixer_l.gain(2, 0.5); diff --git a/mod-delay-gain.cpp b/mod-delay.cpp similarity index 81% rename from mod-delay-gain.cpp rename to mod-delay.cpp index 15be65b..8368e8f 100644 --- a/mod-delay-gain.cpp +++ b/mod-delay.cpp @@ -36,18 +36,16 @@ */ - -#include "mod-delay-gain.h" +#include "mod-delay.h" #define INTERPOLATE (1) -void AudioEffectModDelayGain::update(void) +void AudioEffectModDelay::update(void) { - audio_block_t *audioblock, *controlblockDelay, *controlblockGain; - int16_t *data, *end, *ctrlDelay, *ctrlGain; + audio_block_t *audioblock, *controlblockDelay; + int16_t *data, *end, *ctrlDelay; int32_t extract_index; - int32_t temp; #ifdef INTERPOLATE int32_t interp_delta; @@ -67,20 +65,11 @@ void AudioEffectModDelayGain::update(void) return; } - controlblockGain = receiveReadOnly(2); - if (!controlblockGain) { - release(audioblock); - release(controlblockDelay); - return; - } - data = audioblock->data; end = audioblock->data + AUDIO_BLOCK_SAMPLES; ctrlDelay = controlblockDelay->data; - ctrlGain = controlblockGain->data; - do { delayline_p[insert_index] = *data; @@ -91,9 +80,8 @@ void AudioEffectModDelayGain::update(void) } #ifdef INTERPOLATE - // interp_delta = (buffer_length * (*ctrlDelay)); - delay_delta = interp_delta >> 15; // MSB's for delay len + delay_delta = (interp_delta >> 15); // MSB's for delay len interp_delta &= 0x7fff; //LSBs for interp distance #else delay_delta = (buffer_length * (*ctrlDelay)) >> 15; @@ -115,27 +103,18 @@ void AudioEffectModDelayGain::update(void) } calc = delayline_p[next] - delayline_p[extract_index]; - calc = (calc * interp_delta ) >> 15; calc += delayline_p[extract_index]; - //*data = calc; - temp = (int32_t)calc * (*ctrlGain); - *data = temp >> 15; + *data = calc; #else - //data = delayline_p[extract_index]; - temp = (int32_t)delayline_p[extract_index] * (*ctrlGain); - *data = temp >> 15; + *data = delayline_p[extract_index]; #endif data++; ctrlDelay++; - ctrlGain++; } while (data < end); transmit(audioblock); release(audioblock); release(controlblockDelay); - release(controlblockGain); } - - diff --git a/mod-delay-gain.h b/mod-delay.h similarity index 90% rename from mod-delay-gain.h rename to mod-delay.h index 8bf474e..207c2f0 100644 --- a/mod-delay-gain.h +++ b/mod-delay.h @@ -43,14 +43,13 @@ #ifndef _mod_delay_h_ #define _mod_delay_h_ - #include "AudioStream.h" #include -class AudioEffectModDelayGain: public AudioStream +class AudioEffectModDelay: public AudioStream { public: - AudioEffectModDelayGain (void) : AudioStream(3, inputQueueArray) + AudioEffectModDelay (void) : AudioStream(2, inputQueueArray) { buffer_length = 0; } @@ -64,10 +63,7 @@ class AudioEffectModDelayGain: public AudioStream insert_index = 0; buffer_length = delay_len; - for (int32_t i = 0; i < buffer_length; i++) - { - delayline_p[i] = 0; - } + memset(delayline_p, 0, buffer_length); }; void inspect(void) @@ -81,7 +77,7 @@ class AudioEffectModDelayGain: public AudioStream }; private: - audio_block_t *inputQueueArray[3]; + audio_block_t *inputQueueArray[2]; int16_t *delayline_p; @@ -90,4 +86,4 @@ class AudioEffectModDelayGain: public AudioStream int32_t delay_delta; }; -#endif +#endif