PROG3.LST 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Listing:
  2. 1 MODULE prog3;
  3. 2 (* This program plays musical scales *)
  4. 3 FROM Lib IMPORT Speaker, Delay;
  5. 4 FROM MATHLIB IMPORT Exp,Log;
  6. 5
  7. 6 CONST MiddleC = 131.0;
  8. 7 TYPE NoteType = SHORTINT;
  9. 8 TYPE ScaleType = ARRAY [1..8] OF NoteType;
  10. ***** ^ not supported yet
  11. ***** ^ not supported yet
  12. 9 CONST major = ScaleType(0,2,4,5,7,9,11,12);
  13. ***** ^ not supported yet
  14. 10 CONST minor = ScaleType(0,2,3,5,7,8,11,12);
  15. ***** ^ not supported yet
  16. 11
  17. 12 PROCEDURE PlayScale(mode : ScaleType; key : NoteType);
  18. 13 VAR
  19. 14 i:[1..8];
  20. 15 note:NoteType;
  21. 16 freq:LONGREAL;
  22. 17 BEGIN
  23. 18 FOR i := 1 TO 8 DO
  24. 19 note := key + mode[i];
  25. ***** ^ not supported yet
  26. ***** ^ not supported yet
  27. 20 freq := MiddleC * Exp(LONGREAL(note) * (Log(2.0)/12.0));
  28. ***** ^ not supported yet
  29. ***** ^ not supported yet
  30. ***** ^ not supported yet
  31. ***** ^ not supported yet
  32. ***** ^ not supported yet
  33. 21 Speaker(CARDINAL(freq),200);
  34. ***** ^ not supported yet
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. 22 END;
  38. 23 Delay(500);
  39. ***** ^ not supported yet
  40. ***** ^ not supported yet
  41. 24 END PlayScale;
  42. ***** ^ not supported yet
  43. 25
  44. 26 BEGIN
  45. 27 PlayScale(major, 0); (* C major *)
  46. ***** ^ not supported yet
  47. ***** ^ not supported yet
  48. 28 PlayScale(minor, 2); (* D minor *)
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. 29 END prog3.
  52. 30
  53. 21 errors