Skip to content

This is a project that shows how to produce sounds in Turbo Pascal.

License

Notifications You must be signed in to change notification settings

pontazaricardo/Turbo_Pascal_Sounds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turbo_Pascal_Sounds

This is a project that shows how to implement sounds using Turbo Pascal.

demo01

Installation

Just open the file SOUNDTES.PAS in Turbo Pascal.

demo02

Execution

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:

  1. A high pitch sound example.
  2. A low pitch sound example.
  3. An increasing sound gradient example.
  4. A decreasing sound gradient example.
  5. A random composition.

And the menu also has two extra options:

  1. Modify the length of the produced pitches.
  2. Exit the program.

demo01

Code

There are two important sections to address in the code for this program: the sound generation and the jumps for the menu.

Sound generation

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).

Notes

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.

Menu jumps

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.

demo02

Releases

No releases published

Packages

No packages published

Languages