User Tools

Site Tools


using_20the_20internal_20speaker

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. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
using_20the_20internal_20speaker.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1