14

I'm trying to make a simple piano application in C#.

It's supposed to be a very simple piano (5 or 6 keys maximum). I've found different alternatives, and the ones I've found till now are:

  • consol.beep (); but I feel its sound is not like the tone of the piano
  • saving and playing WAV files. I thought of getting wav files of piano tones but I feel it's the hard way to do so and it won't be salable any may take much unneeded space

Is there a library to play a piano-like tones or any different tones of a different musical instruments?

3 Answers 3

11

Checkout the downloadable source for Mike Gold's Virtual Piano in C#. I think it has what you're looking for.

You may also want to check out this post: Is it possible to generate a constant sound in C# while adjusting its frequency? . The basic idea is that you have a single sample, and you programmatically manipulate the frequency of the sound file, thus generating a different note.

As far as libraries that can help you, you can take a look at:

7

Did you think about using MIDI?

This can be useful.

See http://grouplab.cpsc.ucalgary.ca/cookbook/index.php/VisualStudio/HowToPlayMIDIInstruments

This one is very interesting, it allows you to play sounds in a simple way like this:

MidiPlayer.Play( new NoteOn( 0, 1, "C4", 127 ) );

You can also take a look at this code project page. See http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx

1
  • 1
    The grouplab.cpsc.ucalgary.ca page no longer points to a viable library.
    – Eponymous
    Apr 25, 2015 at 1:42
1

saving and playing WAV files i thought of Getting wav files of piano tones but i feel it's the hard way to do so and it wont be salable any may take much unneeded space

I don't know what level of realism you are seeking, but high end digital pianos have several digital samples per key to represent the different dynamics of hard/soft key presses, so I wouldn't rule this out as a possibility. A big consideration is polyphony, i.e. how many notes can be audible at once.

Minor pitch adjustments can reduce the number of samples needed, e.g. one note can usually be pitched up/down a few semitones without too much degradation.

Alternatively, you might look into playing MIDI samples back. Nearly any modern sound card has the basic 128 MIDI patches, though quality can vary widely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.