79 lines
3.3 KiB
Racket
79 lines
3.3 KiB
Racket
#lang racket/base
|
|
(require "libao/libao.rkt"
|
|
"libflac/flac-decoder.rkt"
|
|
data/queue
|
|
)
|
|
|
|
(define test-file3 #f)
|
|
(let ((os (system-type 'os)))
|
|
(when (eq? os 'unix)
|
|
(set! test-file3 "/muziek/Klassiek-Viool/Alina Ibragimova/Paganini_24 Caprices (2021)/24. 24 Caprices, Op 1 - No. 24 in A minor- Tema con variazioni. Quasi presto.flac"))
|
|
(when (eq? os 'windows)
|
|
;(set! test-file3 "C:\\Muziek\\Klassiek-Strijkkwartet\\Quatuor Zaïde\\Franz\\01 Erlkönig, D. 328 (Arr. For String Quartet by Eric Mouret).flac")
|
|
(set! test-file3 "C:\\Muziek\\Klassiek-Viool\\Janine Jansen\\Janine Jansen - Sibelius en Prokovief 1 (2024)\\02 - Violin Concerto in D Minor, Op. 47 II. Adagio di molto.flac")
|
|
)
|
|
)
|
|
|
|
;(define fmt (ao-mk-format 24 48000 2 'big-endian))
|
|
;(define ao-h (ao-open-live #f fmt))
|
|
|
|
(define current-seconds 0)
|
|
(define ao-h #f)
|
|
|
|
(define (flac-play frame buffer)
|
|
(let* ((sample (hash-ref frame 'number))
|
|
(rate (hash-ref frame 'sample-rate))
|
|
(second (/ (* sample 1.0) (* rate 1.0)))
|
|
(bits-per-sample (hash-ref frame 'bits-per-sample))
|
|
(bytes-per-sample (/ bits-per-sample 8))
|
|
(channels (hash-ref frame 'channels))
|
|
(bytes-per-sample-all-channels (* channels bytes-per-sample))
|
|
(duration (hash-ref frame 'duration))
|
|
)
|
|
(when (eq? ao-h #f)
|
|
(let ((fmt (ao-mk-format bits-per-sample rate channels 'big-endian)))
|
|
(set! ao-h (ao-open-live #f fmt))))
|
|
(ao-play ao-h second buffer)
|
|
(let ((second-printer (λ ()
|
|
(let ((s (inexact->exact (round (ao-at-second ao-h)))))
|
|
(when (> s current-seconds)
|
|
(set! current-seconds s)
|
|
(let ((minutes (quotient s 60))
|
|
(seconds (remainder s 60))
|
|
(tminutes (quotient duration 60))
|
|
(tseconds (remainder duration 60))
|
|
)
|
|
(displayln (format "At time: ~a:~a (~a:~a)"
|
|
minutes seconds
|
|
tminutes tseconds
|
|
))))))))
|
|
(let* ((buf-size (ao-bufsize-async ao-h))
|
|
(buf-seconds (exact->inexact (/ buf-size bytes-per-sample-all-channels rate))))
|
|
(second-printer)
|
|
(when (> buf-seconds 5)
|
|
(letrec ((waiter (λ ()
|
|
(let ((buf-seconds-left (exact->inexact
|
|
(/ (ao-bufsize-async ao-h)
|
|
bytes-per-sample-all-channels
|
|
rate))))
|
|
(if (< buf-seconds-left 2.0)
|
|
(displayln (format "Seconds in buffer left: ~a" buf-seconds-left))
|
|
(begin
|
|
(sleep 0.5)
|
|
(second-printer)
|
|
(waiter)))))
|
|
))
|
|
(waiter))))
|
|
)
|
|
)
|
|
)
|
|
|
|
(define (flac-meta meta)
|
|
(displayln meta))
|
|
|
|
(define flac-h
|
|
(flac-open test-file3 flac-meta flac-play))
|
|
|
|
(flac-read flac-h)
|
|
|