Improved moving threshold behavior

This commit is contained in:
Brian Hrebec 2024-08-20 23:08:37 -05:00
parent 90077f7a4e
commit e8aeb26399

View file

@ -777,8 +777,6 @@ void noteOn(int fingeredNote, int pressureSensor, int initial_breath_value) {
} else { } else {
velocitySend = state.currentPreset->fixedVelocity; velocitySend = state.currentPreset->fixedVelocity;
} }
Serial.print(">velocity:");
Serial.println(velocitySend);
midiSendNoteOn(fingeredNote, velocitySend); // send Note Off message midiSendNoteOn(fingeredNote, velocitySend); // send Note Off message
} }
@ -892,7 +890,6 @@ void readBreath() {
int16_t breathAltSignal = constrain(readAltPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT) + instrument.breathAltZeroOffset; int16_t breathAltSignal = constrain(readAltPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT) + instrument.breathAltZeroOffset;
int16_t spikeSignal = constrain(readSpikePressure(), -SPIKE_HI_LIMIT, SPIKE_HI_LIMIT); int16_t spikeSignal = constrain(readSpikePressure(), -SPIKE_HI_LIMIT, SPIKE_HI_LIMIT);
int16_t diffSignal = breathAltSignal - breathSignal; int16_t diffSignal = breathAltSignal - breathSignal;
int16_t halfOffset = state.calibration->breathThrValOffset / 2;
if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset->breathMode == BREATH_ACC_AT) { if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset->breathMode == BREATH_ACC_AT) {
int delta = breathSignal - instrument.breathZero; int delta = breathSignal - instrument.breathZero;
if (abs(delta) > state.calibration->breathThrValOffset) { if (abs(delta) > state.calibration->breathThrValOffset) {
@ -903,12 +900,20 @@ void readBreath() {
} }
instrument.breathAltSignal = breathAltSignal; instrument.breathAltSignal = breathAltSignal;
int16_t movingThrAdj = instrument.breathBaseline + (instrument.breathSignal - instrument.breathBaseline) * .75;
if (state.mainState != NOTE_ON) {
// Don't allow the threshold to increase if we're not playing a note to make slow attacks consistent
movingThrAdj = min(instrument.breathMovingThrVal, movingThrAdj);
}
instrument.breathMovingThrVal = constrain( instrument.breathMovingThrVal = constrain(
breathBaselineFilter.input(instrument.breathBaseline + (instrument.breathSignal - instrument.breathBaseline) * .75), breathBaselineFilter.input(movingThrAdj),
instrument.breathZero + halfOffset, instrument.breathBaseline,
instrument.breathMaxVal - halfOffset instrument.breathMaxVal - state.calibration->breathThrValOffset
); );
int16_t halfOffset = state.calibration->breathThrValOffset >> 1;
instrument.breathThrVal = instrument.breathMovingThrVal + halfOffset; instrument.breathThrVal = instrument.breathMovingThrVal + halfOffset;
instrument.breathThrOffVal = instrument.breathMovingThrVal - halfOffset; instrument.breathThrOffVal = instrument.breathMovingThrVal - halfOffset;
@ -931,6 +936,8 @@ void readBreath() {
Serial.println(instrument.breathThrVal); Serial.println(instrument.breathThrVal);
Serial.print(">off:"); Serial.print(">off:");
Serial.println(instrument.breathThrOffVal); Serial.println(instrument.breathThrOffVal);
Serial.print(">offset:");
Serial.println(state.calibration->breathThrValOffset);
} }
} }