ensure wav chunks are as big as they ought to be
parent
2741b3739d
commit
aa3025ce23
|
@ -1,6 +1,7 @@
|
||||||
USING: alien.c-types alien.syntax audio combinators
|
USING: alien.c-types alien.syntax audio combinators
|
||||||
combinators.short-circuit io io.binary io.encodings.binary
|
combinators.short-circuit io io.binary io.encodings.binary
|
||||||
io.files io.streams.byte-array kernel locals sequences ;
|
io.files io.streams.byte-array kernel locals math
|
||||||
|
sequences ;
|
||||||
IN: audio.wav
|
IN: audio.wav
|
||||||
|
|
||||||
CONSTANT: RIFF-MAGIC "RIFF"
|
CONSTANT: RIFF-MAGIC "RIFF"
|
||||||
|
@ -46,19 +47,25 @@ ERROR: invalid-wav-file ;
|
||||||
"riff-chunk" heap-size ensured-read* ;
|
"riff-chunk" heap-size ensured-read* ;
|
||||||
|
|
||||||
: id= ( chunk id -- ? )
|
: id= ( chunk id -- ? )
|
||||||
[ 4 memory>byte-array ] dip sequence= ;
|
[ 4 head ] dip sequence= ;
|
||||||
|
|
||||||
|
: check-chunk ( chunk id min-size -- ? )
|
||||||
|
[ id= ] [ [ length ] dip >= ] bi-curry* bi and ;
|
||||||
|
|
||||||
:: read-wav-chunks ( -- fmt data )
|
:: read-wav-chunks ( -- fmt data )
|
||||||
f :> fmt! f :> data!
|
f :> fmt! f :> data!
|
||||||
[ { [ fmt data and not ] [ read-chunk ] } 0&& dup ]
|
[ { [ fmt data and not ] [ read-chunk ] } 0&& dup ]
|
||||||
[ {
|
[ {
|
||||||
{ [ dup FMT-MAGIC id= ] [ fmt! ] }
|
{ [ dup FMT-MAGIC "wav-fmt-chunk" heap-size check-chunk ] [ fmt! ] }
|
||||||
{ [ dup DATA-MAGIC id= ] [ data! ] }
|
{ [ dup DATA-MAGIC "wav-data-chunk" heap-size check-chunk ] [ data! ] }
|
||||||
} cond ] while drop
|
} cond ] while drop
|
||||||
fmt data ;
|
fmt data ;
|
||||||
|
|
||||||
: verify-wav ( chunk -- )
|
: verify-wav ( chunk -- )
|
||||||
{ [ RIFF-MAGIC id= ] [ riff-chunk-format WAVE-MAGIC id= ] } 1&&
|
{
|
||||||
|
[ RIFF-MAGIC id= ]
|
||||||
|
[ riff-chunk-format 4 memory>byte-array WAVE-MAGIC id= ]
|
||||||
|
} 1&&
|
||||||
[ invalid-wav-file ] unless ;
|
[ invalid-wav-file ] unless ;
|
||||||
|
|
||||||
: (read-wav) ( -- audio )
|
: (read-wav) ( -- audio )
|
||||||
|
|
Loading…
Reference in New Issue