flac problems for os threads solved.

This commit is contained in:
2026-06-29 15:10:15 +02:00
parent c4e1a78527
commit b38983109b
4 changed files with 206 additions and 51 deletions
+69
View File
@@ -0,0 +1,69 @@
#lang racket/base
(require "../flac-decoder.rkt")
(define (test-flac-thread flac-path #:pool [pool #f])
(define result-ch (make-channel))
(define (start)
(thread
(lambda ()
(with-handlers ([exn:fail?
(lambda (e)
(channel-put result-ch
(list 'error (exn-message e))))])
(define frames 0)
(define buffers 0)
(define bytes 0)
(define fmt #f)
(define h
(flac-open
flac-path
;; stream-info callback
(lambda (info)
(set! fmt info)
(printf "format: ~s\n" info)
(flush-output))
;; audio callback
(lambda (info buffer len)
(set! buffers (add1 buffers))
(set! bytes (+ bytes len))
(define blocksize (hash-ref info 'blocksize #f))
(when (integer? blocksize)
(set! frames (+ frames blocksize)))
;; af en toe iets printen, zodat je ziet dat hij loopt
(when (zero? (modulo buffers 500))
(printf "buffers=~a bytes=~a frames=~a\n"
buffers bytes frames)
(flush-output)))))
(unless h
(error 'test-flac-thread "could not open FLAC file: ~a" flac-path))
(define state (flac-read h))
(channel-put result-ch
(list 'ok
'state state
'buffers buffers
'bytes bytes
'frames frames
'format fmt))))
#:pool pool)
)
(start)
(start)
(start)
(channel-get result-ch)
(channel-get result-ch)
(channel-get result-ch)
)
; (test-flac-thread "\\\\panderleou\\music\\Jazz\\LA4\\LA4 - Zaca\\01 Zaca.flac")
+46
View File
@@ -0,0 +1,46 @@
#lang racket/base
(require "../main.rkt"
"../audio-encoder.rkt")
(define (convert-to-opus flac-in opus-out)
(let* ((opus-kbps 224)
(settings (hash 'bitrate (* opus-kbps 1000)
'vbr #t))
)
(with-handlers ([exn? (λ (e)
(displayln (format "~a" e))
(when (file-exists? opus-out)
(delete-file opus-out))
#f)])
(let ((result (audio-encode flac-in opus-out
settings
#:encoder 'opus
#:copy-tags? #t)))
#t)
)
)
)
(define (times-3-convert flac-in opus-out1 opus-out2 opus-out3 #:pool [pool #f])
(define (start opus-out)
(thread (λ ()
(displayln (format "Starting conversion: ~a" opus-out))
(convert-to-opus flac-in opus-out)
(displayln (format" converted: ~a" opus-out))
#t
) #:pool pool)
)
(let* ((t1 (start opus-out1))
(t2 (start opus-out2))
(t3 (start opus-out3))
)
(thread-wait t1)
(thread-wait t2)
(thread-wait t3)
)
)
; (convert-to-opus "\\\\panderleou\\music\\Jazz\\LA4\\LA4 - Zaca\\01 Zaca.flac" "c:\\tmp\\test.opus" )