uxn/projects/examples/devices/audio.usm

110 lines
2.8 KiB
Plaintext
Raw Normal View History

2021-04-21 15:44:57 -04:00
( dev/audio )
%MOD { DUP2 DIV MUL SUB }
2021-04-22 22:57:47 -04:00
@timer $1
2021-04-21 15:46:40 -04:00
@progress $1
2021-04-21 15:44:57 -04:00
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
2021-04-25 10:12:45 -04:00
|30 @Audio [ &pad $8 &adsr $2 &len $2 &addr $2 &volume $1 &pitch $1 ]
2021-04-21 15:44:57 -04:00
|0100 ( -> )
( set color pallete )
#00ff .System/r DEO2
#0f0f .System/g DEO2
#0ff0 .System/b DEO2
2021-04-21 15:44:57 -04:00
;on-frame .Screen/vector DEO2 ( run on-frame every 1/60th of a second )
2021-04-25 10:12:45 -04:00
#ff .Audio/volume DEO ( set volume to max )
;saw .Audio/addr DEO2 ( set waveform to saw for audio engine )
;saw/end ;saw SUB2 #0002 SFT2 .Audio/len DEO2
#1202 .Audio/adsr DEO2 ( set envelope for audio engine )
2021-04-21 15:44:57 -04:00
BRK
@on-frame ( -> )
( incr ) .timer PEK #01 ADD .timer POK
( skip ) .timer PEK #10 EQU ,&play-note JNZ BRK &play-note
2021-04-21 15:44:57 -04:00
( get note )
;melody #00 .progress PEK ADD2 GET
2021-04-21 15:44:57 -04:00
( play note )
2021-04-25 10:12:45 -04:00
DUP .Audio/pitch DEO
2021-04-21 15:44:57 -04:00
( erase last note )
#20 .Screen/color DEO
2021-04-21 15:44:57 -04:00
( draw note )
#00 SWP #0004 MUL2 #0100 SUB2 .Screen/y DEO2
#00 .progress PEK #0008 MUL2 .Screen/x DEO2
;dot .Screen/addr DEO2
#21 .Screen/color DEO
2021-04-21 15:44:57 -04:00
( incr ) .progress PEK #01 ADD #20 MOD .progress POK
2021-04-21 15:44:57 -04:00
#00 .timer POK
2021-04-21 15:44:57 -04:00
BRK
@silence ( -> )
BRK
( defines a sawtooth wave. )
@saw ( -> )
2021-04-25 10:12:45 -04:00
dfa0 df40 dee0 de80 de20 ddc0 dd60 dd00
dca0 dc40 dbe0 db80 db20 dac0 da60 da00
d9a0 d940 d8e0 d880 d820 d7c0 d760 d700
d6a0 d640 d5e0 d580 d520 d4c0 d460 d400
d3a0 d340 d2e0 d280 d220 d1c0 d160 d100
d0a0 d040 cfe0 cf80 cf20 cec0 ce60 ce00
cda0 cd40 cce0 cc80 cc20 cbc0 cb60 cb00
caa0 ca40 c9e0 c980 c920 c8c0 c860 c800
c7a0 c740 c6e0 c680 c620 c5c0 c560 c500
c4a0 c440 c3e0 c380 c320 c2c0 c260 c200
c1a0 c140 c0e0 c080 c020 bfc0 bf60 bf00
bea0 be40 bde0 bd80 bd20 bcc0 bc60 bc00
bba0 bb40 bae0 ba80 ba20 b9c0 b960 b900
b8a0 b840 b7e0 b780 b720 b6c0 b660 b600
b5a0 b540 b4e0 b480 b420 b3c0 b360 b300
b2a0 b240 b1e0 b180 b120 b0c0 b060 b000
afa0 af40 aee0 ae80 ae20 adc0 ad60 ad00
aca0 ac40 abe0 ab80 ab20 aac0 aa60 aa00
a9a0 a940 a8e0 a880 a820 a7c0 a760 a700
a6a0 a640 a5e0 a580 a520 a4c0 a460 a400
a3a0 a340 a2e0 a280 a220 a1c0 a160 a100
a0a0 a040 9fe0 9f80 9f20 9ec0 9e60 9e00
9da0 9d40 9ce0 9c80 9c20 9bc0 9b60 9b00
9aa0 9a40 99e0 9980 9920 98c0 9860 9800
97a0 9740 96e0 9680 9620 95c0 9560 9500
94a0 9440 93e0 9380 9320 92c0 9260 9200
91a0 9140 90e0 9080 9020 8fc0 8f60 8f00
8ea0 8e40 8de0 8d80 8d20 8cc0 8c60 8c00
8ba0 8b40 8ae0 8a80 8a20 89c0 8960 8900
88a0 8840 87e0 8780 8720 86c0 8660 8600
85a0 8540 84e0 8480 8420 83c0 8360 8300
82a0 8240 81e0 8180 8120 80c0 8060 8000
&end
2021-04-21 15:44:57 -04:00
BRK
2021-04-21 15:46:40 -04:00
( song data, #ff is used for a rest )
2021-04-21 15:44:57 -04:00
@melody [
54 52 54 4f 4b 4f 48 ff
54 52 54 4f 4b 4f 48 ff
54 56 57 56 57 54 56 54
56 52 54 52 54 50 54 ff
]
2021-04-21 15:46:40 -04:00
( dot sprite )
2021-04-21 15:44:57 -04:00
@dot [ 003c 7eff 7e3c 0000 ]