audio decoding

This commit is contained in:
2026-04-21 22:53:25 +02:00
parent 630a0423a0
commit d7f2202091
3 changed files with 41 additions and 2 deletions
+36 -2
View File
@@ -24,7 +24,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-struct audio-reader
(exts open reader seeker stopper))
(exts valid? open reader seeker stopper))
;; audiotype, audio-reader
(define audio-readers (make-hash))
@@ -32,6 +32,7 @@
(hash-set! audio-readers
'flac
(make-audio-reader '("flac")
flac-valid?
flac-open
flac-read
flac-seek
@@ -84,7 +85,40 @@
(-> (or/c string? path?) boolean?)
(let ((f (build-path file)))
(let ((e (format "~a" (path-get-extension f))))
(audio-valid-ext? e))))
(if (audio-valid-ext? e)
(let ((reader (find-reader file)))
(if (eq? reader #f)
#f
(audio-reader-valid? file)))
#f))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; cb-stream-info will be called with
; - audio-type: symbol?
; - handle: audio-handle?
; - meta: hash?
; Meta information must at least contain:
; ('duration . seconds) - duration of the audio in seconds (or fractions): double
; ('bits-per-sample . integer) - number of audio bits per sample
; ('channels . integer) - number of audio channels
; ('sample-rate . integer) - number of samples per second per channel
; ('total-samples . integer) - total number of samples of the audio
;
; cb-audio will be called with
; - audio-type: symbol?
; - handle: audio-handle?
; - buf-info: hash?
; - buffer: cpointer? - contains data to be fed to ao - must be owned / released by the driver
; the ao-async backend will copy the data
; - buf-size: integer? - contains the size of the data
; buf-info must at least contain:
; ('duration . seconds) - duration of the audio in seconds (or fractions): double
; ('bits-per-sample . integer) - number of audio bits per sample
; ('channels . integer) - number of audio channels
; ('sample-rate . integer) - number of samples per second per channel
; ('total-samples . integer) - total number of samples of the audio
; (sample . integer) - the current sample the audio buffer applies to.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define/contract (audio-open audio-file cb-stream-info cb-audio)
(-> (or/c string? path?) procedure? procedure? audio-handle?)
+4
View File
@@ -6,6 +6,7 @@
"private/utils.rkt")
(provide flac-open
flac-valid?
flac-read
flac-read-meta
flac-stream-state
@@ -20,6 +21,9 @@
;; Functions to do the good stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (flac-valid? flac-file*)
#t)
(define (flac-open flac-file* cb-stream-info cb-audio)
(let ((flac-file (if (path? flac-file*) (path->string flac-file*) flac-file*)))
(if (file-exists? flac-file)
+1
View File
@@ -36,6 +36,7 @@
(bytes-per-sample-all-channels (* channels bytes-per-sample))
(duration (hash-ref buf-info 'duration))
)
(displayln buf-info)
(when (eq? ao-h #f)
(set! ao-h (ao-open-live bits-per-sample rate channels 'big-endian)))
;(displayln 'ao-play)