SOUND.PAS 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. program SoundDemo;
  2. {$C-}
  3. {
  4. SOUND DEMONSTRATION PROGRAM Version 1.00A
  5. This program demonstrates TURBO PASCAL's standard procedures Sound,
  6. Delay and NoSound on the IBM PC and true compatibles.
  7. PSEUDO CODE
  8. 1. Sound an alarm until a key is pressed.
  9. a. Play G and D in octave 4
  10. 2. Sound a siren until a key is pressed.
  11. INSTRUCTIONS
  12. 1. Compile and run this program using the TURBO.COM compiler.
  13. 2. Type any key to stop the alarm.
  14. 3. Type any key to stop the siren and end the program.
  15. }
  16. type
  17. NoteRecord = record
  18. C,CF,D,DF,E,F,FF,G,GF,A,AF,B: integer;
  19. end;
  20. const
  21. Notes: NoteRecord =
  22. (C:1;CF:2;D:3;DF:4;E:5;F:6;FF:7;G:8;GF:9;A:10;AF:11;B:12);
  23. var
  24. ch : char;
  25. procedure Play(Octave,Note,Duration: integer);
  26. { Play Note in Octave Duration milliseconds
  27. Frequency computed by first computing C in
  28. Octave then increasing frequency by Note-1
  29. times the twelfth root of 2. (1.059463994)
  30. If Duration is zero Note will be played
  31. until you activate procedure NoSound }
  32. var
  33. Frequency : real;
  34. I : integer;
  35. begin
  36. Frequency := 32.625;
  37. for I := 1 to Octave do { Compute C in Octave }
  38. Frequency := Frequency * 2;
  39. for I := 1 to Note - 1 do { Increase frequency Note-1 times }
  40. Frequency := Frequency * 1.059463094;
  41. if Duration <> 0 then
  42. begin
  43. Sound(Round(Frequency));
  44. Delay(Duration);
  45. NoSound;
  46. end
  47. else Sound(Round(Frequency));
  48. end;
  49. procedure SoftAlarm;
  50. { Play the notes G and D in octave three 7 times
  51. each with a duration of 70 milliseconds. }
  52. var
  53. I: integer;
  54. begin
  55. for I := 1 to 7 do
  56. with Notes do
  57. begin
  58. Play(4,G,70);
  59. Play(4,D,70);
  60. end;
  61. delay(1000);
  62. end;
  63. procedure Siren;
  64. var
  65. Frequency: integer;
  66. begin
  67. for Frequency := 500 to 2000 do
  68. begin
  69. Delay(1);
  70. Sound(Frequency);
  71. end;
  72. for Frequency := 2000 downto 500 do
  73. begin
  74. Delay(1);
  75. Sound(Frequency);
  76. end;
  77. NoSound;
  78. end;
  79. procedure SoundAlarm;
  80. begin
  81. Writeln('Press any key to Stop');
  82. repeat
  83. SoftAlarm
  84. until KeyPressed;
  85. Read(kbd,ch);
  86. end; {SoundAlarm}
  87. procedure SoundSiren;
  88. begin
  89. Writeln('Press any key to Stop');
  90. repeat
  91. Siren
  92. until KeyPressed;
  93. Read(kbd,ch)
  94. end; {SoundSiren}
  95. begin
  96. SoundAlarm;
  97. SoundSiren;
  98. end.
  99.