Code cleaned up a little, but 4th pot seems broken

This commit is contained in:
Oleksiy 2021-03-01 19:59:24 +02:00
parent e2cc163eca
commit 15e543a2e1
1 changed files with 22 additions and 29 deletions

View File

@ -14,16 +14,6 @@ MIDI_CREATE_DEFAULT_INSTANCE();
bool gate = 0;
// desired carrier frequency max and min, for AutoMap
const int MIN_CARRIER_FREQ = 22;
const int MAX_CARRIER_FREQ = 440;
const int MIN = 10;
const int MAX = 1;
const int MIN_2 = 1;
const int MAX_2 = 15;
// desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics
const int MIN_INTENSITY = 700;
const int MAX_INTENSITY = 10;
@ -32,7 +22,12 @@ const int MAX_INTENSITY = 10;
const int MIN_MOD_SPEED = 10000;
const int MAX_MOD_SPEED = 1;
AutoMap kMapCarrierFreq(0,1023,MIN_CARRIER_FREQ,MAX_CARRIER_FREQ);
const int MIN = 10;
const int MAX = 1;
const int MIN_2 = 1;
const int MAX_2 = 15;
AutoMap kMapIntensity(0,1023,MIN_INTENSITY,MAX_INTENSITY);
AutoMap kMapModSpeed(0,1023,MIN_MOD_SPEED,MAX_MOD_SPEED);
AutoMap mapThis(0,1023,MIN,MAX);
@ -55,7 +50,7 @@ long fm_intensity; // carries control info from updateControl to updateAudio
float smoothness = 0.95f;
Smooth <long> aSmoothIntensity(smoothness);
int carrier_freq = 440;
int carrier_freq;
void noteOn(byte channel, byte note, byte velocity) {
if (channel == MIDI_CHANNEL) {
@ -76,12 +71,14 @@ void setup(){
startMozzi();
//MIDI DIN
MIDI.setHandleNoteOn(noteOn);
MIDI.setHandleNoteOff(noteOff);
MIDI.begin(MIDI_CHANNEL);
}
void updateControl(){
//MIDI USB
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
@ -92,11 +89,13 @@ void updateControl(){
}
} while (rx.header != 0);
int freqVal = mozziAnalogRead(CONTROLL3); // value is 0-1023
int FRQ = mapThis(freqVal);
//Knob 3
int freqVal = mozziAnalogRead(CONTROLL3); // value is 0-1023
int FRQ = mapThis(freqVal);
int knob2 = mozziAnalogRead(CONTROLL4); // value is 0-1023
int knob2Val = mapThis(knob2);
//Knob 4
int knob4 = mozziAnalogRead(CONTROLL4); // value is 0-1023
int knob4calibrated = mapThis(knob4);
//calculate the modulation frequency to stay in ratio
int mod_freq = carrier_freq * mod_ratio * FRQ;
@ -105,31 +104,25 @@ void updateControl(){
aCarrier.setFreq(carrier_freq);
aModulator.setFreq(mod_freq);
// read the light dependent resistor on the width Analog input pin
int Knob1value= mozziAnalogRead(CONTROLL1); // value is 0-1023
int Knob1calibrated = kMapIntensity(Knob1value);
// calculate the fm_intensity
fm_intensity = ((long)Knob1calibrated * knob4calibrated * (kIntensityMod.next()+128))>>8; // shift back to range after 8 bit multiply
// calculate the fm_intensity
fm_intensity = ((long)Knob1calibrated * knob2Val * (kIntensityMod.next()+128))>>8; // shift back to range after 8 bit multiply
// read the light dependent resistor on the speed Analog input pin
// Knob 2
int Knob2value= mozziAnalogRead(CONTROLL2); // value is 0-1023
// use a float here for low frequencies
float mod_speed = (float)kMapModSpeed(Knob2value)/1000;
kIntensityMod.setFreq(mod_speed);
//MIDI DIN
MIDI.read();
}
int updateAudio(){
AudioOutput_t updateAudio(){
long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next();
if (gate == 1) {
return aCarrier.phMod(modulation);//(int)(envelope.next() * aCarrier.phMod(modulation))>>8;