working CLI tool
This commit is contained in:
parent
dab32fea09
commit
4781d9251b
121
wave.tal
121
wave.tal
|
@ -2,7 +2,7 @@
|
||||||
( )
|
( )
|
||||||
( currently reads PCM data )
|
( currently reads PCM data )
|
||||||
|
|
||||||
( WAV format (number byte order is LE) )
|
( WAV format (number byte order is little-endian) )
|
||||||
( )
|
( )
|
||||||
( BYTES EXAMPLE BYTES DESCRIPTION )
|
( BYTES EXAMPLE BYTES DESCRIPTION )
|
||||||
( 0-3 "RIFF" 52 49 46 46 riff string )
|
( 0-3 "RIFF" 52 49 46 46 riff string )
|
||||||
|
@ -29,7 +29,14 @@
|
||||||
( )
|
( )
|
||||||
( s16 -> u8: hi-byte + 0x80 )
|
( s16 -> u8: hi-byte + 0x80 )
|
||||||
( stereo -> mono, take second sample )
|
( stereo -> mono, take second sample )
|
||||||
|
( )
|
||||||
|
( data created using: )
|
||||||
|
( lame --decode tokyo-skies.mp3 # produced tokyo-skies.wav )
|
||||||
|
( sox tokyo-skies.wav -c 1 -e unsigned-integer -b 8 tokyo-skies-mono-u8.wav )
|
||||||
|
( sox tokyo-skies-mono-u8.wav tokyo-skies.raw )
|
||||||
|
|
||||||
|
( |00 @System [ &vec $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &dbg $1 &halt $1 ] )
|
||||||
|
|10 @Console [ &vec $2 &read $1 &pad $5 &out $1 &err $1 ]
|
||||||
|30 @Audio0 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
|30 @Audio0 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
||||||
|40 @Audio1 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
|40 @Audio1 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
||||||
|50 @Audio2 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
|50 @Audio2 [ &vec $2 &pos $2 &out $1 &pad $3 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|
||||||
|
@ -38,10 +45,40 @@
|
||||||
|
|
||||||
|0000
|
|0000
|
||||||
@done $1
|
@done $1
|
||||||
|
@pos $2
|
||||||
|
@is-stereo $1
|
||||||
|
@is-8bit $1
|
||||||
|
|
||||||
|0100
|
|0100
|
||||||
;path .File/name DEO2
|
;filename .pos STZ2
|
||||||
|
;read-filename .Console/vec DEO2
|
||||||
|
BRK
|
||||||
|
|
||||||
|
@read-filename ( -> )
|
||||||
|
#12 DEI ( c^ )
|
||||||
|
DUP #0a EQU ?&exec ( c^ )
|
||||||
|
DUP #00 EQU ?&exec ( c^ )
|
||||||
|
.pos LDZ2 STA ( ; $pos<-c )
|
||||||
|
.pos LDZ2 INC2 .pos STZ2 ( ; pos<-pos+1 )
|
||||||
|
BRK ( )
|
||||||
|
&exec ( c^ -> )
|
||||||
|
POP #00 .pos LDZ2 STA ( ; $pos<-0 )
|
||||||
|
!start ( )
|
||||||
|
|
||||||
|
@start ( -> )
|
||||||
|
;filename .File/name DEO2
|
||||||
parse
|
parse
|
||||||
|
.is-stereo LDZ ?&stereo
|
||||||
|
.is-8bit LDZ ?&mono-8bit
|
||||||
|
;mono-s16-to-u8 ;reload/resample STA2 #01 ;reload/sft STA !&done
|
||||||
|
&mono-8bit
|
||||||
|
;mono-u8-to-u8 ;reload/resample STA2 #00 ;reload/sft STA !&done
|
||||||
|
&stereo
|
||||||
|
.is-8bit LDZ ?&stereo-8bit
|
||||||
|
;stereo-s16-to-u8 ;reload/resample STA2 #02 ;reload/sft STA !&done
|
||||||
|
&stereo-8bit
|
||||||
|
;stereo-u8-to-u8 ;reload/resample STA2 #01 ;reload/sft STA !&done
|
||||||
|
&done
|
||||||
#2000 .File/len DEO2
|
#2000 .File/len DEO2
|
||||||
#2000 ;len0 STA2 #2000 ;buf0 zero-buf-u8
|
#2000 ;len0 STA2 #2000 ;buf0 zero-buf-u8
|
||||||
#2000 ;len1 STA2 #2000 ;buf1 zero-buf-u8
|
#2000 ;len1 STA2 #2000 ;buf1 zero-buf-u8
|
||||||
|
@ -55,59 +92,57 @@
|
||||||
INC2r GTH2kr STHr ?&loop ( 80^ [limit* pos+1*] )
|
INC2r GTH2kr STHr ?&loop ( 80^ [limit* pos+1*] )
|
||||||
POP POP2r POP2r JMP2r ( )
|
POP POP2r POP2r JMP2r ( )
|
||||||
|
|
||||||
( data created using: )
|
( TODO: validate PCM, freq (44.1 kHz), etc. )
|
||||||
( lame --decode tokyo-skies.mp3 # produced tokyo-skies.wav )
|
( TODO: debug/error messages )
|
||||||
( sox tokyo-skies.wav -c 1 -e unsigned-integer -b 8 tokyo-skies-mono-u8.wav )
|
|
||||||
( sox tokyo-skies-mono-u8.wav tokyo-skies.raw )
|
|
||||||
|
|
||||||
( @path "tokyo-skies.raw 00 )
|
|
||||||
@path "tokyo-skies-mono-u8.wav 00
|
|
||||||
( @path "tokyo-skies.wav 00 )
|
|
||||||
|
|
||||||
( TODO: actually parse )
|
|
||||||
@parse ( -> )
|
@parse ( -> )
|
||||||
#002c .File/len DEO2
|
#002c .File/len DEO2
|
||||||
;buf0 .File/r DEO2
|
;header .File/r DEO2
|
||||||
.File/ok DEI2
|
.File/ok DEI2
|
||||||
#002c EQU2 ?&ok #0000 DIV &ok JMP2r
|
#002c EQU2k ?&ok #0000 DIV
|
||||||
|
&ok POP2 POP2
|
||||||
|
;header ( hdr* )
|
||||||
|
#0016 ADD2 LDA2k #0200 EQU2 .is-stereo STZ ( hdr+22* )
|
||||||
|
#000c ADD2 LDA2k #0800 EQU2 .is-8bit STZ ( hdr+34* )
|
||||||
|
JMP2r
|
||||||
|
|
||||||
@reload-mono-u8 ( l-addr* b-addr* -> )
|
@reload ( l-addr* b-addr* -> )
|
||||||
.done LDZ ?&skip ( l-addr* b-addr* )
|
|
||||||
.File/r DEO2 ( l-addr* )
|
|
||||||
.File/ok DEI2 ( l-addr* read* )
|
|
||||||
DUP2 ROT2 STA2 ( read* ; l-addr<-read )
|
|
||||||
#2000 EQU2 ?&end ( ; if we read 0x2000 we are not done )
|
|
||||||
#01 .done STZ ( ; done<-1 )
|
|
||||||
&end JMP2r ( )
|
|
||||||
&skip POP2 POP2 JMP2r ( )
|
|
||||||
|
|
||||||
@reload-stereo-s16 ( l-addr* b-addr* -> )
|
|
||||||
.done LDZ ?&skip ( l-addr* b-addr* )
|
.done LDZ ?&skip ( l-addr* b-addr* )
|
||||||
SWP2 ( b-addr* l-addr* )
|
SWP2 ( b-addr* l-addr* )
|
||||||
;scratch .File/r DEO2 ( b-addr* l-addr* )
|
;scratch .File/r DEO2 ( b-addr* l-addr* )
|
||||||
.File/ok DEI2 ( b-addr* l-addr* read* )
|
.File/ok DEI2 ( b-addr* l-addr* read* )
|
||||||
DUP2 #02 SFT2 ROT2 STA2 ( b-addr* read* ; l-addr<-read/4 )
|
DUP2 LIT &sft $1 SFT2 ( b-addr* l-addr* read* read>>sft )
|
||||||
|
ROT2 STA2 ( b-addr* read* ; l-addr<-read>>sft )
|
||||||
DUP2 #2000 EQU2 ?&end ( b-addr* read* ; if we read 0x2000 we are not done )
|
DUP2 #2000 EQU2 ?&end ( b-addr* read* ; if we read 0x2000 we are not done )
|
||||||
#01 .done STZ ( b-addr* read* ; done<-1 )
|
#01 .done STZ ( b-addr* read* ; done<-1 )
|
||||||
&end ( b-addr* read* )
|
&end ( b-addr* read* )
|
||||||
SWP2 STH2 ;scratch ( read* scratch* [b-addr*] )
|
SWP2 STH2 ;scratch ( read* scratch* [b-addr*] )
|
||||||
DUP2 ROT2 ADD2 SWP2 ( limit=scratch+read* scratch* [b-addr*] )
|
DUP2 ROT2 ADD2 SWP2 ( limit=scratch+read* scratch* [b-addr*] )
|
||||||
INC2 ( limit* scratch+3* [b-addr*] )
|
INC2 ( limit* scratch+1* [b-addr*] )
|
||||||
&loop ( limit* pos* [bpos*] )
|
&loop ( limit* pos* [bpos*] )
|
||||||
s16-to-u8 ( limit* pos+4* sample^ [bpos*] )
|
LIT2 &resample $2 JSR2 ( limit* pos+n* sample^ [bpos*] )
|
||||||
STH2kr STA ( limit* pos* [bpos*] ; bpos<-sample )
|
STH2kr STA ( limit* pos+n* [bpos*] ; bpos<-sample )
|
||||||
INC2r ( limit* pos+4* [bpos+1*] )
|
INC2r GTH2k ?&loop ( limit* pos+n* [bpos+1*] )
|
||||||
GTH2k ?&loop ( limit* pos+4* [bpos+1*] )
|
POP2r ( limit* pos+n* )
|
||||||
POP2r ( limit* pos+4* )
|
POP2 POP2 JMP2r
|
||||||
&skip POP2 POP2 JMP2r ( )
|
&skip ( )
|
||||||
|
#2000 SWP2 zero-buf-u8 ( )
|
||||||
|
#2000 SWP2 STA2 JMP2r ( )
|
||||||
|
|
||||||
@s16-to-u8 ( pos* -> pos+4* sample^ )
|
@mono-u8-to-u8 ( pos* -> pos+1* sample^ )
|
||||||
LDAk #80 ADD #00 SWP STH2
|
LDAk STH INC2 STHr JMP2r
|
||||||
INC2 INC2
|
|
||||||
LDAk #80 ADD #00 SWP STH2
|
@mono-s16-to-u8 ( pos* -> pos+2* sample^ )
|
||||||
ADD2r LITr 01 SFT2r NIPr
|
LDAk #80 EOR STH INC2 INC2 STHr JMP2r
|
||||||
INC2 INC2
|
|
||||||
STHr JMP2r
|
@stereo-u8-to-u8 ( pos* -> pos+2* sample^ )
|
||||||
|
LDAk #00 SWP STH2 INC2
|
||||||
|
LDAk #00 SWP STH2 INC2
|
||||||
|
ADD2r LITr 01 SFT2r NIPr STHr JMP2r
|
||||||
|
|
||||||
|
@stereo-s16-to-u8 ( pos* -> pos+4* sample^ )
|
||||||
|
LDAk #80 EOR #00 SWP STH2 INC2 INC2
|
||||||
|
LDAk #80 EOR #00 SWP STH2 INC2 INC2
|
||||||
|
ADD2r LITr 01 SFT2r NIPr STHr JMP2r
|
||||||
|
|
||||||
@play0 ( -> ) ;play1 ;len0 ;buf0 !play
|
@play0 ( -> ) ;play1 ;len0 ;buf0 !play
|
||||||
@play1 ( -> ) ;play0 ;len1 ;buf1 !play
|
@play1 ( -> ) ;play0 ;len1 ;buf1 !play
|
||||||
|
@ -118,8 +153,7 @@
|
||||||
#010f BRK ( ; exit )
|
#010f BRK ( ; exit )
|
||||||
&nonzero ( next* l-addr b-addr* n* )
|
&nonzero ( next* l-addr b-addr* n* )
|
||||||
OVR2 output ( next* l-addr b-addr* ; play buf1 )
|
OVR2 output ( next* l-addr b-addr* ; play buf1 )
|
||||||
reload-mono-u8 ( next* ; load more data )
|
reload ( next* ; load more data )
|
||||||
( reload-stereo-s16 ) ( next* ; load more data )
|
|
||||||
.Audio0/vec DEO2 ( ; Audio0/vec<-next )
|
.Audio0/vec DEO2 ( ; Audio0/vec<-next )
|
||||||
BRK ( )
|
BRK ( )
|
||||||
|
|
||||||
|
@ -131,7 +165,8 @@
|
||||||
#bc .Audio0/pitch DEO ( ; <- play standard sample once )
|
#bc .Audio0/pitch DEO ( ; <- play standard sample once )
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
|
@filename $100
|
||||||
|
@header $2c
|
||||||
@len0 $2 @buf0 $2000
|
@len0 $2 @buf0 $2000
|
||||||
@len1 $2 @buf1 $2000
|
@len1 $2 @buf1 $2000
|
||||||
|
|
||||||
@scratch $2000
|
@scratch $2000
|
||||||
|
|
Loading…
Reference in New Issue