write a c program which plays 200hz for 100ms in csharp

Here is a sample C# program which plays a 200Hz tone for 100ms using the System.Media.SoundPlayer class:

using System;
using System.Media;

class Program
{
    static void Main()
    {
        int frequency = 200;  // Hz
        int duration = 100;   // ms
        int amplitude = 32767; // 16-bit amplitude (max value)

        // Create a buffer to hold the sound data
        byte[] buffer = new byte[duration * 44100 / 1000 * 2];

        // Fill the buffer with a sine wave at the specified frequency
        for (int i = 0; i < buffer.Length / 2; i++)
        {
            double angle = i / ((double)44100 / frequency) * 2.0 * Math.PI;
            short sample = (short)(amplitude * Math.Sin(angle));
            buffer[i * 2] = (byte)(sample & 0xff);
            buffer[i * 2 + 1] = (byte)(sample >> 8);
        }

        // Play the sound
        SoundPlayer player = new SoundPlayer(new System.IO.MemoryStream(buffer));
        player.PlaySync();
    }
}
862 chars
29 lines

This program generates a sine wave at the specified frequency and duration, and then plays the sound using the SoundPlayer class. Note that this program assumes a sample rate of 44100 Hz and a 16-bit audio format. If your system uses a different sample rate or audio format, you may need to modify the program accordingly.

gistlibby LogSnag