Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playing piano tones using C#

Tags:

c#

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?

like image 331
Hady Elsahar Avatar asked Nov 13 '11 02:11

Hady Elsahar


People also ask

What is C * in piano?

The C major chord is made up of three notes: C, E, and G. To play the root position chord on the piano with your right hand, you'd use the following three fingers: G - Fifth finger (5) E - Third finger (3) C - First finger (1)

What is the pitch for middle C?

The pitch increases with frequency. Thus, the frequency of middle C is 256 Hz, and the frequency of the A above is 440 Hz.


2 Answers

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

like image 77
Salvatore Previti Avatar answered Sep 28 '22 23:09

Salvatore Previti


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:

  • NAudio @codeplex
  • C# MIDI Toolkit @codeproject
  • Wrapper Library for Windows MIDI API @codeproject
like image 24
smartcaveman Avatar answered Sep 28 '22 23:09

smartcaveman