changed async library. Flac conversion in C

This commit is contained in:
2026-04-10 08:32:55 +02:00
parent f3b6fc9669
commit 7aa77436bb
5 changed files with 119 additions and 106 deletions

View File

@@ -1,6 +1,7 @@
#lang racket/base
(require "libao.rkt"
"flac-decoder.rkt"
simple-log
;data/queue
;racket-sound
)
@@ -15,14 +16,15 @@
)
)
(ao-set-async-mode! 'ffi)
;(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)
(sl-log-to-display)
(define (flac-play frame buffer buf-len)
(let* ((sample (hash-ref frame 'number))
(rate (hash-ref frame 'sample-rate))
(second (/ (* sample 1.0) (* rate 1.0)))
@@ -35,8 +37,10 @@
(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 duration buffer)
(let ((second-printer (λ ()
;(displayln 'ao-play)
(ao-play ao-h second duration buffer buf-len 'flac)
;(displayln 'done)
(let ((second-printer (λ (buf-seconds)
(let ((s (inexact->exact (round (ao-at-second ao-h)))))
(unless (= s current-seconds)
(set! current-seconds s)
@@ -45,13 +49,14 @@
(tminutes (quotient duration 60))
(tseconds (remainder duration 60))
)
(displayln (format "At time: ~a:~a (~a:~a)"
(displayln (format "At time: ~a:~a (~a:~a) - ~a"
minutes seconds
tminutes tseconds
buf-seconds
))))))))
(let* ((buf-size (ao-bufsize-async ao-h))
(buf-seconds (exact->inexact (/ buf-size bytes-per-sample-all-channels rate))))
(second-printer)
(second-printer buf-seconds)
(when (> buf-seconds 5)
(letrec ((waiter (λ ()
(let ((buf-seconds-left (exact->inexact
@@ -62,7 +67,7 @@
(displayln (format "Seconds in buffer left: ~a" buf-seconds-left))
(begin
(sleep 0.5)
(second-printer)
(second-printer buf-seconds)
(waiter)))))
))
(waiter))))