20 and more effetcts pedal shield

7 years 3 months ago - 7 years 3 months ago #678 by freddylamenace
Hi,

I put a more than 20 effects (thanks everybody for your contributions) - some are not complet :


int in_ADC0, in_ADC1; //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, POT2,POT3, out_DAC0, out_DAC1; //variables for 4 pots (ADC8, ADC9, ADC10)
int LED = 3;
int FOOTSWITCH = 7;
int TOGGLE = 2;

int toggle_value = 0;
int effect=0;

int upper_threshold, lower_threshold;
uint16_t sDelayBuffer0[45000];
unsigned int DelayCounter = 0;
unsigned int Delay_Depth = 300;
unsigned int count_up=1;
int p;
uint16_t nSine;

int counter = 0,interval = 0;
unsigned int triangle = 0,trianglecounter = 0;
boolean countup=true;
unsigned int lfo_speed =0,lfo_depth = 0;

float DELAY[102] = {0};
int delay_int = 0,j=0,Delay2 = 0;
float delay_sr = 0,frac = 0;

//Low pass butterworth filter order=5 alpha1=0.125

class filter
{
public:
filter()
{
for(int i=0; i <= 5; i++) v=0;
}
private:
short v[6];
public:
short step(short x)
{
v[0] = v[1];
v[1] = v[2];
v[2] = v[3];
v[3] = v[4];
v[4] = v[5];
//12000 kHz cutoff
long tmp = ((((x * 220064L) >> 10) //= ( 3.2792163064e-3 * x)
+ ((v[0] * 151657L) >> 5) //+( 0.0723156691*v[0])
+ ((v[1] * -142720L) >> 2) //+( -0.5444326949*v[1])
+ ((v[2] * 223317L) >> 1) //+( 1.7037722409*v[2])
+ (v[3] * -184222L) //+( -2.8110063119*v[3])
+ (v[4] * 162163L) //+( 2.4744161750*v[4])
)+32768) >> 16; // round and downshift fixed point /65536
v[5]= (short)tmp;

return (short)((/* xpart *//*1.000000 1.000000 */
(((v[0] + v[5]))<<11) /* 131072L (^2)*/ // (v[0] + v[5])/*5.000000 5.000000 */
+ ((163840L * (v[1] + v[4]))>>1) // + 5 * (v[1] + v[4])/*10.000000 10.000000 */
/* xi==xj*/+ (163840L * (v[2] + v[3])) // + 10 * (v[2] + v[3])
)
+8192) >> 14; // round and downshift fixed point
}
};

unsigned int write_pt=0;
unsigned int read_pt=0, ADCMidPoint0, ADCMidPoint1;
int volatile ratio, cent, skip, divider=0;
float tmp;
const float bit_pow = pow(2, 10);

filter Butterworth0 ; //, Butterworth1; Not needed since filtering both ADC0 and ADC1 results in silence for unknown reasons

unsigned int Delay_Depth_echo, Delay = 0, a = 0;

int x_0=0, d_0=0, x_1=0, d_1=0,jj=0;
long f_0=0,f_1=0;

float threshold = 0.33333 ;

double in_0 = 0;
double in_1 = 0;

int memory, sustain;

unsigned int read_pt_A=0, read_pt_B= 5000;
unsigned int increment, dividoctave=0, buffer0, buffer1;

unsigned int DelayCounter_A = 0;
unsigned int DelayCounter_B = 20500;
unsigned int Delay_Depth_A, Delay_Depth_B;

float S,S1=0;
int DC1 = 1, DC2 = 278, DC3 = 873, DC4 = 1832, DC5 = 3033, DC6 = 3033, DC7= 4584, DC8 = 4584;

int sample, accumulator, count, LFO;


void setup()
{
/* turn on the timer clock in the power management controller */
pmc_set_writeprotect(false);
pmc_enable_periph_clk(ID_TC4);
/* we want wavesel 01 with RC */
TC_Configure(/* clock */TC1,/* channel */1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC
| TC_CMR_TCCLKS_TIMER_CLOCK2);
TC_SetRC(TC1, 1, 238); // sets <> 44.1 Khz interrupt rate
//TC_SetRC(TC1, 1, 109); // sets <> 96 Khz interrupt rate
TC_Start(TC1, 1);
// enable timer interrupts on the timer
TC1->TC_CHANNEL[1].TC_IER=TC_IER_CPCS;
TC1->TC_CHANNEL[1].TC_IDR=~TC_IER_CPCS;
/* Enable the interrupt in the nested vector interrupt controller */
/* TC4_IRQn where 4 is the timer number * timer channels (3) + the channel number
(=(1*3)+1) for timer1 channel1 */
NVIC_EnableIRQ(TC4_IRQn);
//ADC Configuration
ADC->ADC_MR |= 0x80; // DAC in free running mode.
ADC->ADC_CR=2; // Starts ADC conversion.
ADC->ADC_CHER=0x3CC0; // Enable ADC channels 0 and 1.
//DAC Configuration
analogWrite(DAC0,0); // Enables DAC0
analogWrite(DAC1,0); // Enables DAC0
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(LED, OUTPUT);
pinMode(TOGGLE, INPUT_PULLUP);
attachInterrupt(TOGGLE, switch_handler, CHANGE);
pinMode(FOOTSWITCH, INPUT);
analogWrite(DAC0,0);
analogWrite(DAC1,0);
pinMode(LED, OUTPUT);
pinMode(TOGGLE, INPUT_PULLUP);
attachInterrupt(TOGGLE, switch_handler, CHANGE);
pinMode(FOOTSWITCH, INPUT);
delay(500);
ADCMidPoint0 = 2041;
ADCMidPoint1 = 2042;
}

void loop()
{
//Read the ADCs
while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0); // wait for ADC 0, 1, 8, 9, 10 conversion complete.
in_ADC0=ADC->ADC_CDR[7]; // read data from ADC0
in_ADC1=ADC->ADC_CDR[6]; // read data from ADC1
POT0=ADC->ADC_CDR[10]; // read data from ADC8
POT1=ADC->ADC_CDR[11]; // read data from ADC9
POT2=ADC->ADC_CDR[12]; // read data from ADC10
POT3=ADC->ADC_CDR[13]; // read data from ADC11

if ((millis() % 100) == 0 ){
cent = map(POT0,0,4095,-1200,1200);
ratio = pow(2,(10 + (cent/1200.0))); //10 bitshifts left = x * 2^10 = x * 1024. Also 2^x * 2^10 = 2^(x+10). Maybe we can shift some more (make the 10 a #define maybe?)
if (ratio > (0.99 * bit_pow) && ratio < (1.01 * bit_pow)){ //a bit of a deadzone seems smart
ratio = bit_pow;
}
//test code
if (ratio < bit_pow){ //Downshift
tmp = -1;
}
else if (ratio > bit_pow){
tmp = 1;
}
}
}

void TC4_Handler()
{
// We need to get the status to clear it and allow the interrupt to fire again
TC_GetStatus(TC1, 1);

if (effect==1) // REGLAGE
{
if (in_ADC0>=4090)
{
digitalWrite(LED, HIGH);
delay(200);
}
else
digitalWrite(LED, LOW);
out_DAC0=map(in_ADC0,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0);//write on DAC
}

else if (effect==2) //AUTO WAH
{

}

else if (effect==3) // BIT CRUSHER 1
{
lfo_speed = ADC->ADC_CDR[12];
counter++;
trianglecounter++;
if (lfo_depth > 5) {
if (trianglecounter >= map(lfo_speed, 0, 4095, 800, 1)) {
if (countup) {
triangle++;
}
else {
triangle--;
}
if (triangle >= 300) {
digitalWrite(LED, HIGH);
countup = !countup;
}
else if (triangle <= 0) {
digitalWrite(LED, LOW);
countup = !countup;
}
trianglecounter = 0;
}
interval = map(POT1, 0, 4095, 0, 300) + triangle/map(lfo_depth, 0, 4095, 100, 1);
}
else {
digitalWrite(LED, LOW);
interval = map(POT1, 0, 4095, 0, 300);
}
if (counter >= interval) {
out_DAC0 = in_ADC0<<map(POT0>>2,0,1024,0,12);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0);//write on DAC
counter=0;
}
}

else if (effect==4) // BIT CRUSHER 2
{
lfo_depth = ADC->ADC_CDR[12];
counter++;
trianglecounter++;
if (lfo_depth > 5) {
if (trianglecounter >= map(lfo_speed, 0, 4095, 800, 1)) {
if (countup) {
triangle++;
}
else {
triangle--;
}
if (triangle >= 300) {
digitalWrite(LED, HIGH);
countup = !countup;
}
else if (triangle <= 0) {
digitalWrite(LED, LOW);
countup = !countup;
}
trianglecounter = 0;
}
interval = map(POT1, 0, 4095, 0, 300) + triangle/map(lfo_depth, 0, 4095, 100, 1);
}
else {
digitalWrite(LED, LOW);
interval = map(POT1, 0, 4095, 0, 300);
}
if (counter >= interval) {
out_DAC0 = in_ADC0<<map(POT0>>2,0,1024,0,12);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0);//write on DAC
counter=0;
}
}

else if (effect==5) // CHORUS SINE
{
sDelayBuffer0[DelayCounter] = in_ADC0;
//Adjust Delay Depth based in pot0 position.
POT0=map(POT0>>2,0,1024,1,25); //25 empirically chosen
DelayCounter++;
if(DelayCounter >= Delay_Depth)
{
DelayCounter = 0;
if(count_up)
{
digitalWrite(LED, HIGH);
for(p=0;p<POT0+1;p++)
sDelayBuffer0[Delay_Depth+p]=sDelayBuffer0[Delay_Depth-1];
Delay_Depth=Delay_Depth+POT0;
if (Delay_Depth>=500)count_up=0;
}
else
{
digitalWrite(LED, LOW);
Delay_Depth=Delay_Depth-POT0;
if (Delay_Depth<=200)count_up=1;
}
}
out_DAC0 = sDelayBuffer0[DelayCounter];
//Add volume control based in POT2
out_DAC0=map(out_DAC0,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0); //write on DAC
}

else if (effect==6)// chorus dattoro
{
POT0=map(POT0>>2,0,1024,1,100); //empirical adjusts
//POT0 = 10;
Delay2 = POT0/2;
DELAY[0] = 0.7*in_ADC0 -0.7*DELAY[Delay2];
//if ( DELAY[0] <=0) DELAY[0] = 0;
for ( int u = 0; u <= POT0; u++)
DELAY[POT0+1-u] = DELAY[POT0-u];
POT1=map(POT1>>2,0,1024,1,4); // empirical adjusts
//POT1 = 1;
delay_sr = Delay2 - Delay2*(0.99 * cos(((2.0*PI)/16000)*j*POT1));
delay_int = int(delay_sr);
frac = delay_sr - delay_int;
if (frac <= 0) frac = 0.01; // Ajusts
if (frac >= 1) frac = 0.99; //
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
out_DAC0 = (DELAY[delay_int+1]*frac + DELAY[delay_int]*(1-frac));
if (out_DAC0 <=0 ) out_DAC0 = 0.01;
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0); //write on DAC
}
else if (effect==7) // compresseur expandeur
{
if (digitalRead(7)) digitalWrite(3, HIGH); else digitalWrite(3, LOW);
//compresion
out_DAC0=map(in_ADC0,0,4095,1,POT1);
out_DAC1=map(in_ADC1,0,4095,1,POT1);
//expansion
out_DAC0=map(out_DAC0,0,4095,1,POT2);
out_DAC1=map(out_DAC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
dacc_set_channel_selection(DACC_INTERFACE, 1);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);
}

else if (effect==8) //DELAI
{
//Store current readings
sDelayBuffer0[DelayCounter] = in_ADC0;
//Adjust Delay Depth based in pot0 position.
Delay_Depth=map(POT0>>2,0,1023,1,15000)+ map(POT1>>2,0,1023,1,31000);
//Increase/reset delay counter.
DelayCounter++;
if(DelayCounter >= Delay_Depth) DelayCounter = 0;
out_DAC0 = ((sDelayBuffer0[DelayCounter]));
//Add volume feature based in pot2 position.
out_DAC0=map(out_DAC0,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0); //write on DAC
}

else if (effect==9) //DETUNE1
{
//Replace all instances of sDelayBuffer0 and sDelayBuffer1 with local vars to gain execution speed (hopefully)
int Buffer0, Buffer1;
//Store current readings our Butterworth filter expects ints not unsigned ints so - 2048
//(A) We take the signal from both ADCs to increase amplitude resolution
Buffer0 = (in_ADC0 - ADCMidPoint0);
//Adjust Delay Depth based in pot2 position. If this were a Delay ;)
Delay_Depth = 4999;
//Flush local vars to global array
sDelayBuffer0[write_pt] = Buffer0;
//Increase/reset delay counter.
write_pt++;
if(write_pt >= Delay_Depth) write_pt = 0;
Buffer0 = sDelayBuffer0[read_pt];
//Calculate Butterworth for Buffer 0
Buffer0 = Butterworth0.step(Buffer0);
out_DAC0 = constrain(Buffer0 + ADCMidPoint0,0,4095);
//Flush local vars to global array
sDelayBuffer0[read_pt] = Buffer0;
if (ratio == bit_pow){ //Unity
read_pt = read_pt + 1;
divider = 0;
}
else if (ratio < bit_pow){ //Downshift
if (divider > ((-1200 << 10) / 1200)){
read_pt = read_pt + 1;
divider = divider + (tmp * (bit_pow - ratio)); // tmp replaces (-1200 / 1200)
}
else {
divider = divider - (tmp * ratio); // tmp replaces (-1200 / 1200)
}
}
else if (ratio > bit_pow){ //Upshift
read_pt = read_pt + 1 + (divider >> 10);
if (divider < ((1200 << 10) / 1200)) {
divider = divider + (tmp * (ratio - bit_pow)); // tmp replaces (1200 / 1200)
}
else {
divider = divider - (tmp * (bit_pow - (ratio - bit_pow))); // tmp replaces (1200 / 1200)
}
}
if(read_pt >= Delay_Depth) read_pt = 0;
//Add volume control with POT2
out_DAC0=map(out_DAC0,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0);//write on DAC
}

else if (effect==10) //DISTORSION
{
upper_threshold=map(POT0,0,4095,4095,2047);
lower_threshold=map(POT1,0,4095,0000,2047);
if(in_ADC0>=upper_threshold) in_ADC0=upper_threshold;
else if(in_ADC0<lower_threshold) in_ADC0=lower_threshold;
if(in_ADC1>=upper_threshold) in_ADC1=upper_threshold;
else if(in_ADC1<lower_threshold) in_ADC1=lower_threshold;
//adjust the volume with POT2
out_DAC0=map(in_ADC0,0,4095,1,POT2);
out_DAC1=map(in_ADC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
}

else if (effect==11) //ECHO
{
sDelayBuffer0[DelayCounter] = (in_ADC0 + (sDelayBuffer0[DelayCounter]))>>1;
//Adjust Delay Depth based in pot0 position.
Delay_Depth =map(POT0>>2,0,2047,1,40000);
//Increse/reset delay counter.
DelayCounter++;
if(DelayCounter >= Delay_Depth) DelayCounter = 0;
out_DAC0 = ((sDelayBuffer0[DelayCounter]));
//Add volume feature based in POT2 position.
out_DAC0=map(out_DAC0,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0); //write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0); //write on DAC
}

else if (effect==12) //SUPERECHO
{
// POT0

[DELAY TIME] DEPTH OF THE EFFECT
// POT1
FEEDBACK ADJUST
// POT2
[MIXER] OUTPUT GAIN
//Store current readings
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
a = map(POT1,0,4095,1,4);
sDelayBuffer0[Delay] = in_ADC0 + (sDelayBuffer0[Delay])>>a;
Delay_Depth_echo = map(POT0>>2,0,2047,1,44100);
Delay++;
if(Delay >= Delay_Depth_echo) Delay = 0;
out_DAC0 = ((sDelayBuffer0[Delay])<<1);
out_DAC0=map(out_DAC0,0,4095,1,POT2);
//
Funcoes do Atmel Software Framework (ASK)
//Escreve nos DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
}

else if (effect==13) //FUZZ
{
threshold=map(POT0,0,4095,0,1);
in_ADC0 = in_ADC0/2047 - 1;
if (abs(in_ADC0) <= threshold) {in_ADC0 = in_ADC0 *2;}
if (abs(in_ADC0) > threshold && abs(in_ADC0) < 2*threshold){
if ( in_ADC0 > 0 ){
in_ADC0 = 2 - 3*in_ADC0;
in_ADC0 = in_ADC0 * in_ADC0;
in_ADC0 = 3 - in_ADC0;
in_ADC0 = in_ADC0 / 3;}
if ( in_ADC0 < 0 ) {
in_ADC0 = 2 - 3*abs(in_ADC0);
in_ADC0 = in_ADC0 * in_ADC0;
in_ADC0 = 3 - in_ADC0;
in_ADC0 = - in_ADC0 / 3; }}
if (abs(in_ADC0) >= 2*threshold){
if ( in_ADC0 > 0 ) in_ADC0 =0.98;
if ( in_ADC0 < 0 ) in_ADC0 = -0.98;}
out_DAC0 = (in_ADC0 + 1) * 2047;
out_DAC0=map(out_DAC0,0,4095,1,POT2);
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
dacc_set_channel_selection(DACC_INTERFACE, 1);
dacc_write_conversion_data(DACC_INTERFACE,0);
}

else if (effect==14) //FUZZ EXP
{
if (digitalRead(7)) digitalWrite(3, HIGH); else digitalWrite(3, LOW);
POT0=map(POT0,0,4095,0,1);
out_DAC0=(in_ADC0/abs(in_ADC0))*(1-exp((POT0*in_ADC0*in_ADC0)/abs(in_ADC0)));
out_DAC0=map(out_DAC0,0,4095,1,POT2);
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
dacc_set_channel_selection(DACC_INTERFACE, 1);
dacc_write_conversion_data(DACC_INTERFACE,0);
}

else if (effect==15) //OCTAVE FUZZ
{
// Set up the Sustain Pot
sustain=map(POT0,0,4095,2095,2000);
//Rectify the signals
if (in_ADC0 < sustain) {
memory = sustain - in_ADC0;
in_ADC0 = (sustain+1000) + memory;
};
if (in_ADC1 < sustain) {
memory = sustain - in_ADC1;
in_ADC1 = (sustain+1000) + memory;
};
//adjust the volume with POT2
out_DAC0=map(in_ADC0,0,4095,1,POT2);
out_DAC1=map(in_ADC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}

else if (effect==16) //OCTAVER
{
//Store current readings
sDelayBuffer0[write_pt] = in_ADC0;
sDelayBuffer0[write_pt+15000] = in_ADC1;
//Adjust Delay Depth based in pot2 position.
Delay_Depth = 9999;
//Increse/reset delay counter.
write_pt++;
if(write_pt >= Delay_Depth) write_pt = 0;
out_DAC0 = ((sDelayBuffer0[read_pt_A]));
out_DAC1 = ((sDelayBuffer0[read_pt_B+15000]));
if (POT0>2700)
{
read_pt_A = read_pt_A + 2;
read_pt_B = read_pt_B + 2;
}
else if (POT0>1350)
{
read_pt_A = read_pt_A + 1;
read_pt_B = read_pt_B + 1;
}
else
{
dividoctave++;
if (dividoctave>=2)
{
read_pt_A = read_pt_A + 1;
read_pt_B = read_pt_B + 1;
dividoctave=0;
}
}
if(read_pt_A >= Delay_Depth) read_pt_A = 0;
if(read_pt_B >= Delay_Depth) read_pt_B = 0;
//Add volume control with POT2
out_DAC0=map(out_DAC0,0,4095,1,POT2);
out_DAC1=map(out_DAC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}

else if (effect==17) //REVERB
{
//Store current readings in DELAY mode ADC00 to 20000 ADC1 20500 to 40500
sDelayBuffer0[DelayCounter_A] = in_ADC0 ;
sDelayBuffer0[DelayCounter_B] = in_ADC1 ;
//Adjust Delay Depth based in POT0 and POT1 position.
Delay_Depth_A =map(POT0>>3,0,512,1,20000);
Delay_Depth_B =map(POT1>>3,0,512,20500,40500);
//Increse/reset delay counter.
DelayCounter_A++;
DelayCounter_B++;
if(DelayCounter_A >= Delay_Depth_A) DelayCounter_A = 0;
if(DelayCounter_B >= Delay_Depth_B) DelayCounter_B = 20500;
//Calculate the output as the sum of DelayBuffer_A + DelayBuffer_B
out_DAC0 = (sDelayBuffer0[DelayCounter_A]);
out_DAC1 = (sDelayBuffer0[DelayCounter_B]);
//Add volume feature based in pot2 position.
out_DAC0=map(out_DAC0,0,4095,1,POT2);
out_DAC1=map(out_DAC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}

else if (effect==18) //SUPEREVERB
{
//Store current readings in ECHO mode
sDelayBuffer0[DelayCounter_A]=(in_ADC0 + (sDelayBuffer0[DelayCounter_A]))>>1;
sDelayBuffer0[DelayCounter_B]=(in_ADC1 + (sDelayBuffer0[DelayCounter_B]))>>1;
//Adjust Delay Depth based in POT0 and POT1 position.
Delay_Depth_A =map(POT0>>3,0,512,1,20000);
Delay_Depth_B =map(POT1>>3,0,512,20500,40500);
//Increse/reset delay counter.
DelayCounter_A++;
DelayCounter_B++;
if(DelayCounter_A >= Delay_Depth_A) DelayCounter_A = 0;
if(DelayCounter_B >= Delay_Depth_B) DelayCounter_B = 20500;
//Calculate the output as the sum of DelayBuffer_A + DelayBuffer_B
out_DAC0 = (sDelayBuffer0[DelayCounter_A]);
out_DAC1 = (sDelayBuffer0[DelayCounter_B]);
//Add volume feature based in pot2 position.
out_DAC0=map(out_DAC0,0,4095,1,POT2);
out_DAC1=map(out_DAC1,0,4095,1,POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}

else if (effect==19) //REVERBSHROEDER
{
if (digitalRead(7)) digitalWrite(3, HIGH); else digitalWrite(3, LOW);
sDelayBuffer0[DC1] = (in_ADC0 + 0.7079 * sDelayBuffer0[DC1]);
sDelayBuffer0[DC2] = (in_ADC0 + 0.6496 * sDelayBuffer0[DC2]);
sDelayBuffer0[DC3] = (in_ADC0 + 0,62 * sDelayBuffer0[DC3]);
sDelayBuffer0[DC4] = (in_ADC0 + 0.6016* sDelayBuffer0[DC4]);
DC1++; if (DC1 >= 277) DC1 = 1;
DC2++; if (DC2 >= 872) DC2 = 278;
DC3++; if (DC3 >= 1831) DC3 = 873;
DC4++; if (DC4 >= 3032) DC4 = 1832;
S =( 0,99 * sDelayBuffer0[DC1]+0,95* sDelayBuffer0[DC2]+0,9 * sDelayBuffer0[DC3]+0,8 * sDelayBuffer0[DC4])/4;
sDelayBuffer0[DC6] = (S + 0,4334 * sDelayBuffer0[DC5]);
S1 = - 0.4334 * sDelayBuffer0[DC6] + sDelayBuffer0[DC5];
DC5++; if (DC5 >= 4583) DC5 = 3033;
DC6++; if (DC6>= 4583) DC6 = 3033;
sDelayBuffer0[DC8] = (S1 + 0.5664 * sDelayBuffer0[DC7]);
out_DAC0 = - 0.5664 * sDelayBuffer0[DC8] +sDelayBuffer0[DC7];
DC7++; if (DC7 >= 5110) DC7 = 4584;
DC8++; if (DC8 >=5110) DC8 = 4584;
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_write_conversion_data(DACC_INTERFACE, 0);
dacc_set_channel_selection(DACC_INTERFACE, 1);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
}

else if (effect==20) //REVERSE
{
if (digitalRead(7)) digitalWrite(3, HIGH); else digitalWrite(3, LOW);
sDelayBuffer0[DelayCounter] = in_ADC0;
if (DelayCounter=0){
dacc_write_conversion_data(DACC_INTERFACE,sDelayBuffer0[1]);
DelayCounter=1;
}
else {
dacc_write_conversion_data(DACC_INTERFACE,sDelayBuffer0[0]);
DelayCounter=0;
}
}

else if (effect==21) //RING MODULATOR
{
DelayCounter =DelayCounter+POT0;
if(DelayCounter >=44100) DelayCounter =0;
if (digitalRead(7))digitalWrite(3, !digitalRead(3)); else digitalWrite(3, LOW);
nSine=(((1+sin(((2.0*PI)/44100)*DelayCounter ))*4095.0)/2);
out_DAC0 =in_ADC0*nSine;
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
dacc_set_channel_selection(DACC_INTERFACE, 1);
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);
}

else if (effect==22) //TREMOLO
{
//Increase the sinewave index and/or reset the value.
POT0 = POT0>>1; //divide value by 2 (its too big)
count++;
if (count>=160) //160 chosen empirically
{
count=0;
sample=sample+POT0;
if(sample>=44100)
{
sample=0;
if(digitalRead(FOOTSWITCH))
{
digitalWrite(LED, !digitalRead(LED));
}
else
{
digitalWrite(LED, LOW);
}
}
}
//Create the Low Frequency Oscillator signal with depth control based in POT1.
nSine = (((1+sin(((2.0*PI)/44100)*sample))*4095.0)/2);
LFO=map(nSine,0,4095,(4095-POT1),4095);
//Modulate the output signals based on the sinetable.
out_DAC0 =map(in_ADC0,1,4095,1, LFO);
out_DAC1 =map(in_ADC1,1,4095,1, LFO);
//Add volume feature with POT2
out_DAC0 =map(out_DAC0,1,4095,1, POT2);
out_DAC1 =map(out_DAC1,1,4095,1, POT2);
//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}
else if (effect==23) //VIBRATO
{
POT0=map(POT0>>2,0,1024,1,80); //empirical adjusts
Delay2 = POT0/2;
for ( int u = 0; u <= POT0; u++)
DELAY[POT0+1-u] = DELAY[POT0-u];
DELAY[0] = in_ADC0;
POT1=map(POT1>>2,0,1024,1,4); // empirical adjusts
delay_sr = Delay2 - Delay2*(0.99 * cos(((2.0*PI)/8000)*(j*POT1)));
delay_int = int(delay_sr);
frac = delay_sr - delay_int;
if (frac = 0) frac = 0.01; // Ajusts
if (frac = 1) frac = 0.99; //
j++;
if (j*POT1>=8000)
{
j = 0;
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, !digitalRead(LED));
}
out_DAC0 = (DELAY[delay_int+2]*frac + DELAY[delay_int]*(1-frac));

//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, 0); //write on DAC
}

}

void switch_handler()
{
delayMicroseconds(10000); //debouncing protection
if (toggle_value!=digitalRead(TOGGLE)) effect++;
delayMicroseconds(100000); //debouncing protection
toggle_value=digitalRead(TOGGLE);
if (effect==24) effect=1;
}
The following user(s) said Thank You: Ray, BowDown

Please Log in to join the conversation.

7 years 2 months ago #679 by Ray
wow!
Could you explain how do you switch from one effect to another and which effects are on this code?
Thanks for your contribution.

Please Log in to join the conversation.

7 years 2 months ago #681 by BowDown
I tried this but it didn't compile...

class filter
{
public:
filter()
{
for(int i=0; i <= 5; i++) v=0;
}

In the for loop, i get this error by the IDE:
"exit status 1
incompatible types in assignment of 'int' to 'short int [6]'"

Please Log in to join the conversation.

7 years 2 months ago #682 by AndrewHPavei
You used some of the effects that Ive posted, since that time i ve been working on these effects and i have some issues to modify mainly in Dattoros effects.
maybe tomorrow i will post again a new Zip file =)

Please Log in to join the conversation.

7 years 2 months ago #683 by Ray

I tried this but it didn't compile...

class filter
{
public:
filter()
{
for(int i=0; i <= 5; i++) v=0;
}

In the for loop, i get this error by the IDE:
"exit status 1
incompatible types in assignment of 'int' to 'short int [6]'"


Yes, it does not compile.
It would be nice to have a working code even if only has 5 effects instead of 20 ;)

Please Log in to join the conversation.

7 years 2 months ago #715 by BowDown

It would be nice to have a working code even if only has 5 effects instead of 20


What is the problem with achieving this?

Please Log in to join the conversation.

7 years 2 months ago #718 by Ray

It would be nice to have a working code even if only has 5 effects instead of 20

What is the problem with achieving this?


Not a problem at all, we just need somebody to do it :silly: maybe 5 could be a nice start and then go bigger up to 20.

By the way here there is a code with 3 effects working at the same time (volume/boost, distortion, echo and chorus/vibrato):

www.electrosmash.com/forum/software-peda...same-program?lang=en

Please Log in to join the conversation.

7 years 2 months ago #719 by BowDown
Oh.. If it's feasible then ok...
The way i read what you said, i thought it was imposible.
Like maybe RAM issues....

Please Log in to join the conversation.

7 years 2 months ago #720 by Ray
I believe that is feasible, RAM should not be a limitation because the code itself is stored in FLASH not RAM.

Please Log in to join the conversation.

7 years 1 month ago #723 by freddylamenace
:(
The bif problem with this effect is a bad function with the switch 'change", sometime it's one more,sometime two ..,,
I've tried to see the number and the effect with LCD, but the indications were not good,
I've tried to hae LED for indicate the number of effect, but indication were not good

I've tried with a switch to up and one to down and the result was bad.

this is a new version of the effect

Please Log in to join the conversation.

Time to create page: 0.128 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio