RosettaCodeData/Task/Musical-scale/XPL0/musical-scale.xpl0
2023-07-01 13:44:08 -04:00

21 lines
709 B
Text

\Square waves on the beeper speaker:
code Sound=39;
real Period; int I;
[Period:= 1190000.0/261.625565; \middle C
for I:= 2 to 9 do
[Sound(1, 4, fix(Period)); \times 2^(-1/6) else 2^(-1/12)
Period:= Period * (if I&3 then 0.890898719 else 0.943874313);
];
]
\MIDI grand piano (requires 32-bit Windows or Sound Blaster 16):
code Sound=39;
int Note, I;
[port($331):= $3F; \set MPU-401 into UART mode
Note:= 60; \start at middle C
for I:= 2 to 9+1 do \(last note is not played)
[port($330):= $90; port($330):= Note; port($330):= $7F;
Sound(0, 4, 1); \This "Sound" is off, but convenient 0.22 sec delay
Note:= Note + (if I&3 then 2 else 1);
];
]