Initial commit

This commit is contained in:
hodasemi 2022-07-18 18:23:07 +02:00
commit 9efd4766e2
31 changed files with 4053 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
target/
Cargo.lock

7
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#610124",
"titleBar.activeBackground": "#870233",
"titleBar.activeForeground": "#FFFBFD"
}
}

View file

@ -0,0 +1,127 @@
/*
Based on the "stomp_shifter" from openmusiclabs;
this is a pitch shifter program. it indexes through a sample
buffer at either a slower or faster rate than the incoming
samples. the buffer boundaries are dealt with by having to samples
being played back simultaneously, each from opposite sides of the
buffer. the volume of each is set by the distance to the boundary.
the rotary encoder sets the speed of playback.
*/
#include "mult16x16.h"
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
#define SIZE 1000 // make this smaller if it clicks
int buffer[SIZE]; // sample buffer
unsigned int location = 0; // current sample input position
unsigned int offset = 0; // playback sample offset from input
byte shift = 0x80;
unsigned int fractional = 0x80; // fractional sample rate
int data_buffer = 0x80;
int counter=0;
int toggle_position=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect) {
// output data
OCR1AL = ((data_buffer >> 8) + 0x80);
OCR1BL = data_buffer; // output the bottom byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
//BUTTONS
counter++; //the pushbuttons are checked every 2500 times.
if(counter==2500)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
shift++;
if (shift >= 0xfe) shift = 0xfe;
}
if (!digitalRead(PUSHBUTTON_1)) {
shift--;
if (shift <= 1) shift = 1;
}
}
//Depending on the Toggle switch position, the effect is reseted)
if(digitalRead(TOGGLE)!=toggle_position)
{
toggle_position = digitalRead(TOGGLE); //update the new value
shift=0x80;
}
buffer[location] = input; // store incoming data
location++; // increment storage location
if (location >= SIZE) location = 0; // boundary wrap
unsigned int temp = location + offset; // find next sample
if (temp >= SIZE) temp -= SIZE; // boundary wrap
int output = buffer[temp]; // fetch sample
temp += (SIZE >> 1); // find sample on opposite side of buffer
if (temp >= SIZE) temp -= SIZE; // boundary wrap
int output2 = buffer[temp]; // fetch sample
unsigned int distance; // find distance to buffer boundary
if (offset > (SIZE >> 1)) distance = SIZE - offset;
else distance = offset;
int result; // average the 2 samples based on distance to boundary
MultiSU16X16toH16(result, output, (distance << 7));
MultiSU16X16toH16(output, output2, (((SIZE >> 1) - distance) << 7));
output += result;
fractional += shift; // increment offset
if (fractional >= 0x0080) {
offset += (fractional >> 7);
fractional &= 0x007f;
}
if (offset >= SIZE) offset -= SIZE; // boundary wrap
// save data
data_buffer = output;
}

View file

@ -0,0 +1,111 @@
/*
Based on the stomp_tremolo.pde from openmusiclabs.com
this program does a tremolo effect. it uses a sinewave stored
in program memory to modulate the signal. the rate at which
it goes through the sinewave is set by the push buttons,
which is min/maxed by the speed value.
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
const char * const sinewave[] PROGMEM = {
// this file is stored in StompShield and is a 1024 value
// sinewave lookup table of signed 16bit integers
// you can replace it with your own waveform if you like
#include "mult16x16.h"
#include "sinetable.inc"
};
unsigned int location = 0; // incoming data buffer pointer
unsigned int fractional = 0x00; // fractional sample position
int data_buffer; // temporary data storage to give a 1 sample buffer
int input, speed=20;
int counter=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect) { // all processing happens here
// output the last value calculated
OCR1AL = ((data_buffer + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = data_buffer; // send out low byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
//BUTTONS
counter++; //to save resources, the pushbuttons are checked every 1000 times.
if(counter==1000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (speed<1024)speed=speed+1; //increase speed
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (speed>0)speed=speed-1; //decrease speed
digitalWrite(LED, LOW); //blinks the led
}
}
fractional += speed; // increment sinewave lookup counter
if (fractional >= 0x0100) { // if its large enough to go to next sample
fractional &= 0x00ff; // round off
location += 1; // go to next location
location &= 0x03ff; // fast boundary wrap for 2^n boundaries
}
// fetch current sinewave value
int amplitude = pgm_read_word_near(sinewave + location);
amplitude += 0x8000; // convert to unsigned
int output;
MultiSU16X16toH16(output, input, amplitude);
// save value for playback next interrupt
data_buffer = output;
}

View file

@ -0,0 +1,121 @@
/* Based on the "CHORUS for Stompshield" adapted from pedal shield, and reconverted for pedalSHIELD UNO*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//defining buttons parameters
#define B_MAX 100 // max value for rotary encoder input (min freq)
#define B_MIN 1 // min value for rotary encoder input (max freq)
//defining FX parameters
#define MAX_DELAY 240
#define MIN_DELAY 200
uint16_t sDelayBuffer0[MAX_DELAY*2];
uint16_t sDelayBuffer1[MAX_DELAY*2];
unsigned int DelayCounter = 5;
unsigned int Delay_Depth = 25;
unsigned int count_up=1;
int p;
int POT0 = 1;
unsigned int location = 0; // incoming data buffer pointer
byte button; // button checking timer
byte last_state; // last rotary encoder state
byte counter = 1; // rotary encoder rotation counter (and start value)
unsigned int fractional = 0x00; // fractional sample position
int data_buffer; // temporary data storage to give a 1 sample buffer
int counter2=0; //buttons timer counter
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
// nothing happens here, all down in the interrupt
}
void checkButton()
{
counter2++; //to save resources, the pushbuttons are checked every 2000 times.
if(counter2==2000)
{
counter2=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (counter > B_MIN) counter-=1; // if not at min, decrement
}
if (!digitalRead(PUSHBUTTON_2)) {
if (counter < B_MAX) counter+=1; // if not at max, increment
}
}
}
ISR(TIMER1_CAPT_vect) { // all processing happens here
// output the last value calculated
OCR1AL = ((data_buffer + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = data_buffer; // send out low byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
checkButton();
// Delay_Depth=counter;
sDelayBuffer0[DelayCounter] = input;
POT0 = counter;
DelayCounter++;
if(DelayCounter >= Delay_Depth)
{
DelayCounter = 0;
if(count_up)
{
for(p=0;p<POT0+1;p++)
sDelayBuffer0[Delay_Depth+p]=sDelayBuffer0[Delay_Depth-1];
Delay_Depth=Delay_Depth+POT0;
if (Delay_Depth>=MAX_DELAY)count_up=0;
}
else
{
Delay_Depth=Delay_Depth-POT0;
if (Delay_Depth<=MIN_DELAY)count_up=1;
}
}
// save value for playback next interrupt
data_buffer = sDelayBuffer0[DelayCounter];
}

View file

@ -0,0 +1,9 @@
Bell_Shifter: A pitch shift program that sounds a bit like a Lo-Fi bell ringing
Better_Tremolo: Tremolo! This one is less noisy than the one included in the PedalSHIELD Uno (at least on my equipment)
Chorus: A basic Chorus effect
Flanger: Pitch oscillation with speed control
Flanger2: Pitch oscillation with speed control, in this one the input is mixed with the output for more depth
Fuzzy_Octave_Down: Octave down effect
UpDown: This program plays through a sample buffer, first forward at double rate, and then backwards at single rate. It changes direction at the buffer boundary.
_Required Files_ : Contains essentials files from the StompShield Library (required for: Bell_Shifter, Better_Tremolo, Flanger and Flanger2)

View file

@ -0,0 +1,142 @@
/* Based on the flanger from openmusiclabs.com
this program does a flanger effect, and interpolates between samples
for a smoother sound output. a rampwave is used to set the variable
delay. the min and max delay times it swing between is set by MIN
and MAX. these are in samples, divide by 31.25ksps to get ms delay
times. the push buttons determines how much the ramp increments
by each time. this sets the frequency of the delay sweep, which is
min/maxed by B_MIN/B_MAX.
*/
#include "mult16x8.h"
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//defining FX parameters
#define MIN 2 // min delay of ~60us
#define MAX 200 // max delay of ~6ms
#define SIZE MAX+10 // data buffer size - must be more than MAX
int buffer[SIZE]; // create a data buffer
byte dir = 1; // keeps track of up/down counting
unsigned int location = 0; // incoming data buffer pointer
byte button; // button checking timer
byte counter = 4; // button counter (and start value)
unsigned int fractional = 0x00; // fractional sample position
int data_buffer; // temporary data storage to give a 1 sample buffer
int toggle_position=0;
int counter2=0; //buttons timer counter
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);}
ISR(TIMER1_CAPT_vect) { // all processing happens here
// output the last value calculated
OCR1AL = ((data_buffer + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = data_buffer; // send out low byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
//BUTTONS
counter2++; //to save resources, the pushbuttons are checked every 2000 times.
if(counter2==2000)
{
counter2=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (counter > MIN) counter-=1; // if not at min, decrement
}
if (!digitalRead(PUSHBUTTON_2)) {
if (counter < MAX) counter+=1; // if not at max, increment
}
//toggle switch
{
toggle_position = digitalRead(TOGGLE);
}
}
// fetch/store data
buffer[location] = input; // store current sample
location++; // go to next sample position
if (location >= SIZE) location = 0; // deal with buffer wrap
int temp = location - (fractional >> 8); // find delayed sample
if (temp < 0) temp += SIZE; // deal with buffer wrap
int output = buffer[temp]; // fetch delayed sample
if (toggle_position=1) output = buffer[temp]+input;
if (toggle_position=0) output = buffer[temp];
temp -= 1; // find adjacent sample
if (temp < 0) temp += SIZE; // deal with buffer wrap
int output2 = buffer[temp]; // get adjacent sample
if (toggle_position=1) output2 = buffer[temp]+input;
if (toggle_position=0) output2 = buffer[temp];
// interpolate between adjacent samples
int temp4; // create some temp variables
int temp5;
// multiply by distance to fractional position
MultiSU16X8toH16(temp4, output, (0xff - (fractional & 0x00ff)));
MultiSU16X8toH16(temp5, output2, (fractional & 0x00ff));
output = temp4 + temp5; // sum weighted samples
// save value for playback next interrupt
data_buffer = output;
// up or down count as necessary till MIN/MAX is reached
if (dir) {
if ((fractional >> 8) >= MAX) dir = 0;
fractional += counter;
}
else {
if ((fractional >> 8) <= MIN) dir = 1;
fractional -= counter;;
}
}

View file

@ -0,0 +1,133 @@
/* Variation based on the flanger from openmusiclabs.com
this program does a flanger effect, and interpolates between samples
for a smoother sound output. a rampwave is used to set the variable
delay. the min and max delay times it swing between is set by MIN
and MAX. these are in samples, divide by 31.25ksps to get ms delay
times. the push buttons determines how much the ramp increments
by each time. this sets the frequency of the delay sweep, which is
min/maxed by B_MIN/B_MAX. In this variant the input signal has been
added to the output.
*/
#include "mult16x8.h"
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//defining FX parameters
#define MIN 2 // min delay of ~60us
#define MAX 200 // max delay of ~6ms
#define SIZE MAX+10 // data buffer size - must be more than MAX
int buffer[SIZE]; // create a data buffer
byte dir = 1; // keeps track of up/down counting
unsigned int location = 0; // incoming data buffer pointer
byte button; // button checking timer
byte counter = 4; // button counter (and start value)
unsigned int fractional = 0x00; // fractional sample position
int data_buffer; // temporary data storage to give a 1 sample buffer
int toggle_position=0;
int counter2=0; //buttons timer counter
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);}
ISR(TIMER1_CAPT_vect) { // all processing happens here
// output the last value calculated
OCR1AL = ((data_buffer + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = data_buffer; // send out low byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
//BUTTONS
counter2++; //to save resources, the pushbuttons are checked every 2000 times.
if(counter2==2000)
{
counter2=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (counter > MIN) counter-=1; // if not at min, decrement
}
if (!digitalRead(PUSHBUTTON_2)) {
if (counter < MAX) counter+=1; // if not at max, increment
}
}
// fetch/store data
buffer[location] = input; // store current sample
location++; // go to next sample position
if (location >= SIZE) location = 0; // deal with buffer wrap
int temp = location - (fractional >> 8); // find delayed sample
if (temp < 0) temp += SIZE; // deal with buffer wrap
int output = buffer[temp]+input; // fetch delayed sample
temp -= 1; // find adjacent sample
if (temp < 0) temp += SIZE; // deal with buffer wrap
int output2 = buffer[temp]+input; // get adjacent sample
// interpolate between adjacent samples
int temp4; // create some temp variables
int temp5;
// multiply by distance to fractional position
MultiSU16X8toH16(temp4, output, (0xff - (fractional & 0x00ff)));
MultiSU16X8toH16(temp5, output2, (fractional & 0x00ff));
output = temp4 + temp5; // sum weighted samples
// save value for playback next interrupt
data_buffer = output;
// up or down count as necessary till MIN/MAX is reached
if (dir) {
if ((fractional >> 8) >= MAX) dir = 0;
fractional += counter;
}
else {
if ((fractional >> 8) <= MIN) dir = 1;
fractional -= counter;;
}
}

View file

@ -0,0 +1,158 @@
/*
Octavedown for pedal shield adapted from Stompshield
Based on https://github.com/spamatica/arduino_stomp_shield_effects
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//#define B_MAX 100 // max value for rotary encoder input (min freq)
//#define B_MIN 1 // min value for rotary encoder input (max freq)
#define MIN_OUT -16383
#define MAX_OUT 16383
#define UP 0
#define DOWN 1
#define NO 0
#define YES 10
//byte button; // button checking timer
//byte last_state; // last rotary encoder state
byte counter = 10; // and start value
byte looper=0;
int oldInput;
int inMaxVal = 0;
int currDirection = UP;
int passedFirst = NO;
int l1=0;
int l2=0;
int input=0; // new input value
int output=0; // calculated current output
int oldOutput=0; // last output value
int filtered=0; // current filtered value;
int oldFiltered=0; // previousFiltered;
int average;
int outGate = 0;
int counter2=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
delay(200);
}
//sounds better if left untouched
/*void checkButton()
{
//BUTTONS
counter2++; //the pushbuttons are checked every 5000 times.
if(counter2==5000)
counter2=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (counter > MIN_OUT) counter=counter-1; // if not at min, decrement
}
if (!digitalRead(PUSHBUTTON_2)) {
if (counter < MAX_OUT) counter=counter+1; // if not at max, increment
}
}
*/
void highPassFilter() // frequency unknown ;)
{
int filterTemp = oldFiltered + output - oldOutput;
filtered = output - (filterTemp/(2));
// filteredArray[i] = alpha * (filteredArray[i-1] + data.recordedSamples[i] - data.recordedSamples[i-1]);
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
// checkButton();
if (input > inMaxVal)
inMaxVal+=10;
if (looper++ % 10 && input > 0 && input < inMaxVal)
inMaxVal-=10;
if (input < 0) // going \ past zero crossing
if (oldInput >= 0)
currDirection = currDirection ^ 1;
// produce output data based on currDirection
if (currDirection)
output+=(counter<<5);
else
output-=(counter<<5);
//calculate gate according to current input
// if (outGate > maxVal) outGate = outGate -10;
// if (outGate < minVal) outGate = outGate +10;
if (inMaxVal < 1200) {
outGate-=50;
if (outGate < 0) outGate=0;
}
else
outGate = MAX_OUT;
// limit outvalue according to current gate
if (output < -outGate) output=-outGate;
if (output > outGate) output=outGate;
highPassFilter();
//filtered=output;
// save data
oldInput = input;
oldOutput = output;
oldFiltered = filtered;
// output data
OCR1AL = ((filtered >> 8) + 0x80);
OCR1BL = filtered; // output the bottom byte
}

View file

@ -0,0 +1,87 @@
/*
Based on the 'stomp_updown" from openmusiclabs.com
this program plays through a sample buffer, first forward at
double rate, and then backwards at single rate. it changes
direction at the buffer boundary.
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
#define SIZE 1000 // buffer size, make lower if it clicks
int buffer[SIZE]; // data buffer
unsigned int location = 0; // current buffer location
unsigned int offset = 0; // distance to current location
byte dir = 0; // direction of travel in buffer
int data_buffer = 0x8000;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
}
ISR(TIMER1_CAPT_vect) { // all processing happens here
// output the last value calculated
OCR1AL = ((data_buffer + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = data_buffer; // send out low byte
// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value
buffer[location] = input; // store current sample
location++; // go to next location
if (location >= SIZE) location = 0; // deal with boundary
unsigned int temp = location + offset; // find playback location
if (temp >= SIZE) temp -= SIZE; // boundary wrap
data_buffer = buffer[temp]; // fetch sample
if (dir) { // increment until at buffer boundary
if (offset >= (SIZE - 4)) {
dir = 0;
offset--;
}
else offset++;
}
else { // decrement till reaching boundary from other side
if (offset <= 4) {
dir = 1;
offset--;
}
else offset -= 2;
}
}

View file

@ -0,0 +1,236 @@
// guest openmusiclabs 6.8.11
// taken from http://mekonik.wordpress.com/2009/03/18/arduino-avr-gcc-multiplication/
// longRes = intIn1 * intIn2
#define MultiU16X16to32(longRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %B1, %B2 \n\t" \
"movw %C0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"mul %B1, %A2 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (longRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" \
)
// intRes = intIn1 * intIn2 >> 16
// uses:
// r26 to store 0
// r27 to store the byte 1 of the 32bit result
#define MultiU16X16toH16(intRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"mov r27, r1 \n\t" \
"mul %B1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"mul %B1, %A2 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (intRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" , "r27" \
)
// intRes = intIn1 * intIn2 >> 16 + round
// uses:
// r26 to store 0
// r27 to store the byte 1 of the 32bit result
// 21 cycles
#define MultiU16X16toH16Round(intRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"mov r27, r1 \n\t" \
"mul %B1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"mul %B1, %A2 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"lsl r27 \n\t" \
"adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (intRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" , "r27" \
)
// signed16 * signed16
// 22 cycles
#define MultiS16X16to32(longRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"movw %A0, r0 \n\t" \
"muls %B1, %B2 \n\t" \
"movw %C0, r0 \n\t" \
"mulsu %B2, %A1 \n\t" \
"sbc %D0, r26 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"mulsu %B1, %A2 \n\t" \
"sbc %D0, r26 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (longRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" \
)
// signed16 * signed 16 >> 16
#define MultiS16X16toH16(intRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"mov r27, r1 \n\t" \
"muls %B1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mulsu %B2, %A1 \n\t" \
"sbc %B0, r26 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"mulsu %B1, %A2 \n\t" \
"sbc %B0, r26 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (intRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26", "r27" \
)
// multiplies a signed and unsigned 16 bit ints with a 32 bit result
#define MultiSU16X16to32(longRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"movw %A0, r0 \n\t" \
"mulsu %B1, %B2 \n\t" \
"movw %C0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"mulsu %B1, %A2 \n\t" \
"sbc %D0, r26 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (longRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" \
)
// multiplies signed x unsigned int and returns the highest 16 bits of the result
#define MultiSU16X16toH16(intRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"mov r27, r1 \n\t" \
"mulsu %B1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"mulsu %B1, %A2 \n\t" \
"sbc %B0, r26 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (intRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26", "r27" \
)
// multiplies signed x unsigned int and returns the highest 16 bits of the result
// rounds the result based on the MSB of the lower 16 bits
// 22 cycles
#define MultiSU16X16toH16Round(intRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"mov r27, r1 \n\t" \
"mulsu %B1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %A1, %B2 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"mulsu %B1, %A2 \n\t" \
"sbc %B0, r26 \n\t" \
"add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"lsl r27 \n\t" \
"adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (intRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26", "r27" \
)

View file

@ -0,0 +1,128 @@
// guest openmusiclabs 6.8.11
// taken from http://mekonik.wordpress.com/2009/03/18/arduino-avr-gcc-multiplication/
// added MultiSU16XConst8toH16
// although the constant multiplies arent any faster
// than just creating a local variable equal to your constant
// added MultiU16x8toH16
// multiplies 16 bit X 8 bit
// stores lower 16 bits
#define MultiSU16X8toL16(intRes, int16In, int8In) \
asm volatile ( \
"mul %A1, %2 \n\t"\
"movw %A0, r0 \n\t"\
"mulsu %B1, %2 \n\t"\
"add %B0, r0 \n\t"\
"clr r1"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"a" (int8In) \
)
// multiplies 16 bit number X 8 bit constant
// saves lower 16 bit
// 8 cycles
#define MultiSU16XConst8toL16(intRes, int16In, int8In) \
asm volatile ( \
"ldi r22, %2 \n\t"\
"mul %A1, r22 \n\t"\
"movw %A0, r0 \n\t"\
"mulsu %B1, r22 \n\t"\
"add %B0, r0 \n\t"\
"clr r1 \n\t"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"M" (int8In) \
:\
"r22"\
)
// multiplies 16 bit number X 8 bit constant
// saves higher 16 bit
// 8 cycles
#define MultiSU16XConst8toH16(intRes, int16In, int8In) \
asm volatile ( \
"clr r26 \n\t"\
"ldi r22, %2 \n\t"\
"mulsu %B1, r22 \n\t"\
"movw %A0, r0 \n\t"\
"mul %A1, r22 \n\t"\
"add %A0, r1 \n\t"\
"adc %B0, r26 \n\t"\
"clr r1 \n\t"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"M" (int8In) \
:\
"r22", \
"r26"\
)
// multiplies 16 bit number X 8 bit and stores 2 high bytes
#define MultiSU16X8toH16(intRes, int16In, int8In) \
asm volatile ( \
"clr r26 \n\t"\
"mulsu %B1, %A2 \n\t"\
"movw %A0, r0 \n\t"\
"mul %A1, %A2 \n\t"\
"add %A0, r1 \n\t"\
"adc %B0, r26 \n\t"\
"clr r1 \n\t"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"a" (int8In) \
:\
"r26"\
)
// multiplies 16 bit signed number X 8 bit and stores 2 high bytes
// rounds the number based on the MSB of the lowest byte
#define MultiSU16X8toH16Round(intRes, int16In, int8In) \
asm volatile ( \
"clr r26 \n\t"\
"mulsu %B1, %A2 \n\t"\
"movw %A0, r0 \n\t"\
"mul %A1, %A2 \n\t"\
"add %A0, r1 \n\t"\
"adc %B0, r26 \n\t"\
"lsl r0 \n\t"\
"adc %A0, r26 \n\t"\
"adc %B0, r26 \n\t"\
"clr r1 \n\t"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"a" (int8In) \
:\
"r26"\
)
// multiplies 16 bit number X 8 bit and stores 2 high bytes
#define MultiU16X8toH16(intRes, int16In, int8In) \
asm volatile ( \
"clr r26 \n\t"\
"mul %B1, %A2 \n\t"\
"movw %A0, r0 \n\t"\
"mul %A1, %A2 \n\t"\
"add %A0, r1 \n\t"\
"adc %B0, r26 \n\t"\
"clr r1 \n\t"\
: \
"=&r" (intRes) \
: \
"a" (int16In), \
"a" (int8In) \
:\
"r26"\
)

File diff suppressed because it is too large Load diff

87
c/bit_crusher.ino Normal file
View file

@ -0,0 +1,87 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
/* pedalshield_uno_bit_crusher.ino reads the ADC and shift the bits creating a high distorted sound
* pressing the pushbutton_1 or 2 turns the bit shift harder or softer..
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, bit_crush_variable=0;
int counter=0;
unsigned int ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
//// All the Digital Signal Processing happens here: ////
counter++; //to save resources, the pushbuttons are checked every 10000 times.
if(counter==10000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (bit_crush_variable<16)bit_crush_variable=bit_crush_variable+1; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (bit_crush_variable>0)bit_crush_variable=bit_crush_variable-1; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
//The bit_crush_variable goes from 0 to 16 and the input signal is crushed in the next instruction:
input = input<<bit_crush_variable;
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

67
c/clean.ino Normal file
View file

@ -0,0 +1,67 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// clean_pedalshield_uno.ino reads the ADC and plays it back into the PWM output
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, vol_variable=512;
int counter=0;
byte ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

197
c/clean_ring_buffer.ino Normal file
View file

@ -0,0 +1,197 @@
// RING BUFFER CLEAN
// via www.Electrosmash.com
// via OpenMusicLabs
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
#define BUFF_SIZE 500 // size of ring buffer, can theoretically be anything
// 500 should hold 15.9 ms of audio
// STRUCTURES
// can be used to implement a virtual debounce, e.g.
// if (millis() - button_time_s.pb1 > 250)
// {
// do something
// button_time_s.pb1 = millis();
// }
// {
// don't do something as it will be the same press as before
// }
// also keeps track of when the footswitch is turned on
struct button_time_s
{
long footswitch;
long pb1;
long pb2;
};
// counts iterations of main and interrupt loops
struct count_s
{
int main;
int interrupt;
};
// keeps track of when the footswitch is turned on
// by storing a current and an old
// if current != old
// switch has just been turned on
struct switch_flag_s
{
bool current;
bool old;
};
// ring buffer structure
// buff is array to store the audio
// head and tail and head and tail, respectively
struct ring_buff_s
{
int buff[BUFF_SIZE];
int head;
int tail;
};
// VARIABLES
int input, vol_variable=512;
byte ADC_low, ADC_high;
int offset = 5; //offset of 5 ms will still be "real time", can theoretically have up to 30 ms delay between input and output and still appear "real time"
long milli;
button_time_s button_time;
count_s count;
switch_flag_s switch_flag;
ring_buff_s buf;
// BUFFER FUNCTIONS
void push_to_buff(int in)
{
buf.buff[buf.head] = in;
buf.head++;
if (buf.head == BUFF_SIZE)
{
buf.head = 0;
}
}
int pop_from_buff (void)
{
int out = buf.buff[buf.tail];
if (buf.tail != buf.head)
{
buf.tail++;
}
if (buf.tail == BUFF_SIZE)
{
buf.tail = 0;
}
return out;
}
void setup()
{
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
// MAIN LOOP
// checks the footswitch is pushed every 100 loops
// changes the switch_flag.current
// checks if the footswitch has been recently pressed
// if switch flag is true call functions
// else just set LED here,
// doesn't need to optimised if no audio is being processed
// finally, increment count
void loop()
{
if (count.main % 100 == 0)
{
switch_flag.current = digitalRead(FOOTSWITCH);
if (switch_flag.current != switch_flag.old)
{
button_time.footswitch = millis();
digitalWrite(LED, true);
}
switch_flag.old = switch_flag.current;
if (switch_flag.current == true)
{
milli = millis();
// add code here when effect is on
}
else
{
digitalWrite(LED, false);
}
}
count.main++;
}
// AUDIO INPUTTER
// pulls the audio from the ADC
// pushes it to the ring buffer
void audio_inputter()
{
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
input = ((ADC_high << 8) | ADC_low); // make a signed 16b value
if (input > 0x8000)
{
input = input + 0x8000;
}
push_to_buff(input);
}
// AUDIO OUTPUTTER
// wait until
// pop audio from ring buffer and output to PWM
void audio_outputter()
{
if (milli - button_time.footswitch > offset)
{
int output = pop_from_buff();
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = output; // send out low byt
}
}
// TIMER1 INTERRUPT
// checks the switch flag is true
// inputs then outputs audio
// increment count
ISR(TIMER1_CAPT_vect)
{
if (switch_flag.current == true)
{
audio_inputter();
audio_outputter();
count.interrupt++;
}
}

94
c/daft_punk_octaver.ino Normal file
View file

@ -0,0 +1,94 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
/* pedalshield_uno_daftpunk_distortion_octaver.ino creates a distortion effect similar to the used
* in Television Rules the Nation by Daft Punk. It also octaves the signal up/down presing the pushbuttons
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int counter = 0;
int counter2 = 0;
int input;
int dist_variable=10;
byte ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect) {
counter++; //to save resources, the pushbuttons are checked every 2000 times.
if(counter==2000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (dist_variable<500)dist_variable++;
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_2)) {
if (dist_variable>0)dist_variable--;
digitalWrite(LED, LOW); //blinks the led
}
}
counter2++;
if(counter2>=dist_variable)
{
counter2=0;
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}
}

94
c/delay.ino Normal file
View file

@ -0,0 +1,94 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// pedalshield_uno_delay.ino reads the ADC, saves it into the DelayBuffer[] array and plays it into the PWM output.
// pressing the pushbutton_1 or 2 makes the delay longer or shorter
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, vol_variable=512;
int counter=0;
unsigned int ADC_low, ADC_high;
#define MAX_DELAY 2000
byte DelayBuffer[MAX_DELAY];
unsigned int DelayCounter = 0;
unsigned int Delay_Depth = MAX_DELAY;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = 0; // ADC_low always 0 to save space
ADC_high = ADCH;
//store the high bit only for
DelayBuffer[DelayCounter] = ADC_high;
counter++; //to save resources, the pushbuttons are checked every 100 times.
if(counter==100)
{
counter=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (Delay_Depth<MAX_DELAY)Delay_Depth=Delay_Depth+1; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_2)) {
if (Delay_Depth>0)Delay_Depth=Delay_Depth-1; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
//Increse/reset delay counter.
DelayCounter++;
if(DelayCounter >= Delay_Depth) DelayCounter = 0;
input = (((DelayBuffer[DelayCounter] << 8) | ADC_low) + 0x8000)+(((ADC_high << 8) | ADC_low) + 0x8000); // make a signed 16b value
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

87
c/distortion.ino Normal file
View file

@ -0,0 +1,87 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// pedalshield_uno_distortion.ino reads the ADC signal and clip it to a threshold value
// pressing the pushbutton_1 or 2 turns the distortion harder or softer.
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, distortion_threshold=6000; //initial value adjusted by try and error.
int counter=0;
unsigned int ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
counter++; //to save resources, the pushbuttons are checked every 1000 times.
if(counter==1000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (distortion_threshold<32768)distortion_threshold=distortion_threshold+25; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (distortion_threshold>0)distortion_threshold=distortion_threshold-25; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
//the input signal is 16bits (values from -32768 to +32768
//the valueif(input>distortion_threshold) input=distortion_threshold; is clipped to the distortion_threshold value
if(input>distortion_threshold) input=distortion_threshold;
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

88
c/fuzz.ino Normal file
View file

@ -0,0 +1,88 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// pedalshield_uno_fuzz.ino reads the ADC signal and boost it to the max or min value depending on a threshold value
// pressing the pushbutton_1 or 2 turns the fuzz distortion harder or softer.
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, distortion_threshold=6000; //initial value adjusted by try and error.
int counter=0;
unsigned int ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
counter++; //to save resources, the pushbuttons are checked every 1000 times.
if(counter==1000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (distortion_threshold<32768)distortion_threshold=distortion_threshold+25; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (distortion_threshold>0)distortion_threshold=distortion_threshold-25; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
//the input signal is 16bits (values from -32768 to +32768
//the value is clipped to the distortion_threshold value
if(input>distortion_threshold) input=32768;
else if(input<-distortion_threshold) input=-32768;
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

159
c/metronome.ino Normal file
View file

@ -0,0 +1,159 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs and GFB previous works.
// pedalshield_metronome.ino plays a beep (togheter with the LED) like a metronome.
// pressing the pushbutton_1 or 2 changes the speed.
const byte waveform[]=
{
0x80,0x80,0x81,0x82,0x83,0x83,0x84,0x85,0x86,0x87,0x87,0x88,0x89,0x8a,0x8a,0x8b,
0x8c,0x8d,0x8e,0x8e,0x8f,0x90,0x91,0x91,0x92,0x93,0x94,0x95,0x95,0x96,0x97,0x98,
0x98,0x99,0x9a,0x9b,0x9b,0x9c,0x9d,0x9e,0x9f,0x9f,0xa0,0xa1,0xa2,0xa2,0xa3,0xa4,
0xa5,0xa5,0xa6,0xa7,0xa8,0xa8,0xa9,0xaa,0xaa,0xab,0xac,0xad,0xad,0xae,0xaf,0xb0,
0xb0,0xb1,0xb2,0xb2,0xb3,0xb4,0xb5,0xb5,0xb6,0xb7,0xb7,0xb8,0xb9,0xba,0xba,0xbb,
0xbc,0xbc,0xbd,0xbe,0xbe,0xbf,0xc0,0xc0,0xc1,0xc2,0xc2,0xc3,0xc4,0xc4,0xc5,0xc6,
0xc6,0xc7,0xc8,0xc8,0xc9,0xca,0xca,0xcb,0xcc,0xcc,0xcd,0xcd,0xce,0xcf,0xcf,0xd0,
0xd0,0xd1,0xd2,0xd2,0xd3,0xd3,0xd4,0xd5,0xd5,0xd6,0xd6,0xd7,0xd7,0xd8,0xd9,0xd9,
0xda,0xda,0xdb,0xdb,0xdc,0xdc,0xdd,0xde,0xde,0xdf,0xdf,0xe0,0xe0,0xe1,0xe1,0xe2,
0xe2,0x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x6,0x6,0x7,0x7,0x7,0x7,0x8,0x8,0x8,0x8,0x9,0x9,0x9,0xa,
0xa,0xa,0xb,0xb,0xb,0xc,0xc,0xc,0xd,0xd,0xd,0xe,0xe,0xe,0xf,0xf,
0xf,0x10,0x10,0x10,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x14,0x14,0x15,0x15,0x15,
0x16,0x16,0x17,0x17,0x18,0x18,0x19,0x19,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,
0x1d,0x1e,0x1e,0x1f,0x1f,0x20,0x20,0x21,0x21,0x22,0x23,0x23,0x24,0x24,0x25,0x25,
0x26,0x26,0x27,0x28,0x28,0x29,0x29,0x2a,0x2a,0x2b,0x2c,0x2c,0x2d,0x2d,0x2e,0x2f,
0x2f,0x30,0x30,0x31,0x32,0x32,0x33,0x33,0x34,0x35,0x35,0x36,0x37,0x37,0x38,0x39,
0x39,0x3a,0x3b,0x3b,0x3c,0x3d,0x3d,0x3e,0x3f,0x3f,0x40,0x41,0x41,0x42,0x43,0x43,
0x44,0x45,0x45,0x46,0x47,0x48,0x48,0x49,0x4a,0x4a,0x4b,0x4c,0x4d,0x4d,0x4e,0x4f,
0x4f,0x50,0x51,0x52,0x52,0x53,0x54,0x55,0x55,0x56,0x57,0x57,0x58,0x59,0x5a,0x5a,
0x5b,0x5c,0x5d,0x5d,0x5e,0x5f,0x60,0x60,0x61,0x62,0x63,0x64,0x64,0x65,0x66,0x67,
0x67,0x68,0x69,0x6a,0x6a,0x6b,0x6c,0x6d,0x6e,0x6e,0x6f,0x70,0x71,0x71,0x72,0x73,
0x74,0x75,0x75,0x76,0x77,0x78,0x78,0x79,0x7a,0x7b,0x7c,0x7c,0x7d,0x7e,0x7f,0x80,
};
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input;
long delay_time=20000;
int counter=0;
int sample=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//BEEP PART: Enable Interruption which makes the sinewave.
digitalWrite(LED, HIGH);
sei(); // turn on interrupts - not really necessary with arduino
delay(50); //the beep has a constant time of 50ms.
//SILENT PART: Disabling Interruption which makes the sinewave.
digitalWrite(LED, LOW);
cli();
//IC_DisableIRQ(TC4_IRQn);
sample=0;
delay(delay_time);
}
ISR(TIMER1_CAPT_vect)
{
counter++; //to save resources, the pushbuttons are checked every 100 times.
if(counter==1000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_1)) {
if (delay_time<2000000)delay_time=delay_time+1000; //increase the vol
// digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_2)) {
if (delay_time>600)delay_time=delay_time-1000; //decrease vol
// digitalWrite(LED, LOW); //blinks the led
}
}
input = waveform[sample];//((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
sample=sample+20;
if(sample>=1023)sample=0;
//write the PWM signal
OCR1AL =waveform[sample];
OCR1BL = waveform[sample];
}

141
c/multi-effects.ino Normal file
View file

@ -0,0 +1,141 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// multi-effects.c including
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input;
int counter=0;
int effect=0;
int toggle_position=0;
byte ADC_low, ADC_high;
//effects variables:
int vol_variable=10000;
int distortion_threshold=6000;
int fuzz_threshold=6000;
int bit_crush_variable=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
//read the initial position of the toggle switch:
toggle_position = digitalRead(TOGGLE);
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//Depending on the Toggle switch position, the effect is changed (up to 4 effects)
if(digitalRead(TOGGLE)!=toggle_position)
{
toggle_position = digitalRead(TOGGLE); //update the new value
effect++;
if (effect>4) effect=0;
//set the default variables for all effects:
vol_variable=10000;
distortion_threshold=6000;
fuzz_threshold=6000;
bit_crush_variable=0;
}
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
//update variables with the push-buttons
counter++; //to save resources, the pushbuttons are checked every 100 times.
if(counter==100)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2))
{
if (vol_variable<32768)vol_variable=vol_variable+10; //increase the volume
if(distortion_threshold<32768)distortion_threshold=distortion_threshold+25; //increase the distortion
if (fuzz_threshold<32768)fuzz_threshold=fuzz_threshold+25; //increase the fuzz
if (bit_crush_variable<16)bit_crush_variable=bit_crush_variable+1; //increase the bit crushing
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1))
{
if (vol_variable>0)vol_variable=vol_variable-10; //decrease volume
if (distortion_threshold>0)distortion_threshold=distortion_threshold-25; //decrease the distortion
if (fuzz_threshold>0)fuzz_threshold=fuzz_threshold-25; //decrease the fuzz
if (bit_crush_variable>0)bit_crush_variable=bit_crush_variable-1; //decrease the bit crushing
digitalWrite(LED, LOW); //blinks the led
}
}
//update variables with the push-buttons
if (effect==0) //CLEAN EFFECT
{
//clean effect so, do nothing
}
//construct the input sumple summing the ADC low and high byte.
else if(effect==1) //VOLUME EFFECT
{
input = map(input, -32768, +32768,-vol_variable, vol_variable);
}
else if(effect==2) //DISTORTION EFFECT
{
if(input>distortion_threshold) input=distortion_threshold;
}
else if(effect==3) //FUZZ EFFECT
{
if(input>fuzz_threshold) input=32768;
else if(input<-fuzz_threshold) input=-32768;
}
else if(effect==4) //BIT CRUSHER EFFECT
{
input = input<<bit_crush_variable;
}
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

150
c/signal_generator.ino Normal file
View file

@ -0,0 +1,150 @@
/ CC-by-www.Electrosmash.com
// Based on OpenMusicLabs and GFB previous works.
// pedalshield_uno_signal_generator.ino plays a waveform stores in memory (waveform[])
// pressing the pushbutton_1 or 2 changes the frequency.
const byte waveform[]=
{0x80,0x80,0x81,0x82,0x83,0x83,0x84,0x85,0x86,0x87,0x87,0x88,0x89,0x8a,0x8a,0x8b,
0x8c,0x8d,0x8e,0x8e,0x8f,0x90,0x91,0x91,0x92,0x93,0x94,0x95,0x95,0x96,0x97,0x98,
0x98,0x99,0x9a,0x9b,0x9b,0x9c,0x9d,0x9e,0x9f,0x9f,0xa0,0xa1,0xa2,0xa2,0xa3,0xa4,
0xa5,0xa5,0xa6,0xa7,0xa8,0xa8,0xa9,0xaa,0xaa,0xab,0xac,0xad,0xad,0xae,0xaf,0xb0,
0xb0,0xb1,0xb2,0xb2,0xb3,0xb4,0xb5,0xb5,0xb6,0xb7,0xb7,0xb8,0xb9,0xba,0xba,0xbb,
0xbc,0xbc,0xbd,0xbe,0xbe,0xbf,0xc0,0xc0,0xc1,0xc2,0xc2,0xc3,0xc4,0xc4,0xc5,0xc6,
0xc6,0xc7,0xc8,0xc8,0xc9,0xca,0xca,0xcb,0xcc,0xcc,0xcd,0xcd,0xce,0xcf,0xcf,0xd0,
0xd0,0xd1,0xd2,0xd2,0xd3,0xd3,0xd4,0xd5,0xd5,0xd6,0xd6,0xd7,0xd7,0xd8,0xd9,0xd9,
0xda,0xda,0xdb,0xdb,0xdc,0xdc,0xdd,0xde,0xde,0xdf,0xdf,0xe0,0xe0,0xe1,0xe1,0xe2,
0xe2,0xe3,0xe3,0xe4,0xe4,0xe5,0xe5,0xe6,0xe6,0xe6,0xe7,0xe7,0xe8,0xe8,0xe9,0xe9,
0xea,0xea,0xea,0xeb,0xeb,0xec,0xec,0xed,0xed,0xed,0xee,0xee,0xef,0xef,0xef,0xf0,
0xf0,0xf0,0xf1,0xf1,0xf1,0xf2,0xf2,0xf2,0xf3,0xf3,0xf3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17,0x17,0x18,0x18,0x19,0x19,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,
0x1d,0x1e,0x1e,0x1f,0x1f,0x20,0x20,0x21,0x21,0x22,0x23,0x23,0x24,0x24,0x25,0x25,
0x26,0x26,0x27,0x28,0x28,0x29,0x29,0x2a,0x2a,0x2b,0x2c,0x2c,0x2d,0x2d,0x2e,0x2f,
0x2f,0x30,0x30,0x31,0x32,0x32,0x33,0x33,0x34,0x35,0x35,0x36,0x37,0x37,0x38,0x39,
0x39,0x3a,0x3b,0x3b,0x3c,0x3d,0x3d,0x3e,0x3f,0x3f,0x40,0x41,0x41,0x42,0x43,0x43,
0x44,0x45,0x45,0x46,0x47,0x48,0x48,0x49,0x4a,0x4a,0x4b,0x4c,0x4d,0x4d,0x4e,0x4f,
0x4f,0x50,0x51,0x52,0x52,0x53,0x54,0x55,0x55,0x56,0x57,0x57,0x58,0x59,0x5a,0x5a,
0x5b,0x5c,0x5d,0x5d,0x5e,0x5f,0x60,0x60,0x61,0x62,0x63,0x64,0x64,0x65,0x66,0x67,
0x67,0x68,0x69,0x6a,0x6a,0x6b,0x6c,0x6d,0x6e,0x6e,0x6f,0x70,0x71,0x71,0x72,0x73,
0x74,0x75,0x75,0x76,0x77,0x78,0x78,0x79,0x7a,0x7b,0x7c,0x7c,0x7d,0x7e,0x7f,0x80,
};
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input,inputa,inputb, speed=1;
int counter=0;
int sample=0;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
counter++; //to save resources, the pushbuttons are checked every 5000 times.
if(counter==5000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (speed<1024)speed=speed+1; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (speed>0)speed=speed-1; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
input = waveform[sample];
sample=sample+speed;
if(sample>1023)sample=0;
//write the PWM signal
OCR1AL =waveform[sample];// (((input + 0x08000)) >> 8); // convert to unsigned, send out high byte
OCR1BL = waveform[sample]; // send out low byte
}

153
c/tremolo.ino Normal file
View file

@ -0,0 +1,153 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// pedalshield_uno_tremolo.ino creates a tremolo effect, modulating the volume with a sinewave.
// pressing the pushbutton_1 or 2 makes the modulation faster or slower.
//this waveform is used to modulate the volume of the output signal.
const byte waveform[]=
{
0x0,0x1,0x1,0x2,0x2,0x2,0x3,0x3,0x4,0x4,0x4,0x5,0x5,0x5,0x6,0x6,0x7,0x7,0x7,0x8,
0x8,0x9,0x9,0x9,0xa,0xa,0xb,0xb,0xb,0xc,0xc,0xd,0xd,0xd,0xe,0xe,0xe,0xf,0xf,0x10,
0x10,0x10,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x17,
0x18,0x18,0x19,0x19,0x19,0x1a,0x1a,0x1b,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1f,0x1f,
0x20,0x20,0x20,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x26,0x26,0x26,0x27,0x27,
0x27,0x28,0x28,0x29,0x29,0x29,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2f,0x2f,
0x2f,0x30,0x30,0x30,0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x34,0x34,0x34,0x35,0x35,0x36,0x36,0x36,0x37,
0x37,0x38,0x38,0x38,0x39,0x39,0x39,0x3a,0x3a,0x3b,0x3b,0x3b,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,0x3e,0x3f,
0x3f,0x3f,0x40,0x40,0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,0x44,0x44,0x44,0x45,0x45,0x46,0x46,0x46,
0x47,0x47,0x48,0x48,0x48,0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,
0x4f,0x4f,0x4f,0x50,0x50,0x51,0x51,0x51,0x52,0x52,0x53,0x53,0x53,0x54,0x54,0x54,0x55,0x55,0x56,0x56,
0x56,0x57,0x57,0x58,0x58,0x58,0x59,0x59,0x5a,0x5a,0x5a,0x5b,0x5b,0x5b,0x5c,0x5c,0x5d,0x5d,0x5d,0x5e,
0x5e,0x5f,0x5f,0x5f,0x60,0x60,0x61,0x61,0x61,0x62,0x62,0x63,0x63,0x63,0x64,0x64,0x64,0x65,0x65,0x66,
0x66,0x66,0x67,0x67,0x68,0x68,0x68,0x69,0x69,0x6a,0x6a,0x6a,0x6b,0x6b,0x6c,0x6c,0x6c,0x6d,0x6d,0x6d,
0x6e,0x6e,0x6f,0x6f,0x6f,0x70,0x70,0x71,0x71,0x71,0x72,0x72,0x73,0x73,0x73,0x74,0x74,0x75,0x75,0x75,
0x76,0x76,0x76,0x77,0x77,0x78,0x78,0x78,0x79,0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,
0x7e,0x7e,0x7e,0x7f,0x7f,0x7f,0x80,0x80,0x81,0x81,0x81,0x82,0x82,0x83,0x83,0x83,0x84,0x84,0x85,0x85,
0x85,0x86,0x86,0x87,0x87,0x87,0x88,0x88,0x88,0x89,0x89,0x8a,0x8a,0x8a,0x8b,0x8b,0x8c,0x8c,0x8c,0x8d,
0x8d,0x8e,0x8e,0x8e,0x8f,0x8f,0x8f,0x90,0x90,0x91,0x91,0x91,0x92,0x92,0x93,0x93,0x93,0x94,0x94,0x95,
0x95,0x95,0x96,0x96,0x97,0x97,0x97,0x98,0x98,0x98,0x99,0x99,0x9a,0x9a,0x9a,0x9b,0x9b,0x9c,0x9c,0x9c,
0x9d,0x9d,0x9e,0x9e,0x9e,0x9f,0x9f,0xa0,0xa0,0xa0,0xa1,0xa1,0xa1,0xa2,0xa2,0xa3,0xa3,0xa3,0xa4,0xa4,
0xa5,0xa5,0xa5,0xa6,0xa6,0xa7,0xa7,0xa7,0xa8,0xa8,0xa9,0xa9,0xa9,0xaa,0xaa,0xaa,0xab,0xab,0xac,0xac,
0xac,0xad,0xad,0xae,0xae,0xae,0xaf,0xaf,0xb0,0xb0,0xb0,0xb1,0xb1,0xb2,0xb2,0xb2,0xb3,0xb3,0xb3,0xb4,
0xb4,0xb5,0xb5,0xb5,0xb6,0xb6,0xb7,0xb7,0xb7,0xb8,0xb8,0xb9,0xb9,0xb9,0xba,0xba,0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,0x82,0x82,0x81,0x81,0x81,0x80,0x80,0x7f,0x7f,0x7f,
0x7e,0x7e,0x7e,0x7d,0x7d,0x7c,0x7c,0x7c,0x7b,0x7b,0x7a,0x7a,0x7a,0x79,0x79,0x78,0x78,0x78,0x77,0x77,
0x76,0x76,0x76,0x75,0x75,0x75,0x74,0x74,0x73,0x73,0x73,0x72,0x72,0x71,0x71,0x71,0x70,0x70,0x6f,0x6f,
0x6f,0x6e,0x6e,0x6d,0x6d,0x6d,0x6c,0x6c,0x6c,0x6b,0x6b,0x6a,0x6a,0x6a,0x69,0x69,0x68,0x68,0x68,0x67,
0x67,0x66,0x66,0x66,0x65,0x65,0x64,0x64,0x64,0x63,0x63,0x63,0x62,0x62,0x61,0x61,0x61,0x60,0x60,0x5f,
0x5f,0x5f,0x5e,0x5e,0x5d,0x5d,0x5d,0x5c,0x5c,0x5b,0x5b,0x5b,0x5a,0x5a,0x5a,0x59,0x59,0x58,0x58,0x58,
0x57,0x57,0x56,0x56,0x56,0x55,0x55,0x54,0x54,0x54,0x53,0x53,0x53,0x52,0x52,0x51,0x51,0x51,0x50,0x50,
0x4f,0x4f,0x4f,0x4e,0x4e,0x4d,0x4d,0x4d,0x4c,0x4c,0x4b,0x4b,0x4b,0x4a,0x4a,0x4a,0x49,0x49,0x48,0x48,
0x48,0x47,0x47,0x46,0x46,0x46,0x45,0x45,0x44,0x44,0x44,0x43,0x43,0x42,0x42,0x42,0x41,0x41,0x41,0x40,
0x40,0x3f,0x3f,0x3f,0x3e,0x3e,0x3d,0x3d,0x3d,0x3c,0x3c,0x3b,0x3b,0x3b,0x3a,0x3a,0x39,0x39,0x39,0x38,
0x38,0x38,0x37,0x37,0x36,0x36,0x36,0x35,0x35,0x34,0x34,0x34,0x33,0x33,0x32,0x32,0x32,0x31,0x31,0x30,
0x30,0x30,0x2f,0x2f,0x2f,0x2e,0x2e,0x2d,0x2d,0x2d,0x2c,0x2c,0x2b,0x2b,0x2b,0x2a,0x2a,0x29,0x29,0x29,
0x28,0x28,0x27,0x27,0x27,0x26,0x26,0x26,0x25,0x25,0x24,0x24,0x24,0x23,0x23,0x22,0x22,0x22,0x21,0x21,
0x20,0x20,0x20,0x1f,0x1f,0x1e,0x1e,0x1e,0x1d,0x1d,0x1d,0x1c,0x1c,0x1b,0x1b,0x1b,0x1a,0x1a,0x19,0x19,
0x19,0x18,0x18,0x17,0x17,0x17,0x16,0x16,0x16,0x15,0x15,0x14,0x14,0x14,0x13,0x13,0x12,0x12,0x12,0x11,
0x11,0x10,0x10,0x10,0xf,0xf,0xe,0xe,0xe,0xd,0xd,0xd,0xc,0xc,0xb,0xb,0xb,0xa,0xa,0x9,
0x9,0x9,0x8,0x8,0x7,0x7,0x7,0x6,0x6,0x5,0x5,0x5,0x4,0x4,0x4,0x3,0x3,0x2,0x2,0x2,
0x1,0x1,0x0,0x0,
};
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, speed=1;
int counter=0;
unsigned int ADC_low, ADC_high;
int sample=0;
int divider=0;
void setup() {
//setup IO
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing else here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
// the input signal is modulated here using a sinewave
ADC_low = map(ADC_low, 0,255, 0, waveform[sample]);
ADC_high = map(ADC_high, 0,255, 0, waveform[sample]);
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
counter++; //to save resources, the pushbuttons are checked every 1000 times.
if(counter==1000)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (speed<1024)speed=speed+1; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (speed>0)speed=speed-1; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
// there is a divider to slow the waveform (otherwise is too fast)
divider++;
if (divider==4){ divider=0; sample=sample+speed;}
if(sample>1023)sample=0;
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

264
c/variable_pitch_shift.ino Normal file
View file

@ -0,0 +1,264 @@
// RING BUFFER VARIABLE PITCH SHIFT
// via www.Electrosmash.com
// via OpenMusicLabs
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
#define BUFF_SIZE 500 // size of ring buffer, can theoretically be anything
// 500 should hold 15.9 ms of audio
//
// STRUCTURES
struct button_time_s
{
long footswitch;
long pb1;
long pb2;
};
struct count_s
{
int main;
int interrupt;
};
struct switch_flag_s
{
bool current;
bool old;
};
struct ring_buff_s
{
int buff[BUFF_SIZE];
int head;
int tail;
};
struct tempo_s
{
int interval;
long timeout;
};
struct divider_s
{
int input;
int output;
};
// VARIABLES
int input, vol_variable=512;
byte ADC_low, ADC_high;
bool led_flag;
int offset = 5;
long milli;
button_time_s button_time;
count_s count;
switch_flag_s switch_flag;
ring_buff_s buf;
divider_s divider;
tempo_s tempo;
// BUFFER FUNCTIONS
void push_to_buff(int in)
{
buf.buff[buf.head] = in;
buf.head++;
if (buf.head == BUFF_SIZE)
{
buf.head = 0;
}
}
int pop_from_buff (void)
{
int out = buf.buff[buf.tail];
if (buf.tail != buf.head)
{
buf.tail++;
}
else
{
buf.buff[buf.tail]--;
}
if (buf.tail == BUFF_SIZE)
{
buf.tail = 0;
}
return out;
}
void setup()
{
//setup IO
Serial.begin(9600);
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
tempo.interval = 150;
divider.input = 0;
divider.output = 9;
}
void tempo_setter()
{
if (milli > tempo.timeout)
{
led_flag = !led_flag;
digitalWrite(LED, led_flag);
tempo.timeout = milli + tempo.interval;
}
}
void tempo_getter()
{
if (digitalRead(PUSHBUTTON_1) == false)
{
if (milli > button_time.pb1)
{
if (milli - button_time.pb1 > 150)
{
tempo.interval = milli - button_time.pb1;
tempo.timeout = milli + tempo.interval;
}
button_time.pb1 = milli;
}
}
}
void pitch_getter()
{
if (digitalRead(PUSHBUTTON_2) == false)
{
if (milli - button_time.pb2 > 150)
{
divider.output++;
if (divider.output > 15)
{
divider.output = 0;
}
if (divider.output == 1)
{
divider.output = 2;
}
button_time.pb2 = milli;
}
}
}
// MAIN LOOP
// checks the footswitch is pushed every 100 loops
// changes the switch_flag
// if switch flag is true call functions
// else just set LED here,
// doesn't need to optimised if no audio is being processed
// increment count
void loop()
{
if (count.main % 100 == 0)
{
switch_flag.current = digitalRead(FOOTSWITCH);
if (switch_flag.current != switch_flag.old)
{
button_time.footswitch = millis();
digitalWrite(LED, true);
Serial.println(button_time.footswitch);
}
switch_flag.old = switch_flag.current;
if (switch_flag.current == true)
{
milli = millis();
pitch_getter();
tempo_getter();
tempo_setter();
}
else
{
digitalWrite(LED, false);
}
}
count.main++;
}
// AUDIO INPUT
// pulls the audio from the ADC
// pushes it to the ring buffer
void audio_inputter(int divide)
{
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
input = ((ADC_high << 8) | ADC_low); // make a signed 16b value
if (input > 0x8000)
{
input = input + 0x8000;
}
push_to_buff(input);
}
// AUDIO OUTPUTTER
// if the eqn is != 0
// pop audio from ring buffer and output to PWM
void audio_outputter(int divide)
{
if (milli - button_time.footswitch > offset)
{
// Serial.println("YE");
if (count.interrupt % divide != 0)
{
int output = pop_from_buff();
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = output; // send out low byt
}
}
}
// TIMER1 INTERRUPT
// checks the switch flag is true
// if LED flag is true, apply effect
// else do not apply effect
ISR(TIMER1_CAPT_vect)
{
if (switch_flag.current == true)
{
if (led_flag == true)
{
audio_inputter(divider.input);
audio_outputter(divider.output);
}
else
{
audio_inputter(0);
audio_outputter(0);
}
count.interrupt++;
}
}

89
c/volume_booster.ino Normal file
View file

@ -0,0 +1,89 @@
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
/* pedalshield_uno_booster.ino reads the ADC and plays it into the PWM output.
* pressing the pushbutton_1 or 2 turns the volume up or down.
*/
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4
//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel
//other variables
int input, vol_variable=10000;
int counter=0;
unsigned int ADC_low, ADC_high;
void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop()
{
//Turn on the LED if the effect is ON.
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//nothing here, all happens in the Timer 1 interruption.
}
ISR(TIMER1_CAPT_vect)
{
// get ADC data
ADC_low = ADCL; // you need to fetch the low byte first
ADC_high = ADCH;
//construct the input sumple summing the ADC low and high byte.
input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
//// All the Digital Signal Processing happens here: ////
counter++; //to save resources, the pushbuttons are checked every 100 times.
if(counter==100)
{
counter=0;
if (!digitalRead(PUSHBUTTON_2)) {
if (vol_variable<32768)vol_variable=vol_variable+10; //increase the vol
digitalWrite(LED, LOW); //blinks the led
}
if (!digitalRead(PUSHBUTTON_1)) {
if (vol_variable>0)vol_variable=vol_variable-10; //decrease vol
digitalWrite(LED, LOW); //blinks the led
}
}
//the amplitude of the input signal is modified following the vol_variable value
input = map(input, -32768, +32768,-vol_variable, vol_variable);
//write the PWM signal
OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
OCR1BL = input; // send out low byte
}

8
rust/.cargo/config.toml Normal file
View file

@ -0,0 +1,8 @@
[build]
target = "avr-atmega328p.json"
[target.'cfg(target_arch = "avr")']
runner = "ravedude uno -cb 57600"
[unstable]
build-std = ["core"]

24
rust/Cargo.toml Normal file
View file

@ -0,0 +1,24 @@
[package]
name = "arduino-pedal"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
panic-halt = "0.2"
avr-device = "*"
arduino-hal = { git = "https://github.com/Rahix/avr-hal", features = ["arduino-uno"], rev = "1aacefb335517f85d0de858231e11055d9768cdf" }
ufmt = "*"
# Configure the build for minimal size - AVRs have very little program memory
[profile.dev]
panic = "abort"
lto = true
opt-level = "s"
[profile.release]
panic = "abort"
codegen-units = 1
debug = true
lto = true
opt-level = "s"

27
rust/avr-atmega328p.json Normal file
View file

@ -0,0 +1,27 @@
{
"arch": "avr",
"atomic-cas": false,
"cpu": "atmega328p",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"eh-frame-header": false,
"exe-suffix": ".elf",
"executables": true,
"late-link-args": {
"gcc": [
"-lgcc"
]
},
"linker": "avr-gcc",
"linker-is-gnu": true,
"llvm-target": "avr-unknown-unknown",
"max-atomic-width": 8,
"no-default-libraries": false,
"pre-link-args": {
"gcc": [
"-mmcu=atmega328p",
"-Wl,--as-needed"
]
},
"target-c-int-width": "16",
"target-pointer-width": "16"
}

4
rust/rust-toolchain.toml Normal file
View file

@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2022-07-08"
components = ["rust-src", "rustfmt"]
profile = "minimal"

31
rust/src/main.rs Normal file
View file

@ -0,0 +1,31 @@
#![no_std]
#![no_main]
use arduino_hal::{delay_ms, pins, Peripherals};
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
// disable interrupts - firmware has panicked so no ISRs should continue running
avr_device::interrupt::disable();
// get the peripherals so we can access serial and the LED.
//
// SAFETY: Because main() already has references to the peripherals this is an unsafe
// operation - but because no other code can run after the panic handler was called,
// we know it is okay.
let dp = unsafe { Peripherals::steal() };
let pins = pins!(dp);
let mut led = pins.d13.into_output();
loop {
led.toggle();
delay_ms(500);
}
}
#[arduino_hal::entry]
fn main() -> ! {
loop {}
}