const MIN_HZ : int := 20 % Minimum for human ear is 20Hz.
const MAX_HZ : int := 20000 % Maximum for human ear is 20 000Hz.
const DEFAULT_HZ : int := 440 % A4
const DEFAULT_DURATION : int := 100
const INCREASE_HZ : char := KEY_UP_ARROW
const DECREASE_HZ : char := KEY_DOWN_ARROW
const INCREASE_DURATION : char := KEY_RIGHT_ARROW
const DECREASE_DURATION : char := KEY_LEFT_ARROW
const PLAY_SOUND : char := KEY_ENTER
const EXIT_PROGRAM : char := KEY_ESC
const TIME_DELAY : int := 30
var frequency : int := DEFAULT_HZ
var duration : int := DEFAULT_DURATION
loop
locate (1, 1)
put "Frequency: ", frequency
put "Duration: ", duration
put "sound (", frequency, ", ", duration, ")"
if hasch then
var c : char := getchar
if c = INCREASE_HZ then
frequency := min (frequency + 1, MAX_HZ )
elsif c = DECREASE_HZ then
frequency := max (frequency - 1, MIN_HZ )
elsif c = INCREASE_DURATION then
duration + = 1
elsif c = DECREASE_DURATION then
duration - = 1
elsif c = PLAY_SOUND then
sound (frequency, duration )
Input.Flush
elsif c = EXIT_PROGRAM then
exit
end if
end if
Time.Delay (TIME_DELAY )
end loop |