Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a sound from scratch C#

I am trying to build a virtual piano in C#, and want a way to create a scale of musical notes from scratch.

I know that I can simply find or create a bunch of .wav files, 1 for each note, but this will create too much space on the User's Hard disk and not be very intuative for myself in the future.

So is there a way to create a proper sound - e.g B flat, in C# without using a .wav file, all in code thorugh c#, and if not, is there a way to do this in a different language - C++.

Thanks, I have tried to make it as clear as possible.

like image 652
H Bellamy Avatar asked Nov 09 '11 17:11

H Bellamy


People also ask

Can we give sound to the cat in scratch?

To do this you need a Sound block ( play sound ), with Meow selected in the dropdown box. Now when you click the green flag and move the mouse around, the cat will meow all of the time.


2 Answers

I think this looks like it should get you started:

http://blogs.msdn.com/b/dawate/archive/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c.aspx

EDIT : I should add that generating sounds without .wav samples and emulating a piano are at odds with each other.

If you want to get a 'real' piano sound, it's best to work with samples (hold them in memory if you don't want to keep them in the filesystem). If you just want a simple way of emitting accurate notes (which sound nothing like a real piano) then doing it programmatically is the way to go!

like image 107
Widor Avatar answered Oct 21 '22 20:10

Widor


If you want to emulate a piano specifically you only have two options, one of which is to use samples and the other is physical modelling. Physical modelling requires some pretty advanced knowledge of DSP (filtering, convolution, etc.) and a piano would be a challenging instrument to tackle but it has been done by the likes of Pianoteq

On the subject of samples, to create a piano that is anywhere near a convincing analogue you would ideally require more than one sample per note for different velocities with crossfades between them but you can probably get away with using a sample over a limited range of notes to reduce the total number of samples.

like image 26
Steve Rowbotham Avatar answered Oct 21 '22 20:10

Steve Rowbotham