tags:

views:

1474

answers:

3

Hello all,

I've start a small project which includes working with Midi files. I've been wondering, does any of you know of a c# \vb.net code that peforms that cast between midi and wav files?

+7  A: 

MIDI files contain only note and controller information, not sounds. In order to get sounds from a MIDI file, you have to pass the file through a music synthesizer or sampler, which will convert the note and controller information into actual sounds.

In practice this means that any given MIDI file doesn't have a specific sound to it. The sound that results from converting a MIDI file to audio will vary depending on the quality of the synthesizer or sample library, and the sounds that are selected to perform the conversion.

Many sound cards have the capability of producing sound from MIDI files. They can do this because many MIDI files follow a standard called the General MIDI specification. The General MIDI Specification provides a standardized way to map specific instrument assignments. If your MIDI file conforms to this standard, you can play it through a General MIDI sound generator and expect a snare drum to sound like a snare drum, and not like a trumpet.

If you have a sophisticated music production package like Cakewalk, you can load a MIDI file into it, and it will use its on-board sound libraries to render a sound file for you, and this can actually be done faster than real-time (i.e. it doesn't have to play the sound through the sound card and capture the output).

I guess what I'm trying to say is there's a lot of moving parts to this. There isn't a single piece of code or a class module that will do this for you.

Robert Harvey
I wish to be able to play midi files over silverlight, am I expacting too much?
vondip
I don't think you need to convert MIDI to WAV in order to play it in silverlight. If silverlight can't handle MIDI files natively, then you can tap into the Windows multimedia API to play the MIDI files.
MusiGenesis
How do I do that? Silverlight's environment blocks me from accessing that. How can I add a com reference to Windows multimedia API ?
vondip
Not Silverlight, but I found this to be very cool...JQuery Media Plugin: http://malsup.com/jquery/media/#overview
Robert Harvey
"a lot of moving parts to this" - I can only think of two. The synthesizer pack used for rendering, and the code that actually does the rendering.
superjoe30
A: 

There are a number of programs you can purchase that will do this (google "convert midi to WAV"), but I've never come across publically-available .Net code that does this (I think some of these programs are written in .Net, but the source code is not available).

I have an online friend who is working on a commercial MIDI-to-WAV converter, but it isn't in .Net and it won't be open source. As Robert Harvey mentioned, this is not a simple task at all, as it basically involves writing your own software synthesizer (a task after my own heart).

MusiGenesis
+6  A: 

You could try to somehow interface with Timidity, which is Open Source:

TiMidity++ is a software synthesizer. It can play MIDI files by converting them into PCM waveform data; give it a MIDI data along with digital instrument data files, then it synthesizes them in real-time, and plays. It can not only play sounds, but also can save the generated waveforms into hard disks as various audio file formats.

FluidSynth is a more recently updated Open Source project in a similar vein:

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications.

You can download some free SoundFonts (the actual PCM data used by these synthesizers to "render" the MIDI files) from the sites on this list.

Jacob
Nice link, Jacob.
Robert Harvey
Thanks, discovered it way back when. Works well with sound fonts from this list: http://en.wikipedia.org/wiki/SoundFont#Free_SoundFont_downloads
Jacob
Jacob, great work with these links. I'm sure they'll be useful. I especially like TiMidity++ feature : 'Plays remote MIDI files over the network' Do you know where I can find a .exe file? I always get messed up when configuring the linker c++ applications (I'm not a great c++ programmer)
vondip
You can try http://ocmnet.com/saxguru/Timidity.htm or http://www.hitsquad.com/smm/programs/TiMidity_win32/. I can't find the site I originally downloaded it from, and I haven't tried these packages yet.
Jacob