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-at #f)
(define el-length #f) (define el-length #f)
(define el-rate #f) (define el-rate #f)
(define el-format #f)
(define el-channels #f) (define el-channels #f)
(define el-bits #f) (define el-bits #f)
@@ -294,10 +295,11 @@
(send playlist add-tab!) (send playlist add-tab!)
(send this update-tabs)) (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-bits set-innerHTML! (format "~a ~a" bits (tr "bits")))
(send el-channels set-innerHTML! (format "~a ~a" channels (tr "channels"))) (send el-channels set-innerHTML! (format "~a ~a" channels (tr "channels")))
(send el-rate set-innerHTML! (format "~a Hz" rate)) (send el-rate set-innerHTML! (format "~a Hz" rate))
(send el-format set-innerHTML! (format "~a" audio-format))
) )
(define (update-repeat state) (define (update-repeat state)
@@ -370,6 +372,7 @@
(set! el-rate (send this element 'rate)) (set! el-rate (send this element 'rate))
(set! el-bits (send this element 'bits)) (set! el-bits (send this element 'bits))
(set! el-channels (send this element 'channels)) (set! el-channels (send this element 'channels))
(set! el-format (send this element 'format))
(send this set-menu! (player-menu)) (send this set-menu! (player-menu))
(send this connect-menu! 'm-quit (λ () (send this quit))) (send this connect-menu! 'm-quit (λ () (send this quit)))
+1
View File
@@ -50,6 +50,7 @@
</div> </div>
<div class="status"> <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="bits"></span><span class="info" id="rate"></span><span class="info" id="channels"></span>
<span class="info" id="format"></span>
<div class="right"> <div class="right">
<span class="info" id="volume-percentage"></span> <span class="info" id="volume-percentage"></span>
<span class="info" id="log-file"></span> <span class="info" id="log-file"></span>
+30 -25
View File
@@ -16,7 +16,7 @@
[track-nr-updater (λ (nr) #t)] [track-nr-updater (λ (nr) #t)]
[state-updater (λ (state) #t)] [state-updater (λ (state) #t)]
[repeat-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-max-seconds 10]
[buffer-min-seconds 4] [buffer-min-seconds 4]
) )
@@ -33,7 +33,7 @@
(define volume 100.0) (define volume 100.0)
(define ao-handle #f) (define ao-handle #f)
(define flac-handle #f) (define audio-handle #f)
(define current-music-id -1) (define current-music-id -1)
(define current-track-id -1) (define current-track-id -1)
@@ -41,6 +41,7 @@
(define current-rate 0) (define current-rate 0)
(define current-bits 0) (define current-bits 0)
(define current-channels 0) (define current-channels 0)
(define current-audio-format 'none)
(define current-length 0) (define current-length 0)
(define current-seconds 0) (define current-seconds 0)
@@ -60,7 +61,7 @@
current-rate current-bits current-channels ao-handle) current-rate current-bits current-channels ao-handle)
(dbg-rktplayer "Opening ao-handle") (dbg-rktplayer "Opening ao-handle")
(when use-ao (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) (start-play-time-updater)
) )
) )
@@ -104,16 +105,16 @@
(= current-bits bits) (= current-bits bits)
(= current-channels channels))) (= 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) (unless (eq? state 'quitted)
(let* ((sample (hash-ref frame 'number)) (let* ((sample (hash-ref buf-info 'sample))
(rate (hash-ref frame 'sample-rate)) (rate (hash-ref buf-info 'sample-rate))
(second (/ (* sample 1.0) (* rate 1.0))) (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)) (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)) (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) (unless (stream-equal? rate bits-per-sample channels)
@@ -134,7 +135,7 @@
(set! current-length duration) (set! current-length duration)
(when (eq? ao-handle #f) (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) (check-ao-handle)
@@ -151,7 +152,7 @@
(sleep 0.25)))) (sleep 0.25))))
(when (not (eq? ao-handle #f)) (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) (define (audio-meta type ao-type handle meta)
(dbg-rktplayer "flac meta: ~a" 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) (define (play-track-worker)
(thread (thread
@@ -180,14 +184,15 @@
(if (eq? ct-data #f) (if (eq? ct-data #f)
'no-track-data 'no-track-data
(let ((file (send ct-data get-file))) (let ((file (send ct-data get-file)))
(dbg-rktplayer "opening flac handle for file: ~a" file) (dbg-rktplayer "opening audios handle for file: ~a" file)
(set! flac-handle (flac-open file flac-meta flac-play)) (set! audio-handle (audio-open file audio-meta audio-play))
(set! current-track-id (send ct-data get-id)) (set! current-track-id (send ct-data get-id))
(dbg-rktplayer "Starting flac-read") (dbg-rktplayer "Starting audio-read")
(let ((result (flac-read flac-handle))) (audio-read audio-handle)
(if (eq? result 'end-of-stream) (unless (eq? state 'stopped)
(set-state! 'track-feeded) (set-state! 'track-feeded)
(dbg-rktplayer "Flac read stopped"))) (dbg-rktplayer "Audio read done")
)
'worker-done 'worker-done
) )
) )
@@ -198,13 +203,13 @@
) )
(define (close-player*) (define (close-player*)
(dbg-rktplayer "Closing flac handle") (dbg-rktplayer "Closing audio handle")
(set! closing #t) (set! closing #t)
(unless (eq? flac-handle #f) (unless (eq? audio-handle #f)
(flac-stop flac-handle) (audio-stop audio-handle)
(set! flac-handle #f)) (set! audio-handle #f))
(set! current-rate 0) (set! current-rate 0)
(set! current-channels 0) (set! current-channels 0)
@@ -327,7 +332,7 @@
(define/public (seek percentage) (define/public (seek percentage)
(ao-clear-async ao-handle) (ao-clear-async ao-handle)
(flac-seek flac-handle percentage)) (audio-seek audio-handle percentage))
(define (state-machine) (define (state-machine)
(let ((st (orig-current-seconds)) (let ((st (orig-current-seconds))
+11
View File
@@ -50,6 +50,14 @@
(define/public (get-length) length) (define/public (get-length) length)
(define/public (get-id) my-id) (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) (define (read-tags)
(let* ((f (if (path? file) (path->string file) file)) (let* ((f (if (path? file) (path->string file) file))
(tags (id3-tags f)) (tags (id3-tags f))
@@ -307,6 +315,9 @@
(define/public (read-tracks) (define/public (read-tracks)
(set! tracks '()) (set! tracks '())
(read-tracks-internal start-map) (read-tracks-internal start-map)
(set! tracks
(sort tracks (λ (t1 t2)
(send t1 track< t2))))
(send this save-tab!) (send this save-tab!)
) )
+7 -6
View File
@@ -35,6 +35,8 @@
) )
) )
(define rktplayer-window #f)
(define (run) (define (run)
(let* ((ini (new ini% [file 'rktplayer])) (let* ((ini (new ini% [file 'rktplayer]))
(context (new wv-context% (context (new wv-context%
@@ -43,12 +45,11 @@
[file-getter my-file-getter] [file-getter my-file-getter]
)) ))
) )
(let ( (let ((window (new rktplayer% [wv-context context] [log-file log-file])))
(window (new rktplayer% [wv-context context] [log-file log-file])) (set! rktplayer-window window)
) (webview-wait-for-quit)
(webview-wait-for-quit) (webview-exit)
(webview-exit) (exit))
(exit))
) )
) )