I have wired up and programmed a Teensy 3.2 to receive and transmit a MIDI serial datastream. The purpose is to introduce a short preset delay between the data from an organ keyboard and the sound production from a synthesizer. I want to simulate the acoustics of a large church where the keyboards are a long way from the pipes so there is a delay between hearing what you play.
There are two parts to the process: (1) read and detect NoteON / NoteOFF events in the datastream and store them with a timestamp and (2) transmit each event after the preset delay has expired. The datasream runs at 31250 baud but the actual rate of events depend on when the keys are pressed… say a max of 16 /sec. There are three bytes per key pressed. A typical delay would be 250msec. I have tried storing a timestamp with the event and then checking if the delay for that event has expired using millis but this doesn't seem to work as the data arrival/storing and the delay expiry are really asynchronous.
Is there a way to use the Teensy 3.2 interrupts to trigger the transmission of each event after its delay has expired? It looks like there are four that can be active at any time but I think I would need up to 16. Thanks.
Here is the 'read/store' code and the current 'transmit after delay' code:
There are two parts to the process: (1) read and detect NoteON / NoteOFF events in the datastream and store them with a timestamp and (2) transmit each event after the preset delay has expired. The datasream runs at 31250 baud but the actual rate of events depend on when the keys are pressed… say a max of 16 /sec. There are three bytes per key pressed. A typical delay would be 250msec. I have tried storing a timestamp with the event and then checking if the delay for that event has expired using millis but this doesn't seem to work as the data arrival/storing and the delay expiry are really asynchronous.
Is there a way to use the Teensy 3.2 interrupts to trigger the transmission of each event after its delay has expired? It looks like there are four that can be active at any time but I think I would need up to 16. Thanks.
Here is the 'read/store' code and the current 'transmit after delay' code: