standard audio pipeline

This commit is contained in:
2026-04-22 19:08:57 +02:00
parent 1fdd7eb204
commit 2db3af084d
5 changed files with 53 additions and 32 deletions
+30 -25
View File
@@ -16,7 +16,7 @@
[track-nr-updater (λ (nr) #t)]
[state-updater (λ (state) #t)]
[repeat-updater (λ (state) #t)]
[audio-info-cb (λ (current-sample rate channels bits) #t)]
[audio-info-cb (λ (current-sample rate channels bits kind) #t)]
[buffer-max-seconds 10]
[buffer-min-seconds 4]
)
@@ -33,7 +33,7 @@
(define volume 100.0)
(define ao-handle #f)
(define flac-handle #f)
(define audio-handle #f)
(define current-music-id -1)
(define current-track-id -1)
@@ -41,6 +41,7 @@
(define current-rate 0)
(define current-bits 0)
(define current-channels 0)
(define current-audio-format 'none)
(define current-length 0)
(define current-seconds 0)
@@ -60,7 +61,7 @@
current-rate current-bits current-channels ao-handle)
(dbg-rktplayer "Opening ao-handle")
(when use-ao
(set! ao-handle (ao-open-live current-bits current-rate current-channels 'big-endian))
(set! ao-handle (ao-open-live current-bits current-rate current-channels 'native-endian))
(start-play-time-updater)
)
)
@@ -104,16 +105,16 @@
(= current-bits bits)
(= current-channels channels)))
(define (flac-play frame buffer buf-len)
(define (audio-play type ao-type handle buf-info buffer buf-len)
(unless (eq? state 'quitted)
(let* ((sample (hash-ref frame 'number))
(rate (hash-ref frame 'sample-rate))
(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))
)
(unless (stream-equal? rate bits-per-sample channels)
@@ -134,7 +135,7 @@
(set! current-length duration)
(when (eq? ao-handle #f)
(audio-info-cb sample current-rate current-channels current-bits)
(audio-info-cb sample current-rate current-channels current-bits current-audio-format)
)
(check-ao-handle)
@@ -151,7 +152,7 @@
(sleep 0.25))))
(when (not (eq? ao-handle #f))
(ao-play ao-handle current-track-id second duration buffer buf-len 'flac)
(ao-play ao-handle current-track-id second duration buffer buf-len ao-type)
)
)
@@ -171,8 +172,11 @@
)
)
(define (flac-meta meta)
(dbg-rktplayer "flac meta: ~a" meta))
(define (audio-meta type ao-type handle meta)
(set! current-audio-format type)
(dbg-rktplayer "type: ~a" type)
(dbg-rktplayer "ao-type: ~a" ao-type)
(dbg-rktplayer "meta: ~a" meta))
(define (play-track-worker)
(thread
@@ -180,14 +184,15 @@
(if (eq? ct-data #f)
'no-track-data
(let ((file (send ct-data get-file)))
(dbg-rktplayer "opening flac handle for file: ~a" file)
(set! flac-handle (flac-open file flac-meta flac-play))
(dbg-rktplayer "opening audios handle for file: ~a" file)
(set! audio-handle (audio-open file audio-meta audio-play))
(set! current-track-id (send ct-data get-id))
(dbg-rktplayer "Starting flac-read")
(let ((result (flac-read flac-handle)))
(if (eq? result 'end-of-stream)
(set-state! 'track-feeded)
(dbg-rktplayer "Flac read stopped")))
(dbg-rktplayer "Starting audio-read")
(audio-read audio-handle)
(unless (eq? state 'stopped)
(set-state! 'track-feeded)
(dbg-rktplayer "Audio read done")
)
'worker-done
)
)
@@ -198,13 +203,13 @@
)
(define (close-player*)
(dbg-rktplayer "Closing flac handle")
(dbg-rktplayer "Closing audio handle")
(set! closing #t)
(unless (eq? flac-handle #f)
(flac-stop flac-handle)
(set! flac-handle #f))
(unless (eq? audio-handle #f)
(audio-stop audio-handle)
(set! audio-handle #f))
(set! current-rate 0)
(set! current-channels 0)
@@ -327,7 +332,7 @@
(define/public (seek percentage)
(ao-clear-async ao-handle)
(flac-seek flac-handle percentage))
(audio-seek audio-handle percentage))
(define (state-machine)
(let ((st (orig-current-seconds))