2

I'm using NAudio to play MIDI files in my .NET project.

I want to play some MIDI tracks (drum loops particularly) so each sound maps to a certain wav or mp3 file. Is that possible?

I'm new to MIDI development, I just heard of the idea of SoundFonts, is this what I'm looking for perhaps?

Has anyone tried that before?

Update
It's not that I have those wave files present, I just hate the sound of the default MIDI device on the computer.

Maybe I just need a better sound card, or maybe there is a virtual MIDI device that has professional tones.

Update
After reading about SoundFont, I am almost sure this is the solution I'm seeking. The question is how to use it with NAudio.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

1 Answers1

1

To do this you will need a software synthesizer, which can convert from MIDI notes into PCM audio. Some software synthesizers make use of soundfonts as you mention, others use samples, and others generate sounds using oscillators or physical modelling.

NAudio does not include a software synthesizer, and building one is not a trivial task at all (will require knowledge of filters, resampling, oscillators, DSP etc). You might find that the best approach is to use NAudio in combination with VST.net. This would allow you to load any VST software instrument (of which there are thousands, both commerical and free), pass your MIDI into that, and use NAudio to write the resulting sound to a file.

Having said that, if all you need is a simple drum sequencer, the NAudio WPF demo does include an example of playing back drum samples.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194
  • Hi Mark and thanks for your kind reply. The answer is I need more than a simple drum loop. I saw the WPF demo, but I'm also focusing on other tracks that will have to be nice tones. The default MIDI tones are just unacceptable. Is there a way to 'fake' a MIDI device? I'm pretty new to audio programming, I used to deal with MIDI messages before, but not with sf2/sampling. Any additional resources will be appreciated. Can you please expand a bit about the potential relationship between NAudio and VST.NET (which I never dealt with), or any hint to get me started? – Shimmy Weitzhandler May 08 '13 at 10:06
  • faking a MIDI device is unfortunately not straightforward. You can buy "Virtual MIDI cables" allowing you to connect two applications together. This would allow you to play sound into a DAW. But to be honest, it might be easier to find a DAW that can be scripted to turn MIDI into WAV (REAPER might be a good option to try). – Mark Heath May 08 '13 at 11:50
  • And what about the VST.NET solution you proposed? Isn't there a way to stream the MIDI thru some sampler so the output (be it wav) will be streamed using SFs? – Shimmy Weitzhandler May 08 '13 at 18:27