[sdiy] MIDI spec

Paul Maddox P.Maddox at signal.qinetiq.com
Wed Dec 4 10:03:45 CET 2002


Seb,

> Unfortunatly, of the 30 or so instructions in a PIC16XXXX, switch/case
isn't included ;-)

It isnt in the AVR, but it is if you use a C compiler :-)

> This is how I have done things in the MIDI2CV converter that I'm currently
programming:
>
> (1) In the interrupt service routine which gets called when a new MIDI
byte is received, I am using the quick-logic I described before..
> > Status bytes starting with "11111" are system realtime messages
> > Status bytes starting with "11110" are system common messages
> > Status bytes starting with "110" have 1 data byte
> > All the rest have 2 data bytes
> The ISR simply keeps track of incoming messages and pushes them into a 16
byte ring-buffer when a complete message is ready.

yep, makes sense...

> (2) In the main loop, I pole the buffer and process messages as they
become available.  This way processing can take a long time if necessary
(for example if many calculations are required to use the message), and it
doesn't block the time critical timer-driven interrupts such as the software
LFOs, Envelopes and Portamento, and the S&H refreshing/sequencing.
>

yep, I do this with the AVR, once a byte is received via the UART IRQ, I
dump into a buffer.
In the main loop I check to see if the buffer pointer is greater than 0,
then jump to it and read the buffer..
It gets checked about 100,000 times a second..

> In the main message parser I use a jump table to decode bits 4-6 of the
status byte (kind of the assembly language equivalent of a switch/case
statement, but very efficient).
>

jump tables are good..

> This approach also means the PIC can fall up to 16 bytes behind the
incoming data before getting a buffer overflow - hopefully this should never
happen, but it's nice to have a bit of margin to avoid dropped MIDI messages
when things get really busy.
>

My buffer is about 64 bytes, mostly because Im paranoid :-)

> BTW, when I finally finish this sucker I will be putting up everything,
but if anyone wants any particular snippets now (e.g. the MIDI
receiving/parsing code), feel free to ask.
>

great I look forward to it..
Do you have a website?

Paul
---------------------------------------------------------------
Modulus Synth page ;-
   Http://www.Modulus.synth.net/
PPG webpages
   Http://www.PPG.synth.net/




More information about the Synth-diy mailing list