Index: cl-wav-synth.lisp =================================================================== --- cl-wav-synth.lisp (revision 910) +++ cl-wav-synth.lisp (working copy) @@ -353,9 +353,10 @@ (defgeneric read-header (filename header)) (defmethod read-header (filename (header header)) + "Read wav header info. See http://www.sonicspot.com/guide/wavefiles.html" (labels ((expected (read-str orig-str) (assert (string= read-str orig-str) () - "error reading header: ~S is not a wav file" filename))) + "error reading header: ~S is not a wav file. Expected ~A Got ~A" filename orig-str read-str))) (with-slots (n-samples-per-sec n-channels n-bits-per-sample n-block-align n-avg-bytes-per-sec @@ -365,16 +366,25 @@ (expected (read-id stream 4) "RIFF") (read-32 stream) (expected (read-id stream 4) "WAVE") - (expected (read-id stream 4) "fmt ") - (read-32 stream) - (read-16 stream) - (setf n-channels (read-16 stream)) - (setf n-samples-per-sec (read-32 stream)) - (setf n-avg-bytes-per-sec (read-32 stream)) - (setf n-block-align (read-16 stream)) - (setf n-bits-per-sample (read-16 stream)) - (expected (read-id stream 4) "data") - (setf total-byte (read-32 stream))))) + (loop + (let* ((next-header (read-id stream 4)) + (bytes (read-32 stream))) + (cond ((string= next-header "fmt ") + (read-16 stream) ;; compression code + (setf n-channels (read-16 stream)) + (setf n-samples-per-sec (read-32 stream)) + (setf n-avg-bytes-per-sec (read-32 stream)) + (setf n-block-align (read-16 stream)) + (setf n-bits-per-sample (read-16 stream)) + ;; possible extra format bytes + (dotimes (i (- bytes 16)) (read-byte stream))) + ((string= next-header "data") + (setf total-byte bytes) + (return)) + (t + ;; There're a lot of headers that we don't + ;; care. For instance, bext minf elmo, etc + (dotimes (i bytes) (read-byte stream))))))))) header) (defgeneric print-header (header &optional comment))