tags:

views:

245

answers:

4

Do you know any library in C# that I can use in order to read an existing *.mid file? I want to draw the sound frequency graph for the MIDI file, but I cannot get the inner data. I tried using NAudio and Alvas.Audio, but I wans't able to read a MIDI file. Any suggestions?

A: 

Bass.net (http://www.un4seen.com) might be what you are looking for. (using the Bassmidi extension down the page)

Femaref
+3  A: 

Here

SLaks
Thank you! I was actually looking for a program that displayed virtual keyboard playing for a midi file, and this does it perfectly. Not what the question is asking for, but it's certainly what I needed.
Corey
+2  A: 

The MIDI file format is relatively complicated (see here). Writing them is easier than reading them (as with WAV files). I don't know of any C# libraries that do this, but I should mention that since your ultimate goal is to create a spectrograph, you probably don't need a library to read the MIDI file at all.

A MIDI file does not contain any actual audio information - it merely contains instructions for a synthesizer, e.g. note on messages, volume change mesages etc. In order to create a spectrograph from a MIDI file, you need to "play" it with something so that you get actual audio data to run FFT analyses on.

You don't really need to play it with something, of course. Google midi-to-wav for a load of options for automatically converting MIDI files into WAV files. Once you have the WAV files, Google wav file spectrum analyzer c# to see the many options for generating spectrographs from WAV file data.

To the down-voters: suggesting Google keywords as an answer is not automatically a bad thing. In this case, I'm just trying to stear the asker in the right direction, so that they don't spend time doing something they don't need to do.

MusiGenesis
Since I answered the question, I'm going to treat myself to a rant: I wish MIDI would just @#%$@%# die already. It's a horribly obsolete spec designed as essentially a workaround for primitive 70s technology. When 99% of the world hears the word "MIDI", they think "crappy rinky-dink music coming out of my PC speakers". In a world where teenagers don't even know what a CD is (let alone what a *record* is), how on Earth is MIDI still around?
MusiGenesis
So if you'd kill MIDI, would you replace it with a new improved protocol to play synthesizers from code, or is doing that just generally obsolete too?
Conrad Albrecht
@Conrad: I should have restricted my rant to MIDI *files* rather than MIDI in general. A version of MIDI files that incorporated sample data and/or synth modules so that a separate application could reconstruct the audio exactly (instead of relying on a crappy FM synth chip to produce the sound) would be great, but none of the attempts at this have taken off (to my knowledge).
MusiGenesis
Well my app lets the user create MIDI files, so I'd be hurting if they died, but if there were a new improved (XML), widely supported file format for holding music information I'd love it.
Conrad Albrecht
@Conrad: I formally retract my desire to see MIDI files die. :)
MusiGenesis
+2  A: 

NAudio can read and write MIDI files. I'm not sure what your problem was. Have a look at MIDI file mapper as an example of a project using NAudio to map drum beats.

Mark Heath