4

I am building a Windows Phone 7 app that plays musical notes. I would like to find some good .wav, .mp3, or .midi files that I can use. I've looked around, but haven't found anything. Any suggestions for where to look?

I've also looked at .NET frameworks like NAudio and Midi.NET to see if I could generate the tones programmatically, but I've been unable to figure out how to do it.

Nick Heiner
  • 119,074
  • 188
  • 476
  • 699

3 Answers3

3

You can create the WAV files yourself using NAudio using the techniques described in these articles:

and here is a little sample program to get you started that calculates the frequency based on the octave and the semi-tone with the 12-tone scale:

private WaveOut waveOut;
private WaveRecorder waveRecorder;

private void Button_Click(object sender, RoutedEventArgs e)
{
    StartStopSineWave();
}

private void StartStopSineWave()
{
    if (waveOut == null)
    {
        int octave = 1;
        int note = 0;
        var sineWaveProvider = new SineWaveProvider32();
        sineWaveProvider.SetWaveFormat(16000, 1); // 16kHz mono
        sineWaveProvider.Frequency = (float)(440 * Math.Pow(2, octave + note / 12.0));
        sineWaveProvider.Amplitude = 0.25f;
        waveRecorder = new WaveRecorder(sineWaveProvider, "sample.wav");
        waveOut = new WaveOut();
        waveOut.Init(waveRecorder);
        waveOut.Play();
    }
    else
    {
        waveOut.Stop();
        waveOut.Dispose();
        waveOut = null;
        waveRecorder.Dispose();
        waveRecorder = null;
    }
}
Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
1

MIDI files don't contain sounds, they just describe a sequence of notes (and other musical controls). The computer's MIDI driver should take care of actually producing the sound. If your Windows phone has a driver, then you should be able to use Midi.NET to say "play a C for x seconds" and it will.

If not, you can synthesise pure tones by using a simple sine function to generate waveforms. For actual instruments I don't know of any repositories - recording them well requires expensive equipment and effort so they are rarely made freely available.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
1

Google for "free soundfonts" to find individually recorded instrument notes for pianos, flutes, violins, drums etc.

Soundfont is a common format for sharing free audio files designed for use in samplers. Generally the quality of anything you will find available for free will vary from unusable to reasonable with a few remarkable high quality exceptions.

Most soundfonts will not contain individual audio files for every note. More commonly soundfonts will contain one sample for every octave. In that case your application will need to be able to pitch shift notes to the correct frequency. (This isn't that difficult to do and is the normal approach for samplers.)

Synthesis (generating tones programmatically) - I don't know what your application does but... sine tones are simple sounds and easy to create but will soon become boring to hear. More interesting sounds can be created but sound synthesis code gets complicated quickly. I wouldn't recommend writing your own synthesis code unless it is a core part of your application. IMHO it would be far better to use sample playback or use MIDI (if Windows Phone 7 has a good MIDI playback library).

Soundfont Archive

Shannon Matthews
  • 9,649
  • 7
  • 44
  • 75