         { [ dup FMT-MAGIC  wav-fmt-chunk  check-chunk ] [ wav-fmt-chunk  memory>struct fmt!  ] }
         { [ dup DATA-MAGIC wav-data-chunk check-chunk ] [ wav-data-chunk memory>struct data! ] }
     } cond ] while drop
-    fmt data 2dup and [ invalid-wav-file ] unless ;
+    fmt data 2dup and [ invalid-audio-file ] unless ;
 
 : verify-wav ( chunk -- )
     {
         [ RIFF-MAGIC id= ]
         [ riff-chunk memory>struct format>> 4 memory>byte-array WAVE-MAGIC id= ]
     } 1&&
-    [ invalid-wav-file ] unless ;
+    [ invalid-audio-file ] unless ;
+
+: convert-data-endian ( audio -- audio )
+    little-endian [
+        dup sample-bits>> {
+            { 16 [ [ 2 seq>native-endianness ] change-data ] }
+            { 32 [ [ 4 seq>native-endianness ] change-data ] }
+            [ drop ]
+        } case
+    ] with-endianness ;
 
 : (read-wav) ( -- audio )
     read-wav-chunks

USING: alien.c-types alien.syntax audio combinators
combinators.short-circuit io io.binary io.encodings.binary
io.files io.streams.byte-array kernel locals math
sequences alien alien.data classes.struct accessors ;

    ] [
        [ header>> size>> 4 memory>byte-array le> dup ]
        [ body>> >c-ptr ] bi swap memory>byte-array
    ] bi*
    <audio>
    convert-data-endian ;

: read-wav ( filename -- audio )
    binary [
