updated for new audio device

This commit is contained in:
~d6 2023-11-27 22:26:43 -05:00
parent f8fbae1af1
commit 1dddbf6cf9
1 changed files with 30 additions and 21 deletions

View File

@ -37,10 +37,7 @@
( |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 ]
|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 ]
|60 @Audio3 [ &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 &dur $2 &pad $1 &adsr $2 &len $2 &addr $2 &vol $1 &pitch $1 ]
|a0 @File [ &vec $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|0000
@ -48,6 +45,7 @@
@pos $2
@is-stereo $1
@is-8bit $1
@bytes-per-ms $2
|0100
;filename .pos STZ2
@ -77,9 +75,9 @@
&done
LIT2 =reload/resample STA2 ( ; save resample function )
LIT2r =reload/sft STAr ( ; save shift size )
#2000 .File/len DEO2
#2000 ;len0 STA2 #2000 ;buf0 zero-buf-u8
#2000 ;len1 STA2 #2000 ;buf1 zero-buf-u8
#2274 .File/len DEO2
#2274 ;len0 STA2 #2274 ;buf0 zero-buf-u8
#2274 ;len1 STA2 #2274 ;buf1 zero-buf-u8
!play0
@zero-buf-u8 ( len* buf* -> )
@ -112,7 +110,7 @@
.File/ok DEI2 ( b-addr* l-addr* read* )
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 #2274 EQU2 ?&end ( b-addr* read* ; if we read 0x2274 we are not done )
#01 .done STZ ( b-addr* read* ; done<-1 )
&end ( b-addr* read* )
SWP2 STH2 ;scratch ( read* scratch* [b-addr*] )
@ -125,18 +123,18 @@
POP2r ( limit* pos+n* )
POP2 POP2 JMP2r
&skip ( )
#2000 SWP2 zero-buf-u8 ( )
#2000 SWP2 STA2 JMP2r ( )
#2274 SWP2 zero-buf-u8 ( )
#2274 SWP2 STA2 JMP2r ( )
@mono-u8-to-u8 ( pos* -> pos+1* sample^ )
LDAk STH INC2 STHr JMP2r
@mono-s16-to-u8 ( pos* -> pos+2* sample^ )
LDAk #80 EOR STH INC2 INC2 STHr JMP2r
LDAk #80 ADD STH INC2 INC2 STHr JMP2r
@stereo-u8-to-u8 ( pos* -> pos+2* sample^ )
LDAk #00 SWP STH2 INC2
LDAk #00 SWP STH2 INC2
LDAk LITr 00 STH INC2
LDAk LITr 00 STH INC2
ADD2r LITr 01 SFT2r NIPr STHr JMP2r
@stereo-s16-to-u8 ( pos* -> pos+4* sample^ )
@ -157,16 +155,27 @@
.Audio0/vec DEO2 ( ; Audio0/vec<-next )
BRK ( )
@bytes-to-millis ( samples* -> ms* )
#01b9 DIV2 #000a MUL2 JMP2r
@output ( len* addr* -> )
.Audio0/addr DEO2 ( ; <- write buf addr )
.Audio0/len DEO2 ( ; <- write len )
#0000 .Audio0/adsr DEO2 ( ; <- write ignore envelope )
DUP2 .Audio0/len DEO2 ( ; <- write length in bytes/samples )
bytes-to-millis .Audio0/dur DEO2 ( ; <- write duration in milliseconds )
#00f0 .Audio0/adsr DEO2 ( ; <- write ignore envelope )
#ff .Audio0/vol DEO ( ; <- play 100% volume )
#bc .Audio0/pitch DEO ( ; <- play standard sample once )
JMP2r
( buffer size is 0x2274, i.e. 8820. )
( this is an important number: 8820 = 4 * 5 * 441. )
( since it is divisible by 4 we know that the buffer will read )
( an exact number of samples, even with 16-bit stereo. and since )
( it is divisble by 441 we know it will always contain a multiple )
( 10 milliseconds of audio. these assumptions help ensure we don't )
( end up with static, popping, or other problems. )
@filename $100
@header $2c
@len0 $2 @buf0 $2000
@len1 $2 @buf1 $2000
@scratch $2000
@len0 $2 @buf0 $2274
@len1 $2 @buf1 $2274
@scratch $2274