I did a little bit of tinkering with an audio application a while ago which generated a variety of different audio waveforms. It is surprisingly easy to generate quite a few of the more common ones such as white noise and sine waves, so here is a little howto to implement this in C#.

White noise is pure and simply just random data being played back. It is the sound of static and of waterfalls. In practice, white noise is very useful for muffling other sounds, which is why you sometimes see in movies, scenes where to beat bugs listening in on conversations, the actors turn on a tap before talking about some state secret. The white noise from the flowing water defeats the listening devices.

This is dreadfully easy to implement, and simply entails filling a buffer with random values between 0 and 255. The buffer can then be played back, or saved as an audio file.

		private void GenerateWhiteNoise(ref byte[] SampleBuffer, int NumSamples)
			Random rnd1 = new System.Random();
			for (int i = 0; i < NumSamples; i++)
				SampleBuffer[i] = (byte) rnd1.Next(255);

The next wave to look at is the sine wave. This type of wave gives a pure sounding tone. Here, what we need is the number of samples, the desired frequency and the sample rate.
continue reading...