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).
\ 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:
10 1 DO 100 I 100 * BEEP LOOP
50 3000 DO 30 I BEEP I 17 / NEGATE +LOOP
MIXER+ ( % -- )
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@.
\ 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@.
\ 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).
MIXER-STATE ( -- ? )
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).
\ unmuting the sound if it was muted \ and increasing the volume by 50% MIXER-STATE 0= IF MIXER-UNMUTE THEN 50 MIXER-UP
MIXER-VOLUME! ( % -- )
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!
MIXER-VOLUME@ ( -- % )
Postfix word which puts on the stack the current sound volume value (Volume Control applet). The value is counted in percents.
\ printing the current volume value to console: MIXER-VOLUME@ . CR
Plays a .wav file in asynchronous mode: task is not suspended while the .wav file is being played.
#( test_play_sound NoActive Action: PLAY-SOUND: "c:\my.wav" )#
Plays a .wav file in synchronous mode: task is suspended until the .wav file has been played.
#( 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