Added square ramps to attack, deacay, release and glide, for much precision on small times. Glide would maybe need another value.

pull/1/head
Pierre-Loup Martin 5 years ago
parent 3a22ae1ac9
commit f55c5f7fc0
  1. 60
      minimoog_teensy/minimoog_teensy.ino

@ -86,6 +86,12 @@ const int16_t PITCH_BEND_MIN = -168;
const int16_t PITCH_BEND_MAX = 134; const int16_t PITCH_BEND_MAX = 134;
const int16_t PITCH_BEND_NEUTRAL = PITCH_BEND_MIN + (PITCH_BEND_MAX - PITCH_BEND_MIN) / 2; const int16_t PITCH_BEND_NEUTRAL = PITCH_BEND_MIN + (PITCH_BEND_MAX - PITCH_BEND_MIN) / 2;
const int16_t PITCH_BEND_COURSE = PITCH_BEND_MAX - PITCH_BEND_MIN; const int16_t PITCH_BEND_COURSE = PITCH_BEND_MAX - PITCH_BEND_MIN;
// Maximum attack, decay, release and glide time (in milliseconds)
const float MAX_ATTACK_TIME = 10000;
const float MAX_DECAY_TIME = 10000;
const float MAX_RELEASE_TIME = 10000;
const float MAX_GLIDE_TIME = 10000;
/* /*
// Moved to Mega 1 // Moved to Mega 1
const uint16_t MOD_WHEEL_MIN = 360; const uint16_t MOD_WHEEL_MIN = 360;
@ -111,7 +117,7 @@ uint8_t internalMidiChannel = 1;
uint8_t midiInChannel = 1; uint8_t midiInChannel = 1;
uint8_t midiOutChannel = 1; uint8_t midiOutChannel = 1;
uint16_t glide = 0; float glide = 0;
bool glideEn = 0; bool glideEn = 0;
bool noteRetrigger = 1; bool noteRetrigger = 1;
@ -199,6 +205,8 @@ MIDI_CREATE_DEFAULT_INSTANCE();
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, midi1, midiSettings); MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, midi1, midiSettings);
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial4, midi2, midiSettings); MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial4, midi2, midiSettings);
// for debug purpose, to send to serial the CPU used by audio library.
// Timer timerCPU;
void setup() { void setup() {
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
@ -365,12 +373,26 @@ void setup() {
midi1.sendControlChange(CC_ASK_FOR_DATA, 127, 1); midi1.sendControlChange(CC_ASK_FOR_DATA, 127, 1);
midi2.sendControlChange(CC_ASK_FOR_DATA, 127, 1); midi2.sendControlChange(CC_ASK_FOR_DATA, 127, 1);
/*
timerCPU.init();
timerCPU.setDelay(500);
timerCPU.start(Timer::LOOP);
Serial.print("max CPU usage");
Serial.println(AudioProcessorUsageMax());
*/
} }
void loop() { void loop() {
midi1.read(); midi1.read();
midi2.read(); midi2.read();
usbMIDI.read(midiInChannel); usbMIDI.read(midiInChannel);
/*
if(timerCPU.update()){
Serial.print("cpu usage :");
Serial.println(AudioProcessorUsage());
}
*/
} }
void noteOn(uint8_t note, uint8_t velocity, bool trigger = 1){ void noteOn(uint8_t note, uint8_t velocity, bool trigger = 1){
@ -380,7 +402,8 @@ void noteOn(uint8_t note, uint8_t velocity, bool trigger = 1){
*/ */
nowPlaying = note; nowPlaying = note;
float fineTune = detuneTable[note] * detuneCoeff[detune]; float fineTune = detuneTable[note] * detuneCoeff[detune];
float duration = 1.0 + (float)glideEn * (float)glide * 3.75; // float duration = 1.0 + (float)glideEn * (float)glide * 3.75;
float duration = 1.0 + (float)glideEn * glide * MAX_GLIDE_TIME;
float level = ((float)note + 12 * transpose) * HALFTONE_TO_DC; float level = ((float)note + 12 * transpose) * HALFTONE_TO_DC;
level += fineTune; level += fineTune;
float filterLevel = (((float)note - FILTER_BASE_NOTE) + (12 * transpose)) * FILTER_HALFTONE_TO_DC; float filterLevel = (((float)note - FILTER_BASE_NOTE) + (12 * transpose)) * FILTER_HALFTONE_TO_DC;
@ -669,6 +692,7 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
Serial.println(command); Serial.println(command);
*/ */
uint16_t longValue = 0; uint16_t longValue = 0;
float rampValue = 0;
if(command < 32){ if(command < 32){
ccTempValue[command] = value; ccTempValue[command] = value;
/* /*
@ -682,12 +706,13 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
longValue = (uint16_t)ccTempValue[command - 32]; longValue = (uint16_t)ccTempValue[command - 32];
longValue <<= 7; longValue <<= 7;
longValue += value; longValue += value;
rampValue = pow((float)longValue / RESO, 2);
/* /*
Serial.print("value : "); Serial.print("value : ");
Serial.println(longValue); Serial.println(longValue);
Serial.print(" (sent : "); Serial.print("ramp value : ");
Serial.print(value); Serial.println(rampValue * 1000);
Serial.println(')'); Serial.println();
*/ */
} else { } else {
/* /*
@ -788,7 +813,8 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
break; break;
case CC_PORTAMENTO_TIME_LSB: case CC_PORTAMENTO_TIME_LSB:
// CC_37 // CC_37
glide = longValue; // glide = longValue;
glide = rampValue;
break; break;
case CC_CHANNEL_VOL_LSB: case CC_CHANNEL_VOL_LSB:
// CC_39 // CC_39
@ -861,11 +887,15 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
break; break;
case CC_FILTER_ATTACK_LSB: case CC_FILTER_ATTACK_LSB:
// CC_55 // CC_55
filterEnvelope.attack(1 + (float)longValue * 5.0); // original : linear attack
// filterEnvelope.attack(1 + (float)longValue * 5.0);
filterEnvelope.attack(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_FILTER_DECAY_LSB: case CC_FILTER_DECAY_LSB:
// CC_56 // CC_56
filterEnvelope.decay((float)longValue * 5.0); // filterEnvelope.decay((float)longValue * 5.0);
filterEnvelope.decay(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_FILTER_SUSTAIN_LSB: case CC_FILTER_SUSTAIN_LSB:
// CC_57 // CC_57
@ -873,15 +903,18 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
break; break;
case CC_FILTER_RELEASE_LSB: case CC_FILTER_RELEASE_LSB:
// CC_58 // CC_58
filterEnvelope.release(1 + (float)longValue * 5.0); // filterEnvelope.release(1 + (float)longValue * 5.0);
filterEnvelope.release(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_EG_ATTACK_LSB: case CC_EG_ATTACK_LSB:
// CC_59 // CC_59
mainEnvelope.attack(1 + (float)longValue * 5.0); // mainEnvelope.attack(1 + (float)longValue * 5.0);
mainEnvelope.attack(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_EG_DECAY_LSB: case CC_EG_DECAY_LSB:
// CC_60 // CC_60
mainEnvelope.decay((float)longValue * 5.0); // mainEnvelope.decay((float)longValue * 5.0);
mainEnvelope.decay(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_EG_SUSTAIN_LSB: case CC_EG_SUSTAIN_LSB:
// CC_61 // CC_61
@ -889,7 +922,8 @@ void handleControlChange(uint8_t channel, uint8_t command, uint8_t value){
break; break;
case CC_EG_RELEASE_LSB: case CC_EG_RELEASE_LSB:
// CC_62 // CC_62
mainEnvelope.release(1 + (float)longValue * 5.0); // mainEnvelope.release(1 + (float)longValue * 5.0);
mainEnvelope.release(rampValue * MAX_ATTACK_TIME);
break; break;
case CC_LFO_RATE_LSB: case CC_LFO_RATE_LSB:
// CC_63 // CC_63

Loading…
Cancel
Save