Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 7:c84086dce9ac
- Parent:
- 6:df635006ee1c
- Child:
- 8:ef4dca8695d1
--- a/main.cpp Sat Jul 30 20:02:42 2016 +0000
+++ b/main.cpp Sat Jul 30 21:34:28 2016 +0000
@@ -14,8 +14,8 @@
//Cubic interpolation might be a possibility if I can figure out how it works.
//Added a nice lowpass filter class. Might want to put the delay in a class like this for reverb work. Need to make an oscillator next.
-#define DELAYLEN 3900 //24,000 is about as far as you can go in the ram.
-#define SAMPLINGFREQ 29 //roughly the smapling frequency in KHz. options are 22,29,44,88 for 22khz,29khz,etc..
+#define DELAYLEN 2900 //24,000 is about as far as you can go in the ram.
+#define SAMPLINGFREQ 44 //roughly the smapling frequency in KHz. options are 22,29,44,88 for 22khz,29khz,etc..
#include "mbed.h"
#include "dsp.h"
@@ -34,30 +34,33 @@
index1 = 0, index2 = (DELAYLEN*0.99), index3 = (DELAYLEN*0.99);
uint16_t left_in_u = 0, meas = 0, measprev = 0;
float left_in_f = 0, feedback = 0, feedback2 = 0, feedback3 = 0, offset = 10.0,
-meas2f = 0.5, measf = 0, measf2 = 0, measf3 = 0, measf3L = 0, measf3L2 = 0, measf3L3 = 0, measf3R = 0, measf3R2 = 0, measf3R3 = 0,
+meas2f = 0.5, damping = 0, damping2 = 0, damping3 = 0, modL = 0, modL2 = 0, modL3 = 0, modL4, modR = 0, modR2 = 0, modR3 = 0, modR4,
left_out_f = 0, right_out_f = 0;
-float left_out_2 = 0, right_out_2 = 0, left_out_3 = 0, right_out_3 = 0, loopfb = 0, loopfb2 = 0;
+float left_out_2 = 0, right_out_2 = 0, left_out_3 = 0, right_out_3 = 0, left_out_4 = 0, right_out_4 = 0, loopfb = 0, loopfb2 = 0;
float audioFeedbackRight,audioFeedbackLeft;
float LPdampingFreq = 11000, HPdampingFreq = 100; //some parameters you might want to adjust.
int LPdampingPoles = 2, HPdampingPoles = 0; //I don't think the highpass is quite working.
-OnePoleLp audioFilter; //might use this as a mor thorough DC offset removal tool. Not yet implemented.
-OnePoleHp audioFilterHP;
OnePoleLp feedbackFilter;
OnePoleLp lengthFilter;
+OnePoleLp dampingFilter;
AllPass delayLeft;
AllPass delayLeft2;
AllPass delayLeft3;
+AllPass delayLeft4;
AllPass delayRight;
AllPass delayRight2;
AllPass delayRight3;
+AllPass delayRight4;
gsOsc OscillatorL;
gsOsc OscillatorL2;
gsOsc OscillatorL3;
+gsOsc OscillatorL4;
gsOsc OscillatorR;
gsOsc OscillatorR2;
gsOsc OscillatorR3;
+gsOsc OscillatorR4;
void I2S_send(void){
cs.write(0); //0 for left output
@@ -73,53 +76,75 @@
feedback2 = feedbackFilter.process(feedback);
feedback3 = feedbackFilter.process(feedback2);
//update delay times with every audio sample if you're going to filter them.
- measf2 = lengthFilter.process(measf);
- measf3 = lengthFilter.process(measf2);
- measf3 *= (DELAYLEN); //convert to delay index normalization
+ damping2 = lengthFilter.process(damping);
+ damping3 = lengthFilter.process(damping2);
+ damping3 *= (5000); //make about 10k the max cutoff for damping
+
+
+ dampingFilter.setFc(damping3);
//process audio. probably calculate these coefficients elsewhere so you don't do the multiply all the time.
//left delay mod
- measf3L = DELAYLEN*.74 + OscillatorL.process(.23,DELAYLEN/76,1);
- measf3L2 = DELAYLEN*.43 + OscillatorL2.process(.05,DELAYLEN/75,1);
- measf3L3 = DELAYLEN*.23 + OscillatorL3.process(.03,DELAYLEN/78,1);
+ modL = DELAYLEN*.74 + OscillatorL.process(.53,DELAYLEN/66,1);
+ modL2 = DELAYLEN*.43 + OscillatorL2.process(.03,DELAYLEN/65,1);
+ modL3 = DELAYLEN*.33 + OscillatorL3.process(.02,DELAYLEN/78,1);
+ modL3 = DELAYLEN*.37 + OscillatorL3.process(.023,DELAYLEN/78,0);
//right delay mod
- measf3R = DELAYLEN*.75 + OscillatorR.process(.21,DELAYLEN/79,0);
- measf3R2 = DELAYLEN*.49 + OscillatorR2.process(.05,DELAYLEN/77,0);
- measf3R3 = DELAYLEN*.23 + OscillatorR3.process(.02,DELAYLEN/78,1);
- if(measf3L > DELAYLEN*.9)
- measf3L = DELAYLEN*.9;
- if(measf3L < DELAYLEN*.05)
- measf3L = DELAYLEN*.05;
- if(measf3L2 > DELAYLEN*.9)
- measf3L2 = DELAYLEN*.9;
- if(measf3L2 < DELAYLEN*.05)
- measf3L2 = DELAYLEN*.05;
- if(measf3L3 > DELAYLEN*.9)
- measf3L3 = DELAYLEN*.9;
- if(measf3L3 < DELAYLEN*.05)
- measf3L3 = DELAYLEN*.05;
- if(measf3R > DELAYLEN*.9)
- measf3R = DELAYLEN*.9;
- if(measf3R < DELAYLEN*.05)
- measf3R = DELAYLEN*.05;
- if(measf3R2 > DELAYLEN*.9)
- measf3R2 = DELAYLEN*.9;
- if(measf3R2 < DELAYLEN*.05)
- measf3R2 = DELAYLEN*.05;
- if(measf3R3 > DELAYLEN*.9)
- measf3R3 = DELAYLEN*.9;
- if(measf3R3 < DELAYLEN*.05)
- measf3R3 = DELAYLEN*.05;
- left_out_2 = delayLeft2.process(satSubtract(left_in_f,loopfb),.3,measf3L);
- left_out_3 = delayLeft3.process(left_out_2,.4,measf3L2);
- left_out_f = delayLeft.process(left_out_3,.4,measf3L3);
- right_out_2 = delayRight2.process(satSubtract(left_in_f,loopfb2),.3,measf3R);
- right_out_3 = delayRight3.process(right_out_2,.4,measf3R2);
- right_out_f = delayRight.process(right_out_3,.4,measf3R3);
- loopfb = left_out_f*feedback3;
- loopfb2 = right_out_f*feedback3;
- //left_out_u = satAdd(left_in_f,left_out_f*measf3/200);
- //right_out_u = satAdd(left_in_f,right_out_f*measf3/200);
+ modR = DELAYLEN*.75 + OscillatorR.process(.51,DELAYLEN/69,0);
+ modR2 = DELAYLEN*.49 + OscillatorR2.process(.03,DELAYLEN/67,0);
+ modR3 = DELAYLEN*.33 + OscillatorR3.process(.02,DELAYLEN/78,1);
+ modR4 = DELAYLEN*.37 + OscillatorR4.process(.023,DELAYLEN/78,1);
+ if(modL > DELAYLEN*.9)
+ modL = DELAYLEN*.9;
+ if(modL < DELAYLEN*.05)
+ modL = DELAYLEN*.05;
+ if(modL2 > DELAYLEN*.9)
+ modL2 = DELAYLEN*.9;
+ if(modL2 < DELAYLEN*.05)
+ modL2 = DELAYLEN*.05;
+ if(modL3 > DELAYLEN*.9)
+ modL3 = DELAYLEN*.9;
+ if(modL3 < DELAYLEN*.05)
+ modL3 = DELAYLEN*.05;
+ if(modL4 > DELAYLEN*.9)
+ modL4 = DELAYLEN*.9;
+ if(modL4 < DELAYLEN*.05)
+ modL4 = DELAYLEN*.05;
+ if(modR > DELAYLEN*.9)
+ modR = DELAYLEN*.9;
+ if(modR < DELAYLEN*.05)
+ modR = DELAYLEN*.05;
+ if(modR2 > DELAYLEN*.9)
+ modR2 = DELAYLEN*.9;
+ if(modR2 < DELAYLEN*.05)
+ modR2 = DELAYLEN*.05;
+ if(modR3 > DELAYLEN*.9)
+ modR3 = DELAYLEN*.9;
+ if(modR3 < DELAYLEN*.05)
+ modR3 = DELAYLEN*.05;
+ if(modR4 > DELAYLEN*.9)
+ modR4 = DELAYLEN*.9;
+ if(modR4 < DELAYLEN*.05)
+ modR4 = DELAYLEN*.05;
+ left_out_2 = delayLeft2.process(satAdd(left_in_f,loopfb),.3,modL);
+ left_out_3 = delayLeft3.process(left_out_2,.4,modL2);
+ left_out_4 = delayLeft4.process(left_out_3,.4,modL3);
+ left_out_f = delayLeft.process(left_out_4,.4,modL4);
+ right_out_2 = delayRight2.process(satAdd(left_in_f,loopfb2),.3,modR);
+ right_out_3 = delayRight3.process(right_out_2,.4,modR2);
+ right_out_4 = delayRight4.process(right_out_3,.4,modR3);
+ right_out_f = delayRight.process(right_out_4,.4,modR4);
+ //loopfb = dampingFilter.process(left_out_f);
+ //loopfb2 = dampingFilter.process(right_out_f);
+
+ //loopfb *= feedback3;
+ //loopfb2 *= feedback3;
+ loopfb2 = left_out_f*feedback3; //swizzle the feedbacks left to right
+ loopfb = right_out_f*feedback3;
+ //loopfb = dampingFilter.process(loopfb);
+ //loopfb2 = dampingFilter.process(loopfb2);
+ //left_out_u = satAdd(left_in_f,left_out_f*damping3/200);
+ //right_out_u = satAdd(left_in_f,right_out_f*damping3/200);
left_out_u = left_out_f;
right_out_u = right_out_f;
@@ -134,14 +159,15 @@
//this is the stuff for the feedback amount pot
meas2f = analog_value2.read_u16(); //converts unint16 value to float
feedback = meas2f/4100; //now you have a value between 0 and 1 that will control the feedback amount.
+ feedback *= feedback;
//this is the stuff for the delay time pot
meas = 4096 - analog_value.read_u16(); //values go from 1 to 4095
//if(abs(meas - measprev) > 5){
measprev = meas;
- measf = meas;
- measf /= 4200; //this number took some tweaking.
- measf *= measf;
+ damping = meas;
+ damping /= 4200; //this number took some tweaking.
+ damping *= damping;
//}
}
@@ -159,12 +185,6 @@
feedbackFilter.setFc(feedbackCutoff);
double lengthCutoff = 3.0/(SAMPLINGFREQ*1000);
lengthFilter.setFc(lengthCutoff);
-
- //initialize audio filter
- double audioCutoff = LPdampingFreq/(SAMPLINGFREQ*1000); //adjust these cutoffs according to taste.
- audioFilter.setFc(audioCutoff);
- audioCutoff = HPdampingFreq/(SAMPLINGFREQ*1000); //adjust these cutoffs according to taste.
- audioFilterHP.setFc(audioCutoff);
//set up I2S
spi.frequency(8e6*2); //8MHz spi. This is fast enough for 88KHz 16 bit sampling.