Musical scale: Difference between revisions

Added solution for Action!
m (→‎Lua Windows: simplified math)
(Added solution for Action!)
Line 14:
 
For languages that cannot utilize a sound device, it is permissible to output to a musical score sheet (or midi file), or the task can be omitted.
 
=={{header|Action!}}==
<lang Action!>DEFINE PTR="CARD"
 
PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
 
PROC Main()
BYTE AUDCTL=$D208,AUDF1=$D200,AUDC1=$D201,AUDF2=$D202,AUDC2=$D203
PTR ARRAY notes(8)
BYTE ARRAY pitch8=[60 53 47 45 40 35 31 30]
CARD ARRAY pitch16=[1703 1517 1350 1274 1134 1010 899 848]
BYTE i
CARD p
 
notes(0)="Do" notes(1)="Re" notes(2)="Mi" notes(3)="Fa"
notes(4)="Sol" notes(5)="La" notes(6)="Si" notes(7)="Do"
 
PrintE("8-bit precision pitch values:")
FOR i=0 TO 7
DO
PrintF("%S-%B ",notes(i),pitch8(i))
Sound(0,pitch8(i),10,10)
Wait(20)
OD
SndRst()
Wait(20)
PutE() PutE()
 
AUDCTL=$50 ;join channel 1 and 2 to get 16-bit
AUDC1=$A0 ;turn off channel 1
AUDC2=$AA ;turn on channel 2
PrintE("16-bit precision pitch values:")
FOR i=0 TO 7
DO
PrintF("%S-%U ",notes(i),pitch16(i))
p=pitch16(i)
AUDF2=p RSH 8
AUDF1=p&$FF
Wait(20)
OD
SndRst()
AUDCTL=$00 ;restore default configuration
Wait(20)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Musical_scale.png Screenshot from Atari 8-bit computer]
<pre>
8-bit precision pitch values:
Do-60 Re-53 Mi-47 Fa-45 Sol-40 La-35 Si-31 Do-30
 
16-bit precision pitch values:
Do-1703 Re-1517 Mi-1350 Fa-1274 Sol-1134 La-1010 Si-899 Do-848
</pre>
 
=={{header|AmigaBASIC}}==
Anonymous user