Memory based audio player

parent 13601dee
Pipeline #1308 passed with stage
in 12 minutes and 53 seconds
......@@ -106,8 +106,10 @@ sample-rate samples/frame / 2* $10 + Constant /idx-block
REPEAT ; is write-record
0 Value play-file
Variable idx-block
Variable idx-block \ in memory index
0 Value idx-pos#
Variable play-block \ in memory file
0 Value play-pos#
Variable opus-out
: $alloc ( u string -- addr u )
......@@ -120,19 +122,32 @@ $100 buffer: opus-error$
opus-error$ "error \ "
! -2 throw ;] do-debug
THEN ;
: in-idx-block ( pos -- addr len )
idx-block $@ rot safe/string ;
: >idx-pos ( block -- )
idx-block $@ drop + idx-pos le-uxd@
play-file reposition-file throw ;
in-idx-block $10 u>= IF
idx-pos le-uxd@
play-file IF
play-file reposition-file throw
ELSE
drop to play-pos#
THEN
ELSE drop THEN ;
: read-idx-block ( -- frame-size )
idx-block $@len 0= IF 0 EXIT THEN
idx-pos# idx-block $@ drop idx-frames c@ dup >r /mod
r> 2* idx-head + *
over 0= IF dup >idx-pos THEN
swap 2* + idx-head + >r
idx-block $@ r> safe/string 2 u>= IF le-uw@ ELSE drop 0 THEN ;
swap 2* + idx-head +
in-idx-block 2 u>= IF le-uw@ ELSE drop 0 THEN ;
: read-opus-block ( frame-size -- )
$3FF and read-opus $!len
read-opus $@ play-file read-file throw drop ;
$3FF and play-file IF
read-opus $!len
read-opus $@ play-file read-file throw drop
ELSE
>r play-block $@ play-pos# safe/string
r> umin dup +to play-pos# read-opus $!
THEN ;
: /frame ( -- u )
idx-block $@ drop dup idx-channels c@ swap idx-samples le-uw@ * 2* ;
: /sample ( -- u ) idx-block $@ drop idx-channels c@ 2* ;
......@@ -177,8 +192,8 @@ Semaphore opus-block-sem
: open-play ( addr-play u addr-idx u -- )
idx-block $slurp-file
r/o open-file throw to play-file
0 to idx-pos#
play-block $slurp-file \ r/o open-file throw to play-file
0 to idx-pos# 0 to play-pos#
opus-task ?dup-IF wake ELSE opus-block-task THEN ;
: open-play+ ( addr u -- ) { | w^ play$ w^ idx$ }
2dup play$ $! ".opus" play$ $+!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment