nxu/synthdemo.tal

67 lines
2.3 KiB
Tal
Raw Permalink Normal View History

2023-08-21 23:23:29 -04:00
( synth demo using new device )
|30 @Audio [
&vec $2 ( callback vector )
&dur $2 ( duration in ms )
&mode $1 ( mode -- currently articulation )
&vol $1 ( L/R volume 0-f )
&a $1 ( envelope: attack, 10ms resolution )
&d $1 ( envelope: decay, 10ms resolution )
&s $1 ( envelope: sustain, 10ms resolution )
&r $1 ( envelope: release, 10ms resolution )
&len $2 ( waveform data length in bytes )
&addr $2 ( waveform data address )
&detune $1 ( fractional semitone detune )
&pitch $1 ( MIDI pitch to play )
]
|0000
@step $2
@tempo $2
|0100
#00bb .tempo STZ2
#ff .Audio/vol DEO
;square .Audio/addr DEO2
#0002 .Audio/len DEO2
;play .Audio/vec DEO2
( #00 .Audio/mode DEO )
#30 .Audio/mode DEO
#00 .Audio/a DEO
#01 .Audio/d DEO
#08 .Audio/s DEO
#08 .Audio/r DEO
( fall-through )
@play
.tempo LDZ2 .Audio/dur DEO2 ( ; dur<-tempo )
.step LDZ2k DUP2 ;notes ADD2 ( z^ step* notes+step* )
LDA .Audio/pitch DEO ( z^ step* ; pitch<-p )
INC2 DUP2 #0004 LTH2 ?&done ( z^ step+1* )
POP2 #0000 ( z^ 0* )
.tempo LDZ2k #0002 SUB2 ( z^ 0* zt^ tempo-2* )
#ea60 OVR2 #0004 MUL2 DIV2 ( z^ 0* zt^ tempo-2* bpm* )
emit-bpm ( z^ 0* zt^ tempo-2* ; emit bpm )
ROT STZ2 ( z^ 0* ; zt<-tempo-2 )
&done ROT STZ2 BRK ( ; z<-step' )
( @notes 21 21 22 23 )
@notes 39 39 3b 3c
@square ff 00
@emit-bpm ( bpm* -> )
emit-dec2 #2018 DEO LIT "b #18 DEO LIT "p #18 DEO LIT "m #18 DEO #0a18 DEO JMP2r
( emit a short as a decimal )
@emit-dec2 ( n* -> )
LITr 00 ( n [0] )
&read ( n [k] )
#000a DIV2k STH2k MUL2 SUB2 STH2r INCr ( n%10 n/10 [k+1] )
DUP2 ORA ,&read JCN
POP2 ( top element was 0000 )
&write ( n0 n1 ... nk [k+1] )
NIP #30 ADD #18 DEO LITr 01 SUBr ( n0 ... n{k-1} [k] )
STHkr ,&write JCN
POPr JMP2r