[Home] [Puzzles & Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities]
Windows has a synchronous Beep function which allows the caller to specify the frequency and duration of the beep. Synchronous means that the function does not return until the beep has ended. Unfortunately, the function ignores frequency and duration if called from Windows 95, 98 or ME. Even worse, the function operate asynchronously, i.e. it returns immediately. If the program needs to sound multiple beeps, there is no way to know when the first beep has completed so that the second can begin.
Here's a program that addresses the situation with a BeepEx procedure that synchronously plays sounds of a specified frequency and duration under all Windows operating systems.
The key is to directly address the PC Speaker with a small bit of assembly language code which I found in a unit named Bleeper. Bleeper is one unit in a freeware download by Andy Preston named BleeperInt available from Torry.net and a few other places. Bleeper is also included with this demo. .
The demo allows users to set a frequency and duration and sounds the appropriate beep when a button is clicked. A second button plays a major scale starting at the specified frequency and playing each note for the specified duration.
Radio group buttons allow you to test the Windows version of Beep vs. the new BeepEx. For Windows NT. 200 and XP, there should be no difference. For lower Windows versions, a big difference!
Addendum April 13, 2007: Viewer Samuel from one of my favorite European countries, The Netherlands, recently sent me the numeric codes for a Minor scale and said that he was working on a full 88 key piano keyboard. That may exceed the capacity of a PC speaker to reproduce, but I wish him luck. I added it and a chromatic scale today. Also added a "melody player" procedure, PlayTune, which takes an array integer pairs representing the frequency and duration of each note. Now if someone just writes a "tune editor" it could play more than one song.
Copyright © 2000-2013, Gary Darby
All rights reserved.