Walker News

C# Source Code Of A Beep Program That Supports Adjustable Frequency and Duration

With reference to MSDN, I have modified the sample source code to compile a simple beep program that have options to produce different pitch or tone frequency and duration.

For those who are interested, you may download the ready-to-run console program or compile the source code with free C# command-line compiler (can be found in Windows SDK for Windows 7 and .Net Framework 4):
using System;

class Sample 
  public static void Main() 
    string[] args = Environment.GetCommandLineArgs();
    if (args.Length != 3)
      Console.ForegroundColor = ConsoleColor.Green;
      Console.WriteLine("www.WalkerNews.net - a " +
        "capsule of Walker's experience in life");
      Console.WriteLine("Syntax: wBeep FRE DUR");
      Console.WriteLine("FRE is beep frequency" + 
        " (min. 37; max. 32767)");
      Console.WriteLine("DUR is beep duration (ms)" +
        " (min. 1)");
      int beepfre = Convert.ToInt32(args[1]);
      int beepdur = Convert.ToInt32(args[2]); 
      Console.Beep(beepfre, beepdur);

The code is modified from the Console.Beep example published by MSDN, to allow user defines frequency (valid range is 37-32767) and duration (must not be 0) at runtime via console program arguments.

MD5 checksum of download files:
  • wbeep.zip – 11e29a21b4ef3eb051fc2716bbe8d1da
  • wbeep.exe – 0d67312deacd6a5660340a1b20814410
  • wbeep.cs – d81050be010f3a73431d135825f0d379

Custom Search

2017  •  Privacy Policy