limit frequency of reading & parsing MIDI data
To improve note accuracy
This commit is contained in:
parent
7d2f555ee4
commit
2a4670009b
20
main.cpp
20
main.cpp
|
@ -5,6 +5,10 @@
|
|||
|
||||
#define NUM_MOTORS 4
|
||||
|
||||
// Minimal interval between reading two chunks of MIDI data
|
||||
// This improves frequency accuracy by throttling non-synthesizing actions
|
||||
#define MIDI_CMD_INTERVAL_MIN 15 * 1000 // 15ms
|
||||
|
||||
using namespace midi;
|
||||
|
||||
MotorControl motors[NUM_MOTORS] = {
|
||||
|
@ -73,11 +77,25 @@ int main() {
|
|||
MIDI.setHandleNoteOn(midi_note_on);
|
||||
MIDI.setHandleNoteOff(midi_note_off);
|
||||
|
||||
unsigned long cur_micros;
|
||||
unsigned long last_read_micros = 0;
|
||||
|
||||
while (true) {
|
||||
unsigned long cur_micros = timer2.get_count() / 2ul; // The unit of get_count is 0.5us
|
||||
cur_micros = timer2.get_count() / 2ul; // The unit of get_count is 0.5us
|
||||
handle_tick(cur_micros);
|
||||
|
||||
if (cur_micros - last_read_micros >= MIDI_CMD_INTERVAL_MIN) {
|
||||
last_read_micros = cur_micros;
|
||||
|
||||
// Read all available MIDI data
|
||||
// Note that the host is expected to send MIDI data only when
|
||||
// it is supposed to be played; therefore we don't need
|
||||
// to worry about the host sending data prematurely
|
||||
while (Serial.available()) {
|
||||
MIDI.read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue