Compare commits
4 Commits
29e5c12777
...
WIP
| Author | SHA1 | Date | |
|---|---|---|---|
| d084cc9912 | |||
| 75f3211629 | |||
| 7e4c0c62b7 | |||
| 41403c9817 |
@ -7,8 +7,9 @@
|
||||
// This code is licenced under GPL v3 or later
|
||||
|
||||
// todo:
|
||||
// debug accent handling that overloads the filter
|
||||
// debug accent handling that overloads the filter, also accent can be too short or too long if it's relying on midi note
|
||||
// add overdrive
|
||||
// frequency from CV (noteFreq) could be Q16n16 for consistency
|
||||
|
||||
#include <Mozzi.h>
|
||||
#include <MIDI.h>
|
||||
@ -98,12 +99,13 @@ Oscil <SAW_MAX_8192_AT_16384_512_NUM_CELLS, MOZZI_AUDIO_RATE> aSaw8192(SAW_MAX_8
|
||||
MetaOscil<SAW_MAX_138_AT_16384_512_NUM_CELLS, MOZZI_AUDIO_RATE, 16> aSaw {&aSaw138, &aSaw154, &aSaw182, &aSaw240, &aSaw292, &aSaw341, &aSaw390, &aSaw431, &aSaw512, &aSaw630, &aSaw744, &aSaw1170, &aSaw1638, &aSaw2730, &aSaw4096, &aSaw8192};
|
||||
|
||||
IntMap kMapNote( 0, 4095, 24 * pitchSubSteps, 84 * pitchSubSteps );
|
||||
IntMap kMapResonance( 0, 1023, 0, 255 );
|
||||
IntMap kMapCutoff( 0, 1023, 26, 100 );
|
||||
IntMap kMapAttack( 0, 1023, 3, 100 );
|
||||
IntMap kMapDecay( 0, 1023, 200, 2000 );
|
||||
IntMap kMapEnvMod( 0, 1023, 0, 160 );
|
||||
IntMap kMapEnvMod( 0, 1023, 0, 140 );
|
||||
IntMap kMapResonance( 0, 1023, 0, 255 );
|
||||
IntMap kMapDrive( 0, 1023, 0, 400 );
|
||||
IntMap kMapAttack( 0, 1023, 1, 100 );
|
||||
IntMap kMapDecay( 0, 1023, 100, 1500 );
|
||||
IntMap kMapAccentLevel( 0, 1023, 0, 128 );
|
||||
|
||||
Ead kEnvelope(MOZZI_CONTROL_RATE);
|
||||
LowPassFilter lpfr;
|
||||
@ -114,7 +116,7 @@ byte gain;
|
||||
bool MIDINotePlaying;
|
||||
bool MIDINoteFaded = true;
|
||||
bool gateIsHigh = false;
|
||||
Q16n16 noteFreq;
|
||||
float noteFreq;
|
||||
bool envSwitchVal;
|
||||
bool droneSwitchVal;
|
||||
byte MIDIChannel;
|
||||
@ -123,11 +125,10 @@ int driveAmount;
|
||||
byte notePlaying;
|
||||
bool accent = false;
|
||||
|
||||
|
||||
void MIDINoteOn(byte channel, byte note, byte velocity) {
|
||||
notePlaying = note;
|
||||
noteFreq = Q16n16_mtof((int) note);
|
||||
|
||||
accent = false; //reset if the previous note was accented
|
||||
if (velocity >= 127) {
|
||||
accent = true;
|
||||
}
|
||||
@ -150,7 +151,6 @@ void MIDINoteOff(byte channel, byte note, byte velocity) {
|
||||
if (note == notePlaying || !droneSwitchVal) {
|
||||
MIDINotePlaying = false;
|
||||
digitalWrite(LED, HIGH);
|
||||
accent = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,14 +269,17 @@ void updateControl(){
|
||||
int CVInVal = mozziAnalogRead(CVIn);
|
||||
|
||||
//Remap the values and assign to parameters
|
||||
int cutoff = accent? 100 : kMapCutoff(knob1Val);
|
||||
int resonance = accent? 255 : kMapResonance(knob2Val);
|
||||
int accentLevel = kMapAccentLevel(knobSVal);
|
||||
int baseCutoff = kMapCutoff(knob1Val);
|
||||
int cutoff = accent? (baseCutoff + (((long)accentLevel * (100 - baseCutoff)) >> 7)) : baseCutoff;
|
||||
int resonance = accent? (255 - (((long)(128 - accentLevel) * (255 - kMapResonance(knob2Val))) >> 7)) : kMapResonance(knob2Val);
|
||||
int envMod = kMapEnvMod(knob3Val);
|
||||
driveAmount = kMapDrive(knob4Val);
|
||||
|
||||
|
||||
//Set pitch and play notes on trigger
|
||||
if (MIDINoteFaded) {
|
||||
noteFreq = Q16n16_mtof((float) kMapNote(CVInVal << 2) / pitchSubSteps);
|
||||
noteFreq = mtof((float) kMapNote(CVInVal << 2) / pitchSubSteps);
|
||||
digitalWrite(LED, !gateInVal);
|
||||
if (gateInVal && !gateIsHigh) {
|
||||
gateIsHigh = true;
|
||||
@ -288,29 +291,35 @@ void updateControl(){
|
||||
|
||||
//Update Envelope Settings
|
||||
int attackTime = kMapAttack(knobAVal);
|
||||
int decayReleaseTime = kMapDecay(knobDRVal);
|
||||
kEnvelope.setDecay(accent? 400 : decayReleaseTime);
|
||||
kEnvelope.setAttack(accent? 3 : attackTime);
|
||||
int baseDecay = kMapDecay(knobDRVal);
|
||||
int decayTime = accent? (100 + (((long)(128 - accentLevel) * (baseDecay - 100)) >> 7)) : baseDecay;
|
||||
kEnvelope.setDecay(decayTime);
|
||||
kEnvelope.setAttack(accent? 1 : attackTime);
|
||||
|
||||
//Calculate makeup Gain
|
||||
//makeupGain = (256L * 127) / (127 + driveAmount); // Q8 fixed-point compensation factor
|
||||
//makeupGain = ((long)256 * 127) / (127 + driveAmount);
|
||||
|
||||
//Set Oscilator Frequency
|
||||
Q16n16 oscFreq;
|
||||
oscFreq = kGlide.next();
|
||||
aSquare.setFreq_Q16n16(oscFreq);
|
||||
aSaw.setFreq_Q16n16(oscFreq);
|
||||
if (!MIDINoteFaded) {
|
||||
oscFreq = kGlide.next();
|
||||
aSquare.setFreq_Q16n16(oscFreq);
|
||||
aSaw.setFreq_Q16n16(oscFreq);
|
||||
} else {
|
||||
aSquare.setFreq(noteFreq);
|
||||
aSaw.setFreq(noteFreq);
|
||||
}
|
||||
|
||||
int env = kEnvelope.next();
|
||||
|
||||
if (!MIDINotePlaying && !MIDINoteFaded && env == 0) { //threshhold might need adjustment
|
||||
if (!MIDINotePlaying && !MIDINoteFaded && env == 0) {
|
||||
MIDINoteFaded = true;
|
||||
accent = false;
|
||||
}
|
||||
|
||||
gain = accent? env * 2 : env;
|
||||
gain = accent? constrain(env + (((long)env * accentLevel) >> 7), 0, 255) : env; //needs finetuning
|
||||
|
||||
lpfr.setCutoffFreqAndResonance(constrain(cutoff + (((long)env * envMod * cutoff)>>16), 0, 255), resonance);
|
||||
|
||||
}
|
||||
|
||||
AudioOutput updateAudio(){
|
||||
@ -320,8 +329,9 @@ AudioOutput updateAudio(){
|
||||
} else {
|
||||
signal = aSaw.next();
|
||||
}
|
||||
signal = signal >> 2; //lowering the gain before filter to avoid filter overflow bug
|
||||
signal = lpfr.next(signal); //filter
|
||||
signal = (signal * gain); //envelope
|
||||
signal = (signal * gain) << 2; //envelope
|
||||
//signal = softClip((signal * (127 + driveAmount)) >> 9); //overdrive
|
||||
//signal = (signal * makeupGain) >> 7; //makeup gain compensation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user