Reputation: 1822
I am trying to create a simple program that plays some notes using a preset from inside a Soundfont. To do this I am trying to use NAudio. So far I have been able to successfully open a SoundFont, and get the names of all the instruments, presets, etc.:
NAudio.SoundFont.SoundFont sf = new NAudio.SoundFont.SoundFont("SoundFont.sf2");
MessageBox.Show(sf.Presets[0].Name); //Just looking at the first name
Now I want to be able to play sounds using those soundfonts, in the end from midi, but for now, just a note. I have played around with a few things, but not come up with anything so far.
Upvotes: 3
Views: 3191
Reputation: 49482
NAudio can read information out of SoundFont files, but it does not include a SoundFont engine. For that you would need a good pitch shifting algorithm, some filters, and some voice management, as well as a sequencer if you wanted to play back MIDI files.
The closest I have come to building something like this is a demo I made for my NAudio Pluralsight course, in which I build a simple sampled piano based on some piano note recordings. If you are subscriber, you are free to use it. The technique I use is to load the sample into memory, connect a RawSourceWaveStream to it, convert it into a sample provider, and then pass it through a pitch shifter sample provider, based on the one I ported to C# for this open source project.
Upvotes: 4