]> gitweb.factorcode.org Git - factor.git/blob - extra/audio/chunked-file/chunked-file.factor
change ERROR: words from throw-foo back to foo.
[factor.git] / extra / audio / chunked-file / chunked-file.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors alien.c-types combinators endian io kernel
3 math sequences ;
4 IN: audio.chunked-file
5
6 ERROR: invalid-audio-file ;
7
8 : ensured-read ( count -- output/f )
9     [ read ] keep over length = [ drop f ] unless ;
10 : ensured-read* ( count -- output )
11     ensured-read [ invalid-audio-file ] unless* ;
12
13 : read-chunk ( -- byte-array/f )
14     4 ensured-read [ 4 ensured-read* dup endian> ensured-read* 3append ] [ f ] if* ;
15
16 : id= ( chunk id -- ? )
17     [ 4 head ] dip sequence= ; inline
18
19 : convert-data-endian ( audio -- audio )
20     dup sample-bits>> {
21         { 16 [ [ 2 seq>native-endianness ] change-data ] }
22         { 32 [ [ 4 seq>native-endianness ] change-data ] }
23         [ drop ]
24     } case ;
25
26 : check-chunk ( chunk id class -- ? )
27     heap-size [ id= ] [ [ length ] dip >= ] bi-curry* bi and ; inline