Computer Science Canada

Sound Finder

Author:  ericfourfour [ Fri Jan 18, 2008 7:54 pm ]
Post subject:  Sound Finder

I made a quick program to help find sounds. I made this because I thought it would be useful for this thread: http://compsci.ca/v3/viewtopic.php?p=152437.

You can customize all of the controls but here are the defaults:

Change Frequency: up/down arrow keys
Change Duration: left/right arrow keys
Play the sound: enter key
Exit program: escape key

Turing:
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


: