MIDI Note Parser to Lookup Table and SPI DAC Output

Synthweez

New Member
Hi, This is my first post.
I've read a few of the threads on MIDI parsing and using the note commands to flash LED's. I'm exploring use of PICAXE to parse MIDI notes on and off and use the note values to lookup DAC values in a table and send to a 8 Channel (12 bit) DAC over SPI. Before I spend quite a bit of time developing, I was wondering whether PICAXE would be able to keep up with multiple MIDI notes on, do the lookup and send the resulting 16 bit values to the DAC? I've seen a few projects and forum posts with MIDI parsing , flashing LED, and also some discussion on SPI 8 bit limitations. Any advice and hints would be appreciated. It looks like there is some code already for MIDI parsing to get me started.

Thanks in advance for any hints or ideas.
 

Jeremy Leach

Senior Member
Hi Synthweez,

IMHO the PICAXE isn't fast enough for this. 'Sending' MIDI isn't a problem but receiving is far more difficult due to the potential very small time intervals between the incoming MIDI events. Yes a PICAXE 'could' detect the 3-byte block of a note on or note off MIDI event but it's very unlikely to be fast enough to do anything with it and to keep up with incoming data. However if it was just the occasional incoming note event then it probably could work.

You could use background receive and have a buffer but unless you can process and empty the buffer fast enough it won't be of much use.

I just happen to be doing MIDI parsing in assembler on a PIC at the moment and you really need to go down to this level to have the necessary speed available for anything complex. For instance my routine to scan and transpose incoming notes operates at roughly 8000 times a second.

PICAXE is a brilliant product which you can do an amazing amount with, but it has limitations.
 
Last edited:

hippy

Technical Support
Staff member
I think it would quite hard to tell what can be achieved until one tries it and it will depend greatly on how much MIDI data is coming in and how much needs to be done in response to that.

Music is not always as demanding as it seems; 240 beats per minutes could mean a MIDI packet every 125ms and a PICAXE can get a lot done in that time at 64MHz. An X2 would be needed for its background receive capability.

At 31250 baud, that's one byte every 320us and the PICAXE can be processing data while further bytes are being received. Processing might lag behind data received but there's potentially a fairly large tolerance for latency in acoustic terms.

If it's simply handling MIDI Note On and Off commands on one channel it should be possible to quickly filter out data that isn't relevant and thereby minimising latency. In this project it's then just a matter of looking up the DAC value and sending it out. For example ( without the outputting ) -

Code:
#Picaxe 28X2

#Macro GetByteIntoB0
  Do : Loop While hSerPtr = ptr
  b0 = @ptrInc
#EndMacro

Symbol channel = b1 : channel = 3
Symbol noteOff = b2 : noteOff = $80 + channel
Symbol noteOn  = b3 : noteOn  = $90 + channel
Symbol cmd     = b4

SetFreq EM64
HSerSetup B31250_64, %001

Do
  GetByteIntoB0
  If b0 >= $80 Then
    cmd = b0
  Else
    Select Case cmd
      Case noteOn
        ; Do something - Key value in b0
        GetByteIntoB0
      Case noteOff
        ; Do something - Key value in b0
        GetByteIntoB0
      Else
        cmd = 0
    End Select
  End If
Loop
That can be improved upon by use of GOTO's back to the DO loop start.

Throughput could also be potentially be improved by having the above filtering the commands and signalling another PICAXE with single byte Note On or Note Off commands, having that convert those to the DAC output.

I think to do a more detailed analysis one would need to know exactly what had to be done, and the proof of the pudding would be in trying it. Perhaps simply lighting LED's with Note On and Note off commands to start with.
 
Top