Teensy 3.6 Midi Buffering

Status
Not open for further replies.

CraigH

Member
I'm using Teensy 3.6 and all 6 Midi ports. All is working very well, except when I send a big block of messages. After about 21 messages, transmission stops. After a few milliseconds, I can send individual messages ok again, but big blocks always behave the same way. (21 messages correlates to around 64 bytes.) This seems likely to be related to transmit buffer overflow. My initial assumption was that the buffer that's overflowing is the serial buffer, so following other forum hints, I've edited the files serial1.c to serial6.c in directory "C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores", as follows. (SERIALx being replaced with SERIAL1 to SERIAL6):

#ifndef SERIALx_TX_BUFFER_SIZE
#define SERIALx_TX_BUFFER_SIZE 1024 // (old 64) number of outgoing bytes to buffer
#endif
#ifndef SERIALx_RX_BUFFER_SIZE
#define SERIALx_RX_BUFFER_SIZE 1024 // (old 64) number of incoming bytes to buffer
#endif

I've restarted the IDE and recompiled the sketch, but the behaviour is the same, and the memory usage is also the same. My questions are:

1) Is this the correct way to change the buffer sizes. If TX_BUFFER_SIZE was already defined, then won't the new value be ignored? I've tried removing the #ifndef and #endif macros, thinking this would either fix the problem or generate a duplicate symbol compile error. Neither of these things happened. (Verbose compile is turned on.)

2) Is there another "Midi Message" buffer that could be overflowing? I did see reference to a Midi Ring Queue, but I could not find any dimensioning for it.

As a workaround, I have created a midi queue within my code, and using a 1mS interrupt, dequeue any available messages and send them. This works fine, but I'm really not happy that this is right way to go.

Any suggestions welcomed.

Thanks
 
Thanks. Though the problem is not related to SysEx. It's just for 3 byte messages. If sent in one block, only 21 can be sent before the remainder get lost. It looks like a Tx Buffer of 64 is overflowing or a midi buffer of 21 messages is overflowing.

Craig
 
After some more checking, I now have the midi queues working well. The problem was related to changing the Serial Buffer sizes. What was wrong, was that I always keep an original file when I make changes. I edited 'serial1.c" with the new buffer sizes, but in the same directory I had a file "serial1-orig.c". When I checked the verbose compilation reading I found that both files were being included. I therefore renamed "serial1-orig.c" to "serial1-orig.txt and all was resolved. I can send blocks of 100 midi messages, and then receive them all 100% reliably. Based on this, I am assuming there is no separate Midi Buffer that needs re-dimensioning.
 
Status
Not open for further replies.
Back
Top