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