<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In 2005 I wrote a MIDI processing program to do minor manipulation such as transposing notes, changing CC messages, etc. I did it in assembly in an 8 MHZ ATTINY2313. Receive and transmit are interrupt driven out of 32 byte buffers each. It handles running status and can filter out some of the real time messages. It will take everything I can throw at it with two hands on the keyboard. It is highly optimized assembly but I suspect your issue is not emptying the buffers fast enough.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I also run this same code on a 16 MHz Basic Stamp which does have I2C D/As which do take some time so care has to be taken. The same code on an Arduino runs about 4.5X faster because the I2C is handled in hardware whereas on the Basic Stamp it is done in software.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I found my Tektronix scope with I2C decoding capability invaluable in seeing where my bottlenecks were in all the communications. Even without that capability I would often use an external pin to create timing signals so I could accurately measure code execution. But I’m a hw guy by nature.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>FYI<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><br>Dave<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> dougall [mailto:<a href="mailto:dougalli@gmail.com" target="_blank">dougalli@gmail.com</a>] <br><b>Envoyé :</b> 19 mars 2020 21:06<br><b>À :</b> <a href="mailto:eidorian@aladan.net" target="_blank">eidorian@aladan.net</a><br><b>Cc :</b> Jean-Pierre Desrochers; <a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><b>Objet :</b> Re: [sdiy] MIDI I/O c code..</span><span lang=FR-CA><o:p></o:p></span></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA> Are you handling running status and note off sent as zero velocity note on?<o:p></o:p></span></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA> -d<o:p></o:p></span></p></div></div><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA> On Fri, 20 Mar 2020 at 11:55, <<a href="mailto:eidorian@aladan.net" target="_blank">eidorian@aladan.net</a>> wrote:<o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Sorry, I don't have example code for you, but here is some analysis that I hope might help point you in the right direction:</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>20MHz / 31,250Hz => ~640 instructions per MIDI data bit, or 6,400 instructions per MIDI data byte.  That's quite a lot of instruction execution time between notes, so I'd be checking the efficiency/optimisation of the code.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>How long is it taking to update the analog outputs and do other processing?  If it's updating all 8 CVs via a "slow" protocol like I2C every time it loops then that might be taking a while, and maybe you need a different approach (i.e. only update a CV output when it changes).</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>How have you implemented the FIFO?  Do you have locking to ensure the interrupt isn't writing to it while the main loop is updating it?</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Create a debug version that has checks on the FIFO size in the interrupt, and sets an LED on if it overflows, so you can confirm for certainly whether or not that's the problem.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>What I do (with 30+ years of programming experience) is pretend I'm the CPU, and "execute" the code in my head (or on paper if complex) in order to try to work out what unplanned or unexpected things might be happening to cause the problematic behaviour.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Cheers,<br>A.</span><span lang=FR-CA><o:p></o:p></span></p><div id="m_-1322366504434334221gmail-m_5822220122528591338signature"><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>---</span><span lang=FR-CA><o:p></o:p></span></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA style='font-size:10.0pt;font-family:"Courier New"'> </span><span lang=FR-CA><o:p></o:p></span></p></div></div><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p><p id="m_-1322366504434334221gmail-m_5822220122528591338reply-intro"><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>On 20-03-2020 11:14, Jean-Pierre Desrochers wrote:</span><span lang=FR-CA><o:p></o:p></span></p><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0in 0in 0in 5.0pt;margin-left:0in;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0in 0in 0in 5.0pt;margin-left:0in;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p></div></blockquote></blockquote><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0in 0in 0in 5.0pt;margin-left:0in;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div id="m_-1322366504434334221gmail-m_5822220122528591338replybody1"><div><div><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I’m working on a new polyphonic MIDI to CV module (8 voices).</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>So far I did my tests with an old PIC16F887 @ 20Mhz micro I had on hand.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I use a USART interrupt driven c function to ‘catch’ all the incoming MIDI bytes.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>My code is pretty fast, but still, since I only read one MIDI channel (1-16) at the time <br>when I play very fast chords on an external keyboard</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>all the notes are read in the incoming queue but sometimes</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I get stuck notes or unread ones..</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Same thing happens when playing MIDI files on Cakewalk SONAR <br>feeding my prototype with  a MIDI cable.<br>The interrupt function grabs each incoming byte and put them</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>In a receive buffer of 32 bytes and the main () reads and treats them in a FIFO manner</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Later in the main loop.</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p><p><em><span lang=FR-CA style='font-family:"Verdana","sans-serif"'>-Would a 32Mhz micro do a difference in the USART interrupt reading speed ?</span></em><span lang=FR-CA><o:p></o:p></span></p><p><em><span lang=FR-CA style='font-family:"Verdana","sans-serif"'>-And is 32 bytes long enough for the RxBuffer to handle a 6 voices chords ?</span></em><span lang=FR-CA><o:p></o:p></span></p><p><em><span lang=FR-CA style='font-family:"Verdana","sans-serif"'>-And finaly I checked the web for a ‘decent’ C code examples</span></em><span lang=FR-CA><o:p></o:p></span></p><p><em><span lang=FR-CA style='font-family:"Verdana","sans-serif"'>  for MIDI reception (MIDI Tx is much easier to implement) with no success..</span></em><i><span lang=FR-CA style='font-family:"Verdana","sans-serif"'><br><em><span style='font-family:"Verdana","sans-serif"'>  ‘Obscure’ Arduino libraries all around with no explainations of its inner code.</span></em></span></i><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Did anybody use good C code available ?</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>JP</span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p><p><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a></span><span lang=FR-CA><o:p></o:p></span></p></div></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><span lang=FR-CA><o:p></o:p></span></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA style='font-size:10.0pt;font-family:"Courier New"'>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a></span><span lang=FR-CA><o:p></o:p></span></p></div></blockquote></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CA>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a><o:p></o:p></span></p></blockquote></div></div></div><p class=MsoNormal>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a><o:p></o:p></p></blockquote></div></div></div></body></html>