Forums

Open Source MIDI Player

Started by Rob Hutchinson August 13, 2007
Hello all,
I'm looking for an open source MIDI player, preferably a C implementation. 
I need the actual MIDI decode source code, (i.e. a player which calls into 
Windows DLL for the decode is no good.).  Goal is to port to ADI Blackfin so 
a fixed point implementation is preferable.   Any suggestions on finding 
this?  Thanks in  advance,
Rob 


Rob Hutchinson wrote:
> Hello all, > I'm looking for an open source MIDI player, preferably a C implementation. > I need the actual MIDI decode source code, (i.e. a player which calls into > Windows DLL for the decode is no good.). Goal is to port to ADI Blackfin so > a fixed point implementation is preferable. Any suggestions on finding > this? Thanks in advance, > Rob > >
A full-blown Midi player would perforce need to include some sort of synthesiser, whereas it looks like you just want the immediate MIDI parsing stage. Try PortMidi: http://www.cs.cmu.edu/~music/portmusic/ There is also RTMidi: http://www.music.mcgill.ca/~gary/rtmidi/ But that is C++. Used in the powerful STK audio tools. Note that many such packages parse the MIDI stream into 2 or 3-byte MIDI messages, which the host the deals with as it sees fit. So you may want/need to look at some of the applications listed as using PortMidi (e.g. Csound, PD). You will also need to consider how much of the MIDI spec you need to support. Basic NOTE ON/OFF of course, but maybe not all the Registered-Parameter Numbers (RPN, NRPN), or SystemExclusive. The basic parsing of a MIDI stream is not that big a deal (apart from Sysex it all comes down to 2-or 3-byte message packets) - the only real issue to be aware of is "Running Status". For a fixed-point implementation, you may actually be better off just reading the official MIDI spec and implementing it from first principles. Worth asking on the music-dsp list too. Richard Dobson
Rob Hutchinson wrote:

> Hello all, > I'm looking for an open source MIDI player, preferably a C implementation. > I need the actual MIDI decode source code, (i.e. a player which calls into > Windows DLL for the decode is no good.). Goal is to port to ADI Blackfin > so > a fixed point implementation is preferable. Any suggestions on finding > this? Thanks in advance, > Rob
Try this one: http://timidity.sourceforge.net/ Iwo
1.)Where can I find the current General MIDI System specification?  What is 
the current version number of this document?

2.)My project requires only bare bones MIDI functionality: I need to play a 
MIDI file.  I will take a MIDI file as input decode it and stream the audio 
data out.  I need to f ind source code to take a MIDI file and produce PCM 
audio, (.wav), data,  (I will take care of streaming the data myself).  I 
must have the source code for the actual MIDI decode.  Where can I find bare 
bones source code for MIDI decode?  Is there an easier way than picking 
apart a player like Timidity or WildMIDI?

Thanks again,
Rob


"Rob Hutchinson" <rhutch7@lisco.com> wrote in message 
news:f9r7al$5kk$1@news.netins.net...
> Hello all, > I'm looking for an open source MIDI player, preferably a C implementation. > I need the actual MIDI decode source code, (i.e. a player which calls into > Windows DLL for the decode is no good.). Goal is to port to ADI Blackfin > so a fixed point implementation is preferable. Any suggestions on > finding this? Thanks in advance, > Rob >
Rob Hutchinson wrote:
> 1.)Where can I find the current General MIDI System specification? What is > the current version number of this document? >
You buy it from the Midi Manufacturers Association: http://www.midi.org/ But a lot of books summarise it completely enough to enable basic parsing code to be written. The MIDI file format is a separate entity, with other things to deal with, such as the "variable-length" numbers used to indicate "delta ticks" between events. You might well want to track down a copy of the book "Midi Programmer's Handbook (out of print but is listed on Amazon): Title: The MIDI programmer's handbook / Steve De Furia and Joe Scacciaferro, Ferro Technologies. Publisher: Redwood City, Calif. : M&T Pub., c1989. ISBN: 1-55851-068-0, 250 pp.
> 2.)My project requires only bare bones MIDI functionality: I need to play a > MIDI file. I will take a MIDI file as input decode it and stream the audio > data out. I need to f ind source code to take a MIDI file and produce PCM > audio, (.wav), data, (I will take care of streaming the data myself). I > must have the source code for the actual MIDI decode. Where can I find bare > bones source code for MIDI decode? Is there an easier way than picking > apart a player like Timidity or WildMIDI? >
I trust you appreciate that to "decode" MIDI entails implementing a complete polyphonic synthesiser. MIDI just defines control information - note on/off comamnds, parameter changes such as volume and modulation, and patch changes. Streaming audio is the least of your problems - you have to decide what audio to create first! You can surely only do it on a single DSP chip if you are extremely conservative about synthesis algorithms. If you have sufficient memory (e.g. 512KB for a wavetable set), using a wavetable library or sample set is probably your best option. You can find a lot of free "soundfonts" (Q.V.) (in MIDI terms, also called DLS - DownLoadable Sounds). the General MIDI spec defines 128 standard voices, covering everything from pianos, organs, wind, strings and brass to percussion and sound effects. IIRC there are even chips one can buy containing a full GM wavetable set. One can reasonably assume that a MIDI file contains patch change commands reflecting the General MIDI spec. One Soundfont site out of many is: http://www.sf2midi.com/ Csound, among other things, supports Soundfonts (I believe, using a 3rd party library). ADI did manage to emulate a full Roland Sound Canvas (as part of their mostly dead "Extended Csound" project), but they needed a card with two SHARC chips on it, plus plenty of memory. A typical GM Soundfont library may be 20MB or greater. I would seriously question whether a single Blackfin is up to the job; though as I say, sample playback should be possible if you have the memory. Depends how many polyphonic voices you decide to support. Richard Dobson
There is also this:
http://www.borg.com/~jglatt/

"Richard Dobson" <richarddobson@blueyonder.co.uk> wrote in message 
news:eMzwi.7085$lx3.2062@fe3.news.blueyonder.co.uk...
> Rob Hutchinson wrote: >> 1.)Where can I find the current General MIDI System specification? What >> is the current version number of this document? >> > > > You buy it from the Midi Manufacturers Association: http://www.midi.org/ > > But a lot of books summarise it completely enough to enable basic parsing > code to be written. The MIDI file format is a separate entity, with other > things to deal with, such as the "variable-length" numbers used to > indicate "delta ticks" between events. You might well want to track down a > copy of the book "Midi Programmer's Handbook (out of print but is listed > on Amazon): > > Title: The MIDI programmer's handbook / Steve De Furia and Joe > Scacciaferro, Ferro Technologies. > Publisher: Redwood City, Calif. : M&T Pub., c1989. > ISBN: 1-55851-068-0, 250 pp. > > > > >> 2.)My project requires only bare bones MIDI functionality: I need to play >> a MIDI file. I will take a MIDI file as input decode it and stream the >> audio data out. I need to f ind source code to take a MIDI file and >> produce PCM audio, (.wav), data, (I will take care of streaming the data >> myself). I must have the source code for the actual MIDI decode. Where >> can I find bare bones source code for MIDI decode? Is there an easier >> way than picking apart a player like Timidity or WildMIDI? >> > > I trust you appreciate that to "decode" MIDI entails implementing a > complete polyphonic synthesiser. MIDI just defines control information - > note on/off comamnds, parameter changes such as volume and modulation, and > patch changes. Streaming audio is the least of your problems - you have to > decide what audio to create first! You can surely only do it on a single > DSP chip if you are extremely conservative about synthesis algorithms. If > you have sufficient memory (e.g. 512KB for a wavetable set), using a > wavetable library or sample set is probably your best option. You can find > a lot of free "soundfonts" (Q.V.) (in MIDI terms, also called DLS - > DownLoadable Sounds). the General MIDI spec defines 128 standard voices, > covering everything from pianos, organs, wind, strings and brass to > percussion and sound effects. IIRC there are even chips one can buy > containing a full GM wavetable set. One can reasonably assume that a MIDI > file contains patch change commands reflecting the General MIDI spec. > > One Soundfont site out of many is: > > http://www.sf2midi.com/ > > Csound, among other things, supports Soundfonts (I believe, using a 3rd > party library). > > ADI did manage to emulate a full Roland Sound Canvas (as part of their > mostly dead "Extended Csound" project), but they needed a card with two > SHARC chips on it, plus plenty of memory. A typical GM Soundfont library > may be 20MB or greater. I would seriously question whether a single > Blackfin is up to the job; though as I say, sample playback should be > possible if you have the memory. Depends how many polyphonic voices you > decide to support. > > Richard Dobson > >
Hi Richard,
Thanks much, very good info.  I am learning!  We will have off chip memory 
on this board so we believe we can store enough Wavetable data for our 
needs.  Blackfin has a lot of MIPS so I dont think that will be the 
bottlleneck.  This does seem like a big development project tho.  I found 2 
open source players:  Timidity and WildMIDI,  but I can see porting them 
will be a lot of work.  What do you think is less work: i.)Porting an 
existing player to Blackfin OR ii.)Coding ourselves.  We do have to 
implement a polyphonic synthesizer BUT we can scale its capabilities down a 
lot by limiting  it to playing a small set of MIDI files.  We only need to 
play a set of MIDI files for ringtomes, prompts etc.
Rob


"Richard Dobson" <richarddobson@blueyonder.co.uk> wrote in message 
news:eMzwi.7085$lx3.2062@fe3.news.blueyonder.co.uk...
> Rob Hutchinson wrote: >> 1.)Where can I find the current General MIDI System specification? What >> is the current version number of this document? >> > > > You buy it from the Midi Manufacturers Association: http://www.midi.org/ > > But a lot of books summarise it completely enough to enable basic parsing > code to be written. The MIDI file format is a separate entity, with other > things to deal with, such as the "variable-length" numbers used to > indicate "delta ticks" between events. You might well want to track down a > copy of the book "Midi Programmer's Handbook (out of print but is listed > on Amazon): > > Title: The MIDI programmer's handbook / Steve De Furia and Joe > Scacciaferro, Ferro Technologies. > Publisher: Redwood City, Calif. : M&T Pub., c1989. > ISBN: 1-55851-068-0, 250 pp. > > > > >> 2.)My project requires only bare bones MIDI functionality: I need to play >> a MIDI file. I will take a MIDI file as input decode it and stream the >> audio data out. I need to f ind source code to take a MIDI file and >> produce PCM audio, (.wav), data, (I will take care of streaming the data >> myself). I must have the source code for the actual MIDI decode. Where >> can I find bare bones source code for MIDI decode? Is there an easier >> way than picking apart a player like Timidity or WildMIDI? >> > > I trust you appreciate that to "decode" MIDI entails implementing a > complete polyphonic synthesiser. MIDI just defines control information - > note on/off comamnds, parameter changes such as volume and modulation, and > patch changes. Streaming audio is the least of your problems - you have to > decide what audio to create first! You can surely only do it on a single > DSP chip if you are extremely conservative about synthesis algorithms. If > you have sufficient memory (e.g. 512KB for a wavetable set), using a > wavetable library or sample set is probably your best option. You can find > a lot of free "soundfonts" (Q.V.) (in MIDI terms, also called DLS - > DownLoadable Sounds). the General MIDI spec defines 128 standard voices, > covering everything from pianos, organs, wind, strings and brass to > percussion and sound effects. IIRC there are even chips one can buy > containing a full GM wavetable set. One can reasonably assume that a MIDI > file contains patch change commands reflecting the General MIDI spec. > > One Soundfont site out of many is: > > http://www.sf2midi.com/ > > Csound, among other things, supports Soundfonts (I believe, using a 3rd > party library). > > ADI did manage to emulate a full Roland Sound Canvas (as part of their > mostly dead "Extended Csound" project), but they needed a card with two > SHARC chips on it, plus plenty of memory. A typical GM Soundfont library > may be 20MB or greater. I would seriously question whether a single > Blackfin is up to the job; though as I say, sample playback should be > possible if you have the memory. Depends how many polyphonic voices you > decide to support. > > Richard Dobson > >
Rob Hutchinson wrote:
> Hi Richard, > Thanks much, very good info. I am learning! We will have off chip memory > on this board so we believe we can store enough Wavetable data for our > needs. Blackfin has a lot of MIPS so I dont think that will be the > bottlleneck. This does seem like a big development project tho. I found 2 > open source players: Timidity and WildMIDI, but I can see porting them > will be a lot of work. What do you think is less work: i.)Porting an > existing player to Blackfin OR ii.)Coding ourselves. We do have to > implement a polyphonic synthesizer BUT we can scale its capabilities down a > lot by limiting it to playing a small set of MIDI files. We only need to > play a set of MIDI files for ringtomes, prompts etc. > Rob > >
I am not best qualified to answer this (having only dabbled with programming DSP chips, and ported just one C program to the SHARC), and more information would be needed, from timescale to manpower available. But my instinct says that if your required synthesiser is as minimal as you say, coding directly (but with reference to the design of your chosen examples) would be the better bet. Perhaps you don't even need to worry about things such as voice allocation and stealing, and can just employ a fixed four-voice architecture (say), create some simple voices that render your PCM data (would you even need things such as filters?), and that's it. Parsing MIDI files is not really a big deal, again especially if you know what the content is a priori and know which bits you don't need. I am moved to ask - why do you need MIDI files for this? Is it so 3rd parties can change sounds? That would raise the bar a lot. But if it is all internal, you could convert the MIDI files to some private format externally, such as a simple text-based note list. You can even use Csound for that. There are also tools around that convert MIDI files to Csound score format. Richard Dobson