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
+4 -1
View File
@@ -56,6 +56,7 @@
(define el-at #f)
(define el-length #f)
(define el-rate #f)
(define el-format #f)
(define el-channels #f)
(define el-bits #f)
@@ -294,10 +295,11 @@
(send playlist add-tab!)
(send this update-tabs))
(define (update-audio-info samples rate channels bits)
(define (update-audio-info samples rate channels bits audio-format)
(send el-bits set-innerHTML! (format "~a ~a" bits (tr "bits")))
(send el-channels set-innerHTML! (format "~a ~a" channels (tr "channels")))
(send el-rate set-innerHTML! (format "~a Hz" rate))
(send el-format set-innerHTML! (format "~a" audio-format))
)
(define (update-repeat state)
@@ -370,6 +372,7 @@
(set! el-rate (send this element 'rate))
(set! el-bits (send this element 'bits))
(set! el-channels (send this element 'channels))
(set! el-format (send this element 'format))
(send this set-menu! (player-menu))
(send this connect-menu! 'm-quit (λ () (send this quit)))
+1
View File
@@ -50,6 +50,7 @@
</div>
<div class="status">
<span class="info" id="bits"></span><span class="info" id="rate"></span><span class="info" id="channels"></span>
<span class="info" id="format"></span>
<div class="right">
<span class="info" id="volume-percentage"></span>
<span class="info" id="log-file"></span>
+29 -24
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)
(dbg-rktplayer "Starting audio-read")
(audio-read audio-handle)
(unless (eq? state 'stopped)
(set-state! 'track-feeded)
(dbg-rktplayer "Flac read stopped")))
(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))
+11
View File
@@ -50,6 +50,14 @@
(define/public (get-length) length)
(define/public (get-id) my-id)
(define/public (track< t2)
(if (string-ci<? album (send t2 get-album))
#t
(if (string-ci=? album (send t2 get-album))
(< number (send t2 get-number))
#f))
)
(define (read-tags)
(let* ((f (if (path? file) (path->string file) file))
(tags (id3-tags f))
@@ -307,6 +315,9 @@
(define/public (read-tracks)
(set! tracks '())
(read-tracks-internal start-map)
(set! tracks
(sort tracks (λ (t1 t2)
(send t1 track< t2))))
(send this save-tab!)
)
+4 -3
View File
@@ -35,6 +35,8 @@
)
)
(define rktplayer-window #f)
(define (run)
(let* ((ini (new ini% [file 'rktplayer]))
(context (new wv-context%
@@ -43,9 +45,8 @@
[file-getter my-file-getter]
))
)
(let (
(window (new rktplayer% [wv-context context] [log-file log-file]))
)
(let ((window (new rktplayer% [wv-context context] [log-file log-file])))
(set! rktplayer-window window)
(webview-wait-for-quit)
(webview-exit)
(exit))