Working with Sounds
BEEP: <length_in_ms> <frequency_in_hz>
Causes your computer to beep using internal speaker. You can specify the beep's length (in milliseconds) and frequency (in hertz).
Example:
\ making a 500 Hz beep half a second long BEEP: 500 500
You can use a postfix version of this word (BEEP) in order to be able to pick up length and frequency values directly from the stack:
<length_in_ms> <frequency_in_hz> BEEP
In this way, you can create some curious and funny sound effects for various events:
Examples:
10 1 DO 100 I 100 * BEEP LOOP
50 3000 DO 30 I BEEP I 17 / NEGATE +LOOP
This postfix word increases or decreases volume of the sound (Volume Control applet) by specified number of percents. To increase the volume use positive value, to decrease the volume use negative value. You can find the current volume value using the word MIXER-VOLUME@.
Examples:
\ increase the volume by 10% 10 MIXER+ \ decrease the volume by 30% -30 MIXER+
MIXER-DOWN ( % -- )
MIXER-UP ( % -- )
Postfix words to decrease/encrease volume of the sound (Volume Control applet) by specified number of percents. You can find the current volume value using the word MIXER-VOLUME@.
Examples:
\ increase the volume by 10% 10 MIXER-UP \ decrease the volume by 30% 30 MIXER-DOWN
Postfix words to mute/unmute volume of the sound (Volume Control applet).
Postfix word which returns TRUE (-1) if sound is unmuted (the Mute checkbox in Volume Control applet was not set) and FALSE (0) if sound is muted (the Mute checkbox in Volume Control applet was set).
Example:
\ unmuting the sound if it was muted \ and increasing the volume by 50% MIXER-STATE 0= IF MIXER-UNMUTE THEN 50 MIXER-UP
Postfix word which set the current sound volume (Volume Control applet) to a specified value in percents.
Примеры:
\ set volume to 10% 10 MIXER-VOLUME! \ set volume to 90% 90 MIXER-VOLUME!
Postfix word which puts on the stack the current sound volume value (Volume Control applet). The value is counted in percents.
Example:
\ printing the current volume value to console: MIXER-VOLUME@ . CR
PLAY-SOUND: "path_of_wav_file"
Plays a .wav file in asynchronous mode: task is not suspended while the .wav file is being played.
Example:
#( test_play_sound NoActive Action: PLAY-SOUND: "c:\my.wav" )#
PLAY-SOUNDW: "path_of_wav_file"
Plays a .wav file in synchronous mode: task is suspended until the .wav file has been played.
Example:
#( test_play_soundw NoActive Action: PLAY-SOUNDW: "c:\my.wav" \ ... the next line will be executed only after
\ the .wav file has been played to the end
)#