Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy 3.6 Midi Buffering

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    13

    Teensy 3.6 Midi Buffering

    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

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    569
    As per the MIDI library documentation this is how you can change the Sysex size

    Code:
    struct MySettings : public midi::DefaultSettings
    {
       static const unsigned SysExMaxSize = 1024; // Accept SysEx messages up to 1024 bytes long.
    };
     
    MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial2, midi, MySettings);
    Here's the link to all the settings available: http://fortyseveneffects.github.io/a...ry/a00059.html

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    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

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,351
    https://forum.pjrc.com/threads/43699...TX-buffer-size

    Looks like your path isn't correct. Teensy after Hardware...

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •