1 ! (c)2009 Joe Groff bsd license
2 USING: accessors alien.c-types combinators endian io kernel
6 ERROR: invalid-audio-file ;
8 : ensured-read ( count -- output/f )
9 [ read ] keep over length = [ drop f ] unless ;
10 : ensured-read* ( count -- output )
11 ensured-read [ throw-invalid-audio-file ] unless* ;
13 : read-chunk ( -- byte-array/f )
14 4 ensured-read [ 4 ensured-read* dup endian> ensured-read* 3append ] [ f ] if* ;
16 : id= ( chunk id -- ? )
17 [ 4 head ] dip sequence= ; inline
19 : convert-data-endian ( audio -- audio )
21 { 16 [ [ 2 seq>native-endianness ] change-data ] }
22 { 32 [ [ 4 seq>native-endianness ] change-data ] }
26 : check-chunk ( chunk id class -- ? )
27 heap-size [ id= ] [ [ length ] dip >= ] bi-curry* bi and ; inline