From 008d2172867d572d73b18ae26f58baf3db2107a0 Mon Sep 17 00:00:00 2001 From: Steve Ayerhart Date: Sat, 13 Aug 2022 19:38:54 -0400 Subject: [PATCH] working decoder? --- src/flac.scm | 21 +++++++++++++++++++-- src/flac/decoder.scm | 2 +- src/flac/format.scm | 7 +++++-- src/flac/reader.scm | 4 +++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/flac.scm b/src/flac.scm index 1efb0a9..01f7412 100644 --- a/src/flac.scm +++ b/src/flac.scm @@ -44,7 +44,8 @@ (iota (frame-header-blocksize header))))) (define (decode-flac-file infile outfile) - (with-input-from-file infile + (let ((old-output (current-output-port))) + (with-input-from-file infile (λ () (with-flac-input-port (current-input-port) (λ () @@ -87,4 +88,20 @@ (write-frame frame (stream-info-channels stream-info)) (frame-loop (+ 1 frame-number) (read-flac-frame stream-info)))))) - #:binary #t))))))) + #:binary #t)))))))) +; +; (format #t "SAMPLES: ~a\n" (stream-info-samples stream-info)) +; (format #t "bps: ~a\n" (stream-info-bits-per-sample stream-info)) +; (with-output-to-file outfile +; (lambda () +; (put-bytevector (current-output-port) (bytestructure-unwrap wav-header)) +; (let frame-loop ((frame-number 0) +; (frame (read-flac-frame stream-info))) +; (if (= (stream-info-samples stream-info) frame-number) +; #t +; (begin +; (format old-output "frame ~a\n" frame) +; (write-frame frame (stream-info-channels stream-info)) +; (frame-loop (+ 1 frame-number) +; (read-flac-frame stream-info)))))))))))) +; #:binary #t)))))))) diff --git a/src/flac/decoder.scm b/src/flac/decoder.scm index 991d17d..26cc4f3 100644 --- a/src/flac/decoder.scm +++ b/src/flac/decoder.scm @@ -114,7 +114,7 @@ (parameters '()) (raw-bits '()) (residual '())) - (if (= partition partitions) + (if (>= partition partitions) (values (%make-entropy-coding-method coding-method (%make-rice-partition diff --git a/src/flac/format.scm b/src/flac/format.scm index a570c7a..0f7ed41 100644 --- a/src/flac/format.scm +++ b/src/flac/format.scm @@ -120,7 +120,6 @@ (header subframe-header) (data subframe-data)) - (define-record-type (%make-subframe-lpc entropy-coding-method order qlp-coefficient-precision quantization-level qlp-coefficients warmup residual) subframe-lpc? @@ -169,7 +168,6 @@ (type entropy-coding-method-type) (data entropy-coding-method-data)) - (define-record-type (make-frame-header blocking-strategy blocksize sample-rate channel-assignment bits-per-sample frame/sample-number crc) frame-header? @@ -332,6 +330,11 @@ (λ (record port) (format port "#< type: ~a mime-type: ~a>" (picture-type record) (picture-mime-type record)))) +(set-record-type-printer! + + (λ (record port) + (format port "#< header: ~a>" (frame-header record)))) + (define-record-type (make-flac-metadata stream-info padding application seek-table vorbis-comment cuesheet pictures) flac-metadata? diff --git a/src/flac/reader.scm b/src/flac/reader.scm index cf01fca..3d4def2 100644 --- a/src/flac/reader.scm +++ b/src/flac/reader.scm @@ -93,4 +93,6 @@ (let coded-number-loop ((coded-sample-number (flac-read-uint 8))) (if (< coded-sample-number #b11000000) coded-sample-number - (coded-number-loop (bitwise-and (bitwise-arithmetic-shift coded-sample-number 1) #xff))))) + (begin + (flac-read-uint 8) + (coded-number-loop (bitwise-and (bitwise-arithmetic-shift coded-sample-number 1) #xff))))))