halogravity
Well-known member
Hey guys, quick question. The synth is coming along swimmingly. I have 8 arcade buttons two pots and a OLED working great, the only issue is when I change the attack and release of a notes envelope I have to hit all the buttons once to update the settings. Can someone tell me where my logic is flawed here? I have the synth architecture in a separate file, if anyone would like to see that I'll post it as well. Also there is some stuff floating around in there that hasn't been completely implemented yet (mostly the array stuff, which I'm still learning).
Code:
#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SynthArch.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);
Bounce button2 = Bounce(2, 15);
Bounce button3 = Bounce(3, 15);
Bounce button4 = Bounce(4, 15);
Bounce button5 = Bounce(5, 15);
Bounce button6 = Bounce(14, 15);
Bounce button7 = Bounce(16, 15);
#define NPROGS 8
uint8_t progs[NPROGS] = {
WAVEFORM_SINE,
WAVEFORM_SQUARE,
WAVEFORM_TRIANGLE,
WAVEFORM_SAWTOOTH,
WAVEFORM_SAWTOOTH_REVERSE,
WAVEFORM_PULSE,
WAVEFORM_SAMPLE_HOLD,
WAVEFORM_ARBITRARY,
};
int scale;
float noteFrequencies[8][8] = {
//Amin
{220.00,246.94,261.63,293.66,329.63,349.23,392.00,440.00},
//Bmin
{246.94,277.18,293.66,329.63,369.99,392.00,440.00,493.88},
//Cmin
{261.63,293.66,311.13,349.23,392.00,415.30,466.16,523.25},
//Dmin
{293.66,329.63,349.23,392.00,440.00,466.16,523.25,587.33},
//Emin
{329.63,369.99,392.00,440.00,493.88,523.25,587.33,659.25},
//Fmin
{349.23,392.00,415.30,466.16,523.25,554.37,622.25,698.46},
//Gmin
{392.00,440.00,466.16,523.25,587.33,622.25,698.46,783.99},
//Chrom
{220.00,233.08,246.94,261.63,277.18,293.66,311.13,329.63},
};
const byte BUFFER = 8;
float attack = 50;
float decay = 150;
float sustain = 0.8;
float release = 550;
int numNotes = 8;
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("PANDA SYNTH");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.println("V.0.0.1 BETA");
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("PANDA LABS");
display.display();
delay(2000);
display.clearDisplay();
AudioMemory(50);
sgtl5000_1.enable();
// Full volume is 1.0 which will damage speakers or ears in most cases
sgtl5000_1.volume(0.4);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
float mixgain = 0.8;
mixerL.gain(0, mixgain);
mixerL.gain(1, mixgain);
mixerL.gain(2, mixgain);
mixerL.gain(3, mixgain);
mixerR.gain(0, mixgain);
mixerR.gain(1, mixgain);
mixerR.gain(2, mixgain);
mixerR.gain(3, mixgain);
mixerFinal.gain(0, mixgain);
mixerFinal.gain(1, mixgain);
envelope1.attack(attack);
envelope1.decay(decay);
envelope1.sustain(sustain);
envelope1.release(release);
envelope2.attack(attack);
envelope2.decay(decay);
envelope2.sustain(sustain);
envelope2.release(release);
envelope3.attack(attack);
envelope3.decay(decay);
envelope3.sustain(sustain);
envelope3.release(release);
envelope4.attack(attack);
envelope4.decay(decay);
envelope4.sustain(sustain);
envelope4.release(release);
envelope5.attack(attack);
envelope5.decay(decay);
envelope5.sustain(sustain);
envelope5.release(release);
envelope6.attack(attack);
envelope6.decay(decay);
envelope6.sustain(sustain);
envelope6.release(release);
envelope7.attack(attack);
envelope7.decay(decay);
envelope7.sustain(sustain);
envelope7.release(release);
envelope8.attack(attack);
envelope8.decay(decay);
envelope8.sustain(sustain);
envelope8.release(release);
//Change var prognum to change wave & amplitude
int prognum = 3;
float progamp = 0.7;
waveform1.begin(progamp, 220.00, progs[prognum]);
waveform2.begin(progamp, 220.00, progs[prognum]);
waveform3.begin(progamp, 220.00, progs[prognum]);
waveform4.begin(progamp, 220.00, progs[prognum]);
waveform5.begin(progamp, 220.00, progs[prognum]);
waveform6.begin(progamp, 220.00, progs[prognum]);
waveform7.begin(progamp, 220.00, progs[prognum]);
waveform8.begin(progamp, 220.00, progs[prognum]);
// waveform10.begin(0.6, 220.00, WAVEFORM_TRIANGLE);
// waveform11.begin(0.6, 220.00, WAVEFORM_TRIANGLE);
// waveform12.begin(0.6, 220.00, WAVEFORM_TRIANGLE);
// noise4.amplitude(0.7);
}
void loop() {
int knob1 = 11880 * analogRead(A7) / 1023;
int knob2 = 11880 * analogRead(A6) / 1023;
AudioNoInterrupts();
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
AudioInterrupts();
if (button0.fallingEdge()) {
envelope1.noteOn();
envelope1.attack(knob1);
envelope1.release(knob2);
waveform1.frequency(220.00);
}
if (button0.risingEdge()) {
envelope1.noteOff();
}
if (button1.fallingEdge()) {
envelope2.noteOn();
envelope2.attack(knob1);
envelope2.release(knob2);
waveform2.frequency(246.94);
}
if (button1.risingEdge()) {
envelope2.noteOff();
}
if (button2.fallingEdge()) {
envelope3.noteOn();
envelope3.attack(knob1);
envelope3.release(knob2);
waveform3.frequency(261.63);
}
if (button2.risingEdge()) {
envelope3.noteOff();
}
if (button3.fallingEdge()) {
envelope4.noteOn();
envelope4.attack(knob1);
envelope4.release(knob2);
waveform4.frequency(293.66);
}
if (button3.risingEdge()) {
envelope4.noteOff();
}
if (button4.fallingEdge()) {
envelope5.noteOn();
envelope5.attack(knob1);
envelope5.release(knob2);
waveform5.frequency(329.63);
}
if (button4.risingEdge()) {
envelope5.noteOff();
}
if (button5.fallingEdge()) {
envelope6.noteOn();
envelope6.attack(knob1);
envelope6.release(knob2);
waveform6.frequency(349.23);
}
if (button5.risingEdge()) {
envelope6.noteOff();
}
if (button6.fallingEdge()) {
envelope7.noteOn();
envelope7.attack(knob1);
envelope7.release(knob2);
waveform7.frequency(392.00);
}
if (button6.risingEdge()) {
envelope7.noteOff();
}
if (button7.fallingEdge()) {
envelope8.noteOn();
envelope8.attack(knob1);
envelope8.release(knob2);
waveform8.frequency(440.00);
}
if (button7 .risingEdge()) {
envelope8.noteOff();
}
}