]> gitweb.factorcode.org Git - factor.git/blob - extra/audio/chunked-file/chunked-file.factor
Update some copyright headers to follow the current convention
[factor.git] / extra / audio / chunked-file / chunked-file.factor
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
4 math sequences ;
5 IN: audio.chunked-file
6
7 ERROR: invalid-audio-file ;
8
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* ;
13
14 : read-chunk ( -- byte-array/f )
15     4 ensured-read [ 4 ensured-read* dup endian> ensured-read* 3append ] [ f ] if* ;
16
17 : id= ( chunk id -- ? )
18     [ 4 head ] dip sequence= ; inline
19
20 : convert-data-endian ( audio -- audio )
21     dup sample-bits>> {
22         { 16 [ [ 2 seq>native-endianness ] change-data ] }
23         { 32 [ [ 4 seq>native-endianness ] change-data ] }
24         [ drop ]
25     } case ;
26
27 : check-chunk ( chunk id class -- ? )
28     heap-size [ id= ] [ [ length ] dip >= ] bi-curry* bi and ; inline