I am using the MOZZI audio library to implement a simple synthesizer and I cant work out what I am doing wrong when trying to implement a volume control. I have tried implementing it in the way explained in the example on the MOZZI website (scroll down to the one named Volume_Control) and all that happens is I get no audio output at all. If anyone could have a look at my code and see if they notice any glaringly obvious mistakes I would really appreciate it as I am stuck and not really sure how to proceed.
//#include <ADC.h> // Teensy 3.1 uncomment this line and install http://github.com/pedvide/ADC
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/saw2048_int8.h> // saw table for oscillator
#include <tables/sin2048_int8.h> // saw table for oscillator
#include <LowPassFilter.h>
//#include <tables/saw1024_int8.h> // saw table for oscillator
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> aSaw(SAW2048_DATA);
Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> bSaw(SAW2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
//LowPassFilter lpf; //for implementing my LPF
// use #define for CONTROL_RATE, not a constant
#define CONTROL_RATE 64 // powers of 2 please
const char INPUT_PIN0 = 0;
const char INPUT_PIN1 = 1;
const char INPUT_PIN2 = 2;
byte pitch;
byte vol;
byte detune;
void setup(){
Serial.begin(115200);
startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
}
void updateControl(){
int pitch = mozziAnalogRead(INPUT_PIN0); //assign variables to analog pin
int vol = mozziAnalogRead(INPUT_PIN2);
int detune = mozziAnalogRead(INPUT_PIN1);
pitch = map(pitch, 0, 1023, 65, 262); // map the pot range (0-1023 to a new set of values)
vol = map(vol, 0, 1023, 0, 255);
detune = map(detune, 0, 1023, 0, 100);
detune = (detune*0.05);
aSaw.setFreq(pitch); //assign variables to oscilator parameters
bSaw.setFreq(pitch * detune);
aSin.setFreq((pitch)/2);
Serial.print("vol = ");
Serial.println((int)vol);
}
int updateAudio(){
return ((
((int)aSin.next())
+
((int)aSaw.next() * 0.5)
+
((int)bSaw.next() * 0.5)
) * (vol>>8));
}
void loop(){
audioHook(); // required here
}