This is a project that shows how to implement sounds using Turbo Pascal.
Just open the file SOUNDTES.PAS in Turbo Pascal.
To execute the file, just do a normal CTRL + F9 key stroke in the keyboard (or go to Compile -> Run).
The produced program has a menu that allows to reproduce different options:
- A high pitch sound example.
- A low pitch sound example.
- An increasing sound gradient example.
- A decreasing sound gradient example.
- A random composition.
And the menu also has two extra options:
- Modify the length of the produced pitches.
- Exit the program.
There are two important sections to address in the code for this program: the sound generation and the jumps for the menu.
For produce the sounds, the following code was used:
writeln('REPRODUCING...');
sound(3000);
delay(pitchlength);
nosound;
read;
where pitchlength is an integer variable previously defined which indicates the length of the pitch.
For the increasing (and decreasing) gradient scales, the following code was used
pivotGradient := 0;
writeln('REPRODUCING...');
for counter:= 0 to 40 do
begin
pivotGradient := pivotGradient + 100;
sound(pivotGradient);
delay(100);
end;
nosound;
read;
The previous code basically increases the pitch by 100 in each iteration.
Finally, for the random sounds, the random function
Random()
was used. To use this function, at the beggingin of the code, you must use the command
Randomize;
and to produce a random sound, just use do it as
sound(Random(4000));
delay(100);
where Random(4000) returns a random integer between 0 and 3999. (So you can modify this accordingly to vary the lowest and highest pitch you want to obtain).
The line
sound(3000);
indicates the frequency of the output sound. A high value will produce a high pitch, while a low value will produce a low pitch.
It is worth to mention that the lines
nosound;
read;
are needed to stop the sound. If they are not added, the sound will keep going until the program is finished.
The menu jumps were obtained by the use of labels. At the beggining of the code, the labes have to be defined as
program soun;
uses crt;
label menu, highpitch, lowpitch, gradient_up_label, gradient_down_label, random_label, correction_label, exitlabel;
Later, for defining a section of code that will be identified by a label, you use
lowpitch:
{all your code here}
goto menu;
where
goto menu;
makes it to jump to the label called menu.