generic audio decoder framework implemented

This commit is contained in:
2026-04-21 18:01:33 +02:00
parent fd124f594a
commit 630a0423a0
3 changed files with 182 additions and 14 deletions
+14 -12
View File
@@ -1,7 +1,8 @@
#lang racket/base
(require "libao.rkt"
"flac-decoder.rkt"
"audio-decoder.rkt"
simple-log
"private/utils.rkt"
;data/queue
;racket-sound
)
@@ -25,20 +26,20 @@
(sl-log-to-display)
(define (flac-play frame buffer buf-len)
(let* ((sample (hash-ref frame 'number))
(rate (hash-ref frame 'sample-rate))
(define (audio-play type handle buf-info buffer buf-len)
(let* ((sample (hash-ref buf-info 'sample))
(rate (hash-ref buf-info 'sample-rate))
(second (/ (* sample 1.0) (* rate 1.0)))
(bits-per-sample (hash-ref frame 'bits-per-sample))
(bits-per-sample (hash-ref buf-info 'bits-per-sample))
(bytes-per-sample (/ bits-per-sample 8))
(channels (hash-ref frame 'channels))
(channels (hash-ref buf-info 'channels))
(bytes-per-sample-all-channels (* channels bytes-per-sample))
(duration (hash-ref frame 'duration))
(duration (hash-ref buf-info 'duration))
)
(when (eq? ao-h #f)
(set! ao-h (ao-open-live bits-per-sample rate channels 'big-endian)))
;(displayln 'ao-play)
(ao-play ao-h test-file3-id second duration buffer buf-len 'flac)
(ao-play ao-h test-file3-id second duration buffer buf-len type)
;(displayln 'done)
(let ((second-printer (λ (buf-seconds)
(let ((s (inexact->exact (round (ao-at-second ao-h)))))
@@ -87,13 +88,14 @@
)
)
(define (flac-meta meta)
(displayln meta))
(define (audio-meta type handle meta)
(dbg-sound "type: ~a" type)
(dbg-sound "meta: ~a" meta))
(define (play)
(set! ao-h #f)
(let ((flac-h (flac-open test-file3 flac-meta flac-play)))
(flac-read flac-h)
(let ((audio-h (audio-open test-file3 audio-meta audio-play)))
(audio-read audio-h)
(ao-close ao-h)
(set! ao-h #f)))
;(sleep 1.0)