1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types combinators endian io kernel
7 ERROR: invalid-audio-file ;
9 : ensured-read ( count -- output/f )
10 [ read ] keep over length = [ drop f ] unless ;
11 : ensured-read* ( count -- output )
12 ensured-read [ invalid-audio-file ] unless* ;
14 : read-chunk ( -- byte-array/f )
15 4 ensured-read [ 4 ensured-read* dup endian> ensured-read* 3append ] [ f ] if* ;
17 : id= ( chunk id -- ? )
18 [ 4 head ] dip sequence= ; inline
20 : convert-data-endian ( audio -- audio )
22 { 16 [ [ 2 seq>native-endianness ] change-data ] }
23 { 32 [ [ 4 seq>native-endianness ] change-data ] }
27 : check-chunk ( chunk id class -- ? )
28 heap-size [ id= ] [ [ length ] dip >= ] bi-curry* bi and ; inline