home *** CD-ROM | disk | FTP | other *** search
- PROGRAM AGTsound;
-
- (* Adapted by Dave Malmberg -- but, based on ... *)
-
- {****************************************************************************}
- {* SOUND TOOLS *}
- {* Version 1.0, October 26, 1988 *}
- {* *}
- {* Written by: Turbo Pascal sound generation tools. *}
- {* Nels Anderson *}
- {* 92 Bishop Drive Released to the public domain. *}
- {* Framingham, MA 01701 *}
- {* *}
- {****************************************************************************}
-
- { Sound effects demo }
-
- USES
- Crt;
-
- { Sound Effects }
-
- CONST Maxtones = 10000;
-
- TYPE
- AGT_tone = RECORD
- Frequency, {Frequency in Hertz}
- Duration, {Length of tone in milleseconds}
- Pause {Length of pause between tones in milleseconds}
- : Word;
- END;
-
- VAR
- AGT_tones : Word; (* AGT sound array size *)
-
- AGT_sound : ARRAY[0..Maxtones] OF AGT_tone;
-
-
- PROCEDURE Play_AGT_sound; (* Routine to play AGT sound/music array *)
-
- VAR K : Word;
-
- BEGIN
- K := 0;
- AGT_tones := AGT_sound[K].Frequency;
- REPEAT
- Inc(K);
- IF AGT_sound[K].Frequency = 0
- THEN NoSound
- ELSE Sound(AGT_sound[K].Frequency); (* Frequency *)
- Delay(AGT_sound[K].Duration); (* Length of tone *)
- NoSound;
- Delay(AGT_sound[K].Pause); (* Length of "pause' between tones *)
- UNTIL K >= AGT_tones;
- NoSound;
- END;
-
- PROCEDURE PlayATone(Play_Freq, Play_Duration, Rest_Duration : Word);
- BEGIN
- IF Play_Freq > 0
- THEN Sound(Play_Freq) (* Hertz *)
- ELSE NoSound;
- Delay(Play_Duration); (* Milliseconds *)
- NoSound;
- Delay(Rest_Duration); (* Milliseconds *)
- IF AGT_tones < Maxtones
- THEN BEGIN
- Inc(AGT_tones);
- IF Play_Freq > 0
- THEN AGT_sound[AGT_tones].Frequency := Play_Freq
- ELSE AGT_sound[AGT_tones].Frequency := 0;
- AGT_sound[AGT_tones].Duration := Play_Duration;
- AGT_sound[AGT_tones].Pause := Rest_Duration;
- END;
- END; (* PlayAtone *)
-
-
- CONST
- Cuckoo : ARRAY[1..5] OF Integer = (247, -62, 150, 2, 0);
- UhOh : ARRAY[1..13] OF Integer = (33, 7, 20, 13, -1, 0, 20, 1, 62, -3, 20, 13, 0);
- Bat : ARRAY[1..5] OF Integer = (12000, -100, 6, 106, 0);
- BirdCall : ARRAY[1..13] OF Integer = (3500, 0, 50, 1, 3000, 0, 50, 1, 4000, 0, 50, 1, 0);
- ClockTick : ARRAY[1..9] OF Integer = (12500, 0, 19, 1, -1, 0, 1000, 1, 0); {uses frequency of -1 for silence}
- Conveyor : ARRAY[1..5] OF Integer = (37, 1, 3, 64, 0);
- Crickets : ARRAY[1..13] OF Integer = (1800, 0, 3, 10, 2000, 0, 1, 1, -1, 0, 100, 1, 0);
- DoorBuzzer : ARRAY[1..5] OF Integer = (5700, 1500, 1, 7, 0);
- Explosion : ARRAY[1..5] OF Integer = (300, 150, 6, 10, 0);
- PhoneRing : ARRAY[1..9] OF Integer = (523, 0, 28, 1, 659, 0, 28, 1, 0);
- FlyingSaucer : ARRAY[1..5] OF Integer = (500, 200, 28, 5, 0);
- Siren : ARRAY[1..9] OF Integer = (200, 1, 2, 800, 1000, -1, 2, 800, 0);
- Drip : ARRAY[1..9] OF Integer = (1000, 100, 8, 3, -1, 0, 600, 1, 0);
- Train : ARRAY[1..5] OF Integer = (1700, -4, 1, 416, 0);
- Whoop : ARRAY[1..5] OF Integer = (900, 1, 5, 100, 0);
- Phaser : ARRAY[1..5] OF Integer = (300, 100, 6, 15, 0);
-
- TYPE
- IntArray = ARRAY[1..2] OF Integer;
-
- PROCEDURE SndEff(Info : Pointer);
- { Generate sounds according to the Info table. Each table entry contains the
- following:
-
- Starting Tone in Hz
- Freq. change in Hz per repetition
- Milliseconds between changes
- Number of repetitions
-
- The table can repeat these parameters as many times as necessary. To end
- the table a single 0 is required.
- }
- VAR
- Table : ^IntArray;
- i, tone,
- offset : Integer;
- BEGIN
- offset := 0; {init. offset into table}
- Table := Info; {set pointer}
- REPEAT
- tone := Table^[offset+1]; {get initial tone}
- FOR i := 1 TO Table^[offset+4] DO BEGIN {for each repetition...}
- PlayATone(tone, Table^[offset+3], 0);
- tone := tone+Table^[offset+2]; {change tone}
- END; {for i}
- offset := offset+4; {increment offset into table}
- UNTIL Table^[offset+1] = 0; {until end of table}
- NoSound;
- END; {SoundEff procedure}
-
-
- PROCEDURE CustomSound; (* Put your own custom sound in this routine *)
- { The example below has the sound made when a spell is cast }
- VAR
- z : Real;
- BEGIN
- { This example has a sound made when a spell is cast }
- z := 1;
- REPEAT
- PlayATone(Round((Sin(z)+40)*50), 11, 0);
- z := z+0.4
- UNTIL z >= 30;
- NoSound;
- END; {CustomSound procedure}
-
- VAR
- K : Word;
- AGT_Tone_File : FILE OF AGT_tone;
- c : Char;
- soundnum : Integer;
- Filename : String;
-
- PROCEDURE WriteAGTsoundFile;
- BEGIN
- AGT_sound[0].Frequency := AGT_tones;
-
- Filename := 'TEMP.MUC'; (* You must rename the file in order to save it *)
- Assign(AGT_Tone_File, Filename);
- Rewrite(AGT_Tone_File);
- FOR K := 0 TO AGT_tones DO Write(AGT_Tone_File, AGT_sound[K]);
- Close(AGT_Tone_File);
- END;
-
- BEGIN {Main routine}
-
- AGT_tones := 0; (* AGT sound array size *)
-
- FOR K := 0 TO Maxtones DO (* "Zero" out AGT sound array *)
- BEGIN
- AGT_sound[K].Frequency := 0;
- AGT_sound[K].Duration := 0;
- AGT_sound[K].Pause := 0;
- END;
-
- REPEAT
- WriteLn('Select by Number:');
- WriteLn('1) Bat');
- WriteLn('2) Bird Call');
- WriteLn('3) Clock Tick');
- WriteLn('4) Conveyor');
- WriteLn('5) Crickets');
- WriteLn('6) Door Buzzer');
- WriteLn('7) Explosion');
- WriteLn('8) Phone Ringing');
- WriteLn('9) Flying Saucer');
- WriteLn('10) Siren');
- WriteLn('11) Drip');
- WriteLn('12) Train');
- WriteLn('13) Whoop');
- WriteLn('14) Phaser');
- WriteLn('15) Cuckoo');
- WriteLn('16) Uh oh');
- WriteLn('17) Your Own Custom Sound');
- Write('Select sound, 0 to quit: ');
- ReadLn(soundnum);
- IF soundnum > 0 THEN BEGIN
- WriteLn('Hit a key to stop...');
- AGT_tones := 0; (* "Zero" out AGT sound array *)
- REPEAT
- CASE soundnum OF
- 1 : SndEff(@Bat);
- 2 : SndEff(@BirdCall);
- 3 : SndEff(@ClockTick);
- 4 : SndEff(@Conveyor);
- 5 : SndEff(@Crickets);
- 6 : SndEff(@DoorBuzzer);
- 7 : SndEff(@Explosion);
- 8 : SndEff(@PhoneRing);
- 9 : SndEff(@FlyingSaucer);
- 10 : SndEff(@Siren);
- 11 : SndEff(@Drip);
- 12 : SndEff(@Train);
- 13 : SndEff(@Whoop);
- 14 : SndEff(@Phaser);
- 15 : BEGIN SndEff(@Cuckoo); soundnum := 999; END;
- 16 : BEGIN SndEff(@UhOh); soundnum := 999; END;
- 17 : CustomSound;
- END; {case}
- UNTIL KeyPressed;
- c := ReadKey;
- END; {if soundnum > 0}
- UNTIL soundnum = 0;
-
- NoSound;
-
- WriteLn;
- Write('Would you like to save that last sound as an AGT .MUC file? (Y/N) ');
- c := ReadKey;
- IF (c = 'Y') OR(c = 'y') THEN
- BEGIN
- WriteAGTsoundFile;
- WriteLn;
- WriteLn;
- WriteLn('The AGT sound file is ', Filename, ' -- with ', AGT_tones, ' total tones');
-
- WriteLn;
- WriteLn('Here is what it sounds like....');
-
- AGT_tones := 0; (* AGT sound array size *)
-
- FOR K := 0 TO Maxtones DO
- BEGIN
- AGT_sound[K].Frequency := 0;
- AGT_sound[K].Duration := 0;
- AGT_sound[K].Pause := 0;
- END;
-
- Assign(AGT_Tone_File, Filename);
- Reset(AGT_Tone_File);
- Read(AGT_Tone_File, AGT_sound[0]);
- AGT_tones := AGT_sound[0].Frequency;
- FOR K := 1 TO AGT_tones DO Read(AGT_Tone_File, AGT_sound[K]);
- Close(AGT_Tone_File);
-
- Play_AGT_sound;
-
- NoSound;
- END; (* Record AGT .MUC sound file and played it back *)
-
- END.
-