# BBC BASIC Programmers' Reference

### Site Tools

using_20the_20internal_20speaker

# Differences

This shows you the differences between two versions of the page.

 using_20the_20internal_20speaker [2018/03/31 13:19]127.0.0.1 external edit using_20the_20internal_20speaker [2018/04/15 13:06] (current)richardrussell Added syntax highlighting 2018/04/15 13:06 richardrussell Added syntax highlighting2018/03/31 13:19 external edit 2018/04/15 13:06 richardrussell Added syntax highlighting2018/03/31 13:19 external edit Line 1: Line 1: =====Using the internal speaker===== =====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:\\ \\ + //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% 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 [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin7.html#​sound|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:\\ \\ + ​ + + 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 [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin7.html#​sound|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% SOUND 1, -15, pitch%, dur% IF pitch% SYS "​Beep",​ 61.7354*2^(pitch%/​48),​ dur%*50 ELSE WAIT dur%*5 IF pitch% SYS "​Beep",​ 61.7354*2^(pitch%/​48),​ dur%*50 ELSE WAIT dur%*5 +