User Tools

Site Tools


Using the internal speaker

by Richard Russell, November 2007

The code in this article requires Windows NT4, Windows 2000, Windows XP or Windows Vista.

Even if your PC has a sound card (or integrated audio) it is still possible to use the internal speaker (if fitted) to produce simple sounds. You can do that using the Beep API function, as follows:

        SYS "Beep", frequency%, duration%

Here frequency% is the approximate frequency of the sound in Hertz and duration% is the approximate duration in milliseconds; frequency% must be in the range 37 Hz to 32767 Hz. Note that Windows does not return control to your BASIC program until the sound is finished.

If you prefer to specify the frequency and duration using the same parameters as the BBC BASIC SOUND statement you can do that using a simple calculation. The two statements listed below produce (nearly) the same results, but the second outputs the sound using the internal speaker:

        SOUND 1, -15, pitch%, dur%
        IF pitch% SYS "Beep", 61.7354*2^(pitch%/48), dur%*50 ELSE WAIT dur%*5
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
using_20the_20internal_20speaker.txt · Last modified: 2018/04/15 14:06 by richardrussell