From 15e543a2e1a813eb503aeb4303f2f27e32535d03 Mon Sep 17 00:00:00 2001 From: Oleksiy Date: Mon, 1 Mar 2021 19:59:24 +0200 Subject: [PATCH] Code cleaned up a little, but 4th pot seems broken --- FM/FM.ino | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/FM/FM.ino b/FM/FM.ino index 2629322..5ac6690 100644 --- a/FM/FM.ino +++ b/FM/FM.ino @@ -13,16 +13,6 @@ MIDI_CREATE_DEFAULT_INSTANCE(); #define MIDI_CHANNEL 3 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; @@ -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 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(); @@ -91,12 +88,14 @@ void updateControl(){ noteOff(rx.byte1 - 127, rx.byte2, rx.byte3); } } while (rx.header != 0); - - 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 3 + int freqVal = mozziAnalogRead(CONTROLL3); // value is 0-1023 + int FRQ = mapThis(freqVal); + + //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 * knob2Val * (kIntensityMod.next()+128))>>8; // shift back to range after 8 bit multiply - + // calculate the fm_intensity + fm_intensity = ((long)Knob1calibrated * knob4calibrated * (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;