opus conversie
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
(require rackunit
|
||||
racket/file
|
||||
racket/path
|
||||
"../flac-48khz-manager.rkt")
|
||||
"../flac-48khz-manager.rkt"
|
||||
"../private/fingerprint.rkt")
|
||||
|
||||
(define tmp (make-temporary-file "alm-test-~a" 'directory))
|
||||
(define hi (build-path tmp "hires.flac"))
|
||||
@@ -11,6 +12,37 @@
|
||||
(call-with-output-file hi #:exists 'replace (lambda (out) (display "hires" out)))
|
||||
(call-with-output-file cd #:exists 'replace (lambda (out) (display "cd" out)))
|
||||
|
||||
(define (u64be-bytes n)
|
||||
(define b (make-bytes 8 0))
|
||||
(for ([i (in-range 8)])
|
||||
(bytes-set! b i (bitwise-and (arithmetic-shift n (- (* 8 (- 7 i)))) #xff)))
|
||||
b)
|
||||
|
||||
(define (minimal-flac-bytes sample-rate)
|
||||
(define streaminfo (make-bytes 34 0))
|
||||
(bytes-set! streaminfo 0 #x10)
|
||||
(bytes-set! streaminfo 1 #x00)
|
||||
(bytes-set! streaminfo 2 #x10)
|
||||
(bytes-set! streaminfo 3 #x00)
|
||||
(define packed (bitwise-ior (arithmetic-shift sample-rate 44)
|
||||
(arithmetic-shift 1 41)
|
||||
(arithmetic-shift 15 36)
|
||||
1000))
|
||||
(bytes-copy! streaminfo 10 (u64be-bytes packed))
|
||||
(bytes-append #"fLaC" (bytes #x80 #x00 #x00 #x22) streaminfo))
|
||||
|
||||
(define native-flac (build-path tmp "native.flac"))
|
||||
(define id3-flac (build-path tmp "id3-prefix.flac"))
|
||||
(call-with-output-file native-flac #:exists 'replace
|
||||
(lambda (out) (write-bytes (minimal-flac-bytes 96000) out)))
|
||||
(call-with-output-file id3-flac #:exists 'replace
|
||||
(lambda (out)
|
||||
(write-bytes (bytes-append #"ID3" (bytes 4 0 0 0 0 0 3) #"abc" (minimal-flac-bytes 88200)) out)))
|
||||
(check-equal? (flac-streaminfo-sample-rate (read-flac-streaminfo native-flac)) 96000)
|
||||
(check-equal? (flac-streaminfo-sample-rate (read-flac-streaminfo id3-flac)) 88200)
|
||||
(delete-file native-flac)
|
||||
(delete-file id3-flac)
|
||||
|
||||
(define convert-count 0)
|
||||
|
||||
(define (mock-inspect p)
|
||||
@@ -19,6 +51,9 @@
|
||||
[(regexp-match? #rx"hires" s) 96000]
|
||||
[else 44100]))
|
||||
|
||||
(define (mock-fingerprint p)
|
||||
(string-append "mock:" (file->string p)))
|
||||
|
||||
(define (mock-convert p rate compression)
|
||||
(set! convert-count (add1 convert-count))
|
||||
(call-with-output-file p #:exists 'replace
|
||||
@@ -26,21 +61,21 @@
|
||||
(list (cons 'mock #t) (cons 'target-sample-rate rate)))
|
||||
|
||||
(define first-summary
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:fingerprint-proc mock-fingerprint #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'seen first-summary) '(seen . 2))
|
||||
(check-equal? (assoc 'new first-summary) '(new . 2))
|
||||
(check-equal? (assoc 'converted first-summary) '(converted . 1))
|
||||
(check-equal? convert-count 1)
|
||||
|
||||
(define second-summary
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:fingerprint-proc mock-fingerprint #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'seen second-summary) '(seen . 2))
|
||||
(check-equal? (assoc 'unchanged second-summary) '(unchanged . 2))
|
||||
(check-equal? convert-count 1)
|
||||
|
||||
(delete-file cd)
|
||||
(define third-summary
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
||||
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:fingerprint-proc mock-fingerprint #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'removed third-summary) '(removed . 1))
|
||||
(check-equal? (assoc 'unchanged third-summary) '(unchanged . 1))
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#lang racket/base
|
||||
|
||||
(require rackunit
|
||||
racket/file
|
||||
racket/path
|
||||
"../flac2opus-manager.rkt")
|
||||
|
||||
(define tmp (make-temporary-file "alm-flac2opus-src-~a" 'directory))
|
||||
(define out (make-temporary-file "alm-flac2opus-out-~a" 'directory))
|
||||
(define sub (build-path tmp "disc1"))
|
||||
(make-directory* sub)
|
||||
|
||||
(call-with-output-file (build-path tmp ".flac-48khz-manager.ini") #:exists 'replace
|
||||
(lambda (o)
|
||||
(display "[manager]\n" o)
|
||||
(display "change-detection=quick\n" o)
|
||||
(display "display-log=false\n" o)
|
||||
(display "dry-run=false\n" o)
|
||||
(display "log-file=.flac-48khz-manager.log\n" o)
|
||||
(display "[mail]\n" o)
|
||||
(display "enabled=false\n" o)))
|
||||
|
||||
(define flac (build-path sub "track.flac"))
|
||||
(define pdf (build-path sub "booklet.pdf"))
|
||||
(define jpg (build-path tmp "cover.jpg"))
|
||||
(call-with-output-file flac #:exists 'replace (lambda (o) (display "fake flac" o)))
|
||||
(call-with-output-file pdf #:exists 'replace (lambda (o) (display "booklet" o)))
|
||||
(call-with-output-file jpg #:exists 'replace (lambda (o) (display "jpg" o)))
|
||||
|
||||
(define convert-count 0)
|
||||
(define (mock-convert src dst kbps)
|
||||
(set! convert-count (add1 convert-count))
|
||||
(make-directory* (let-values ([(base name dir?) (split-path dst)]) base))
|
||||
(call-with-output-file dst #:exists 'replace
|
||||
(lambda (o) (fprintf o "opus from ~a at ~a" (path->string src) kbps)))
|
||||
(list (cons 'mock #t) (cons 'kbps kbps)))
|
||||
|
||||
(define first-summary
|
||||
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'seen first-summary) '(seen . 3))
|
||||
(check-equal? (assoc 'converted first-summary) '(converted . 1))
|
||||
(check-equal? (assoc 'copied first-summary) '(copied . 2))
|
||||
(check-true (file-exists? (build-path out "disc1" "track.opus")))
|
||||
(check-true (file-exists? (build-path out "disc1" "booklet.pdf")))
|
||||
(check-true (file-exists? (build-path out "cover.jpg")))
|
||||
(check-equal? convert-count 1)
|
||||
|
||||
(define second-summary
|
||||
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'seen second-summary) '(seen . 3))
|
||||
(check-equal? (assoc 'unchanged second-summary) '(unchanged . 3))
|
||||
(check-equal? convert-count 1)
|
||||
|
||||
(delete-file pdf)
|
||||
(define third-summary
|
||||
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
|
||||
(check-equal? (assoc 'removed third-summary) '(removed . 1))
|
||||
(check-false (file-exists? (build-path out "disc1" "booklet.pdf")))
|
||||
|
||||
(delete-directory/files tmp)
|
||||
(delete-directory/files out)
|
||||
Reference in New Issue
Block a user