livingsteel
New member
Hi!
I am trying to put together an effect unit that can process incoming audio with a variety of effects. I am using a teensy 4.1 with audio adapter and a 4067 multiplexer in the arduino ide. I have 16 pots connected to the multiplexer along with 4 toggle buttons connected to the teensy pins. I am using the pot readings to control the parameters of the effects and using the buttons to turn them on or off. I have successfully read the incoming signals from the 4067 and printed them to serial. The function muxRead () in my code works well. I have also successfully read the high and low states of the buttons and they effect the audio appropriately. The big problem I'm having is that I cannot figure out how to combine the muxRead () function with my button update code. The buttons work if I have disabled the muxRead () portion of the code but then I have no pot information. The muxRead () function works if I have disabled the button update code. That is my problem in a nutshell. If there is any generous soul out there who could take a look at my code and let me know what is going wrong, I would really appreciate it. THANKS!
I am trying to put together an effect unit that can process incoming audio with a variety of effects. I am using a teensy 4.1 with audio adapter and a 4067 multiplexer in the arduino ide. I have 16 pots connected to the multiplexer along with 4 toggle buttons connected to the teensy pins. I am using the pot readings to control the parameters of the effects and using the buttons to turn them on or off. I have successfully read the incoming signals from the 4067 and printed them to serial. The function muxRead () in my code works well. I have also successfully read the high and low states of the buttons and they effect the audio appropriately. The big problem I'm having is that I cannot figure out how to combine the muxRead () function with my button update code. The buttons work if I have disabled the muxRead () portion of the code but then I have no pot information. The muxRead () function works if I have disabled the button update code. That is my problem in a nutshell. If there is any generous soul out there who could take a look at my code and let me know what is going wrong, I would really appreciate it. THANKS!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#include "effect_platervbstereo.h"
// GUItool: begin automatically generated code
AudioInputI2S i2s2; //xy=169,883
AudioMixer4 mixer1; //xy=614,739
AudioEffectChorus chorus1; //xy=620,875
AudioEffectChorus chorus2; //xy=621,813
AudioEffectPlateReverb verb1; //xy=621,813
AudioMixer4 mixer4; //xy=626,1023
AudioMixer4 mixer2; //xy=835,851
AudioMixer4 mixer3; //xy=863,947
AudioEffectGranular granular1; //xy=888,744
AudioEffectFreeverb freeverb1; //xy=929,1036
AudioMixer4 mixer5; //xy=1092,881
AudioFilterStateVariable filter1; //xy=1236,881
AudioSynthWaveformSine sine1;
AudioConnection patchCord23(sine1, 0, filter1, 1);
AudioOutputI2S i2s1; //xy=1367,884
AudioConnection patchCord1(i2s2, 0, mixer1, 0);
AudioConnection patchCord2(i2s2, 0, mixer4, 0);
AudioConnection patchCord3(i2s2, 0, chorus1, 0);
AudioConnection patchCord21(i2s2, 0, verb1, 0);
AudioConnection patchCord22(i2s2, 1, verb1, 1);
AudioConnection patchCord4(i2s2, 1, mixer1, 1);
AudioConnection patchCord5(i2s2, 1, mixer4, 1);
AudioConnection patchCord6(i2s2, 1, chorus2, 0);
AudioConnection patchCord7(mixer1, granular1);
AudioConnection patchCord8(chorus2, 0, mixer2, 1);
AudioConnection patchCord9(chorus1, 0, mixer2, 0);
AudioConnection patchCord19(verb1, 0, mixer3, 0);
AudioConnection patchCord20(verb1, 1, mixer3, 1);
AudioConnection patchCord10(mixer4, freeverb1);
AudioConnection patchCord11(mixer2, 0, mixer5, 1);
AudioConnection patchCord12(mixer3, 0, mixer5, 2);
AudioConnection patchCord13(granular1, 0, mixer5, 0);
AudioConnection patchCord14(freeverb1, 0, mixer5, 3);
AudioConnection patchCord15(mixer5, 0, filter1, 0);
AudioConnection patchCord16(mixer5, 0, filter1, 1);
AudioConnection patchCord17(filter1, 0, i2s1, 0);
AudioConnection patchCord18(filter1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=678,1182
// GUItool: end automatically generated code
const int myInput = AUDIO_INPUT_LINEIN;
#define chorusDelayLength (16*AUDIO_BLOCK_SAMPLES) // Number of samples in each delay line
short l_delayline[chorusDelayLength]; // Allocate the delay lines for left and right channels
short r_delayline[chorusDelayLength];
int n_chorus = 2; // number of "voices" in the chorus including the original voice
bool chorusActive = false; // track if chorus effect is on or off
#define GRANULAR_MEMORY_SIZE 12800 // enough for 290 ms at 44.1 kHz
int16_t granularMemory[GRANULAR_MEMORY_SIZE];
#define PASSTHRU_PIN 1
Bounce b_passthru = Bounce(PASSTHRU_PIN,15);
#define MS0 31 //These pins are connected to S0-S3 and Z on the 4067 multiplexer
#define MS1 30
#define MS2 29
#define MS3 28
#define MZ A13
#define MnumControls 16
//#define Button0 33
//#define Button1 34
//#define Button2 35
//#define Button3 36
#define MUXchorus_1 0
#define MUXchorus_2 1
#define MUXfilterRes 2
#define MUXfilterFreq 3
#define MUXlfo_1Freq 4
#define MUXlfo_1Amp 5
#define MUXplate_1 6
#define MUXplate_2 7
#define MUXplate_3 8
#define MUXplate_4 9
#define MUXplate_5 10
#define MUXfreeverb_1 11
#define MUXfreeverb_2 12
#define MUXgranular_1 13
#define MUXgranular_2 14
#define MUXflange_3 15
//#define button0 33
//#define button1 34
//#define button2 35
//#define button3 36
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Bounce button0 = Bounce(33, 15);
Bounce button1 = Bounce(34, 15);
Bounce button2 = Bounce(35, 15);
Bounce button3 = Bounce(36, 15);
void setup() {
Serial.begin(9600);
AudioMemory(18);
pinMode(MS0, OUTPUT);
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(MS3, OUTPUT);
pinMode(33, INPUT_PULLDOWN);
pinMode(34, INPUT_PULLDOWN);
pinMode(35, INPUT_PULLDOWN);
pinMode(36, INPUT_PULLDOWN);
sgtl5000_1.enable();
sgtl5000_1.volume(0.7);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
mixer2.gain(0, 0.5);
mixer2.gain(1, 0.5);
mixer3.gain(0, 0.5);
mixer3.gain(1, 0.5);
mixer4.gain(0, 0.5);
mixer4.gain(1, 0.5);
mixer5.gain(0, 0.5);
mixer5.gain(1, 0.5);
// the Granular effect requires memory to operate
granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
if (!chorus1.begin(r_delayline, chorusDelayLength, n_chorus)) {
Serial.println("AudioEffectChorus - left channel begin failed");
while (1);
}
Serial.println("done.");
// initially the effect is off.
chorus1.voices(0);
chorus2.voices(0);
Serial.println("Waiting for control input...");
// reset audio resource usage stats.
// useful if tracking max usage in main program
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
}
void loop() {
checkMux ();
button0.update();
button1.update();
button2.update();
button3.update();
if (button1.risingEdge()) {
mixer4.gain(0, .5);
mixer4.gain(1, .5);
Serial.print("Reverb: mix=");
Serial.print(MUXfreeverb_1 * 100.0);
Serial.print("%, roomsize=");
Serial.print(MUXfreeverb_1 * 100.0);
Serial.print("%, damping=");
Serial.print(MUXfreeverb_2 * 100.0);
Serial.print("%, CPU Usage=");
Serial.print(MUXfreeverb_1);
Serial.println("%");
}
if (button1.fallingEdge()) {
freeverb1.roomsize(0);
freeverb1.damping(0);
mixer4.gain(1, 0);
mixer4.gain(0, 0);
Serial.print("stop reverb");
}
/* if (button0.fallingEdge()) {
granular1.beginPitchShift(msec);
mixer1.gain(0, .5);
mixer1.gain(1, .5);
Serial.print("Begin granular pitch phift using ");
Serial.print(MUXgranular_1);
Serial.println(" grains");
}
if (button0.risingEdge()) {
granular1.stop();
mixer1.gain(0, .0);
mixer1.gain(1, .0);
Serial.println(" pitch stop");
}/*/
if (button2.risingEdge()) {
mixer2.gain(0, .5);
mixer2.gain(1, .5);
Serial.print("chorus");
chorus1.begin(l_delayline, chorusDelayLength, n_chorus);
chorus2.begin(l_delayline, chorusDelayLength, n_chorus);
chorusActive = !chorusActive;
}
if (button2.fallingEdge()) {
mixer2.gain(0, 0);
mixer2.gain(1, 0);
Serial.print("chorus stop");
}
if (button3.risingEdge()) {
mixer3.gain(0, .5);
mixer3.gain(1, .5);
Serial.print("plate");
}
if (button3.fallingEdge()) {
mixer3.gain(0, 0);
mixer3.gain(1, 0);
Serial.print("plate stop");
}
}
void checkMux() {
static byte muxInput = 0;
static int muxValues[MnumControls] = {};
unsigned long currentMicros = micros();
if (currentMicros >= 1000) {
float muxRead = (float)analogRead(MZ) / 1023;
muxValues[muxInput] = muxRead;
switch (muxInput) {
case MUXfreeverb_1:
freeverb1.roomsize(muxRead);
Serial.print("freeverb= ");
Serial.print(muxRead);
break;
case MUXfreeverb_2:
freeverb1.damping(muxRead);
Serial.print("freeverb2= ");
Serial.print(muxRead);
break;
case MUXplate_1:
verb1.size(muxRead);
Serial.print("plate1= ");
Serial.print(muxRead);
break;
case MUXplate_2:
verb1.lodamp(muxRead);
Serial.print("plate2= ");
Serial.print(muxRead);
break;
case MUXplate_3:
verb1.lowpass(muxRead);
Serial.print("plate3= ");
Serial.print(muxRead);
break;
case MUXplate_4:
verb1.hidamp(muxRead);
Serial.print("plate4= ");
Serial.print(muxRead);
break;
case MUXplate_5:
verb1.diffusion(muxRead);
Serial.print("plate5= ");
Serial.print(muxRead);
break;
/*case MUXchorus_1:
int(ottowa) = int(muxRead * 10);
Serial.print("chorus1= ");
Serial.print(muxRead);
break;
case MUXchorus_2:
short(manitoba) = short(muxRead * 16);
Serial.print("chorus2= ");
Serial.print(manitoba);
break;/*
case MUXgranular_1:
float(msec) = float(25.0 + (muxRead * 75.0));
Serial.print("gran1= ");
Serial.print(msec);
break;
case MUXgranular_2:
granular1.setSpeed(powf(2.0, muxread * 2.0 - 1.0);
Serial.print("gran2= ");
Serial.print(Ratio);
break;/*/
case MUXfilterRes:
//muxRead = muxRead * 5;
filter1.resonance(muxRead * 5);
Serial.print("filterres= ");
Serial.print(muxRead);
break;
case MUXfilterFreq:
//muxRead = muxRead * 1000;
filter1.frequency(muxRead * 1000);
Serial.print("filterfreq= ");
Serial.print(muxRead);
break;
case MUXlfo_1Freq:
//muxRead = muxRead * 10;
sine1.frequency(muxRead * 10);
Serial.print("lfofreq= ");
Serial.print(muxRead);
case MUXlfo_1Amp:
sine1.amplitude(muxRead);
Serial.print("lfoamop= ");
Serial.print(muxRead);
}
muxInput++;
if (muxInput >= MnumControls) muxInput = 0;
digitalWrite(MS0, muxInput & B0001);
digitalWrite(MS1, muxInput & B0010);
digitalWrite(MS2, muxInput & B0100);
digitalWrite(MS3, muxInput & B1000);
}
}