]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/audio/aiff/aiff.factor
factor: trim using lists
[factor.git] / extra / audio / aiff / aiff.factor
index 82db3d993c81bbe6b20798bc9f6e790d1eddced2..662cc5d2ebdd8bef2e4b208d4af8ad54a338c8df 100644 (file)
@@ -1,7 +1,9 @@
+! Copyright (C) 2009 Joe Groff.
+! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.data audio
-audio.chunked-file classes.struct combinators
-combinators.short-circuit endian io io.binary
-io.encodings.binary io.files kernel locals math sequences ;
+audio.chunked-file audio.loader classes.struct combinators
+combinators.short-circuit endian io.encodings.binary io.files
+kernel math sequences ;
 IN: audio.aiff
 
 CONSTANT: FORM-MAGIC "FORM"
@@ -32,8 +34,7 @@ STRUCT: sound-data-chunk
 
 ! cheesy long-double>integer converter that assumes the long double is a positive integer
 : sample-rate>integer ( byte[10] -- sample-rate )
-    [ 2 tail-slice be> ]
-    [ 2 head-slice be> 16383 - 63 - ] bi shift ;
+    2 cut-slice [ be> ] bi@ swap 16383 - 63 - shift ;
 
 : read-form-chunk ( -- byte-array/f )
     form-chunk heap-size ensured-read* ;
@@ -41,7 +42,7 @@ STRUCT: sound-data-chunk
 : verify-aiff ( chunk -- )
     {
         [ FORM-MAGIC id= ]
-        [ form-chunk memory>struct form-type>> 4 memory>byte-array AIFF-MAGIC id= ] 
+        [ form-chunk memory>struct form-type>> 4 memory>byte-array AIFF-MAGIC id= ]
     } 1&&
     [ invalid-audio-file ] unless ;
 
@@ -79,3 +80,6 @@ STRUCT: sound-data-chunk
             read-form-chunk verify-aiff (read-aiff)
         ] with-file-reader
     ] with-endianness ;
+
+"aif"  [ read-aiff ] register-audio-extension
+"aiff" [ read-aiff ] register-audio-extension