corrected main.rkt and removed archive as it gets compiled on the racket packages site.

This commit is contained in:
2026-05-16 08:23:52 +02:00
parent 17838e4f33
commit ba087f07f1
3 changed files with 4 additions and 326 deletions
-130
View File
@@ -1,130 +0,0 @@
#lang racket/base
(require ffi/unsafe
ffi/unsafe/define
"private/utils.rkt"
;"libao-ffi.rkt"
)
(provide ao_create_async
ao_real_output_bits_async
ao_stop_async
ao_play_async
ao_is_at_music_id_async
ao_is_at_second_async
ao_music_duration_async
ao_bufsize_async
ao_reuse_buf_len
ao_clear_async
ao_pause_async
ao_set_volume_async
ao_volume_async
make-BufferInfo_t
ao_version
ao-playback-buf-ms
ao-set-playback-buf-ms!
ao_sample_queue_len
)
(define pb 250)
(define (ao-playback-buf-ms)
pb)
(define (ao-set-playback-buf-ms! ms)
(set! pb ms))
(define (ao_sample_queue_len h)
0)
(define _BufferType_t
(_enum '(ao = 1
flac = 2
mp3 = 3
ogg = 4
)))
;#define AO_FMT_LITTLE 1
;#define AO_FMT_BIG 2
;#define AO_FMT_NATIVE 4
(define _Endian_t
(_enum '(little-endian = 1
big-endian = 2
native-endian = 4
)
)
)
(define-cstruct _BufferInfo_t
(
[type _BufferType_t]
[sample_bits _int]
[sample_rate _int]
[channels _int]
[endiannes _Endian_t]
))
(define (ao_version)
(let* ((v (ao_async_version))
(patch (remainder v 256))
(minor (remainder (quotient v 256) 256))
(major (quotient v 65536))
)
(list major minor patch)))
(when (eq? (system-type 'os) 'windows)
(void (get-lib '("libao-1.2.2") '(#f))))
(define lib (get-lib '("ao-play-async" "libao-play-async") '(#f)))
;(define lib (ffi-lib "/home/hans/src/racket/racket-sound-lib/lib/linux-x86_64/libao-play-async.so"))
(define-ffi-definer define-libao-async lib
#:default-make-fail make-not-available)
(define _libao-async-handle-pointer (_cpointer 'ao-async-handle))
;extern int ao_async_version()
(define-libao-async ao_async_version (_fun -> _int))
;extern void *ao_create_async(int bits, int rate, int channel, int byte_format);
(define-libao-async ao_create_async(_fun _int _int _int _Endian_t _string/utf-8 -> _libao-async-handle-pointer))
;extern int ao_real_output_bits(void *handle)
(define-libao-async ao_real_output_bits_async
(_fun _libao-async-handle-pointer -> _int))
;extern void ao_stop_async(void *handle);
(define-libao-async ao_stop_async(_fun _libao-async-handle-pointer -> _void))
;extern void ao_play_async(void *handle, int music_id, double at_second, double music_duration, int buf_size, void *mem, BufferInfo_t info);
(define-libao-async ao_play_async(_fun _libao-async-handle-pointer _int _double _double _uint32 _pointer _BufferInfo_t -> _void))
;extern double ao_is_at_second_async(void *handle);
(define-libao-async ao_is_at_second_async(_fun _libao-async-handle-pointer -> _double))
;extern int ao_is_at_music_id_async(void *handle);
(define-libao-async ao_is_at_music_id_async (_fun _libao-async-handle-pointer -> _int))
;extern double ao_music_duration_async(void *handle);
(define-libao-async ao_music_duration_async(_fun _libao-async-handle-pointer -> _double))
;extern int ao_bufsize_async(void *handle);
(define-libao-async ao_bufsize_async(_fun _libao-async-handle-pointer -> _int))
;extern void ao_clear_async(void *handle);
(define-libao-async ao_clear_async(_fun _libao-async-handle-pointer -> _void))
;extern void ao_pause_async(void *handle, int pause);
(define-libao-async ao_pause_async(_fun _libao-async-handle-pointer _int -> _void))
;extern void ao_set_volume_async(void *handle, double percentage)
(define-libao-async ao_set_volume_async (_fun _libao-async-handle-pointer _double -> _void))
;extern double ao_volume_async(void *handle)
(define-libao-async ao_volume_async (_fun _libao-async-handle-pointer -> _double))
(define (ao_reuse_buf_len h) -1)
-188
View File
@@ -1,188 +0,0 @@
#lang racket/base
(require "ao-player.rkt"
"audio-decoder.rkt"
simple-log
"private/utils.rkt"
racket-sprintf
racket/runtime-path)
(define-runtime-path tests "../racket-audio-test")
(define test-file3 (build-path tests "idyll.flac"))
(define test-file4 (build-path tests "mahler-2.mp3"))
(define test-file3-id 3)
(define test-file4-id 4)
(define current-seconds 0)
(define current-file-id -1)
(define current-audio-h #f)
(define player #f)
(sl-log-to-display)
(define wav-output-file #f)
(define seeked #f)
(define (player-status)
(if player
(ao-player-status player)
(hash 'open? #f
'at-second 0.0
'duration 0.0
'buf-size 0
'volume 100.0
'reuse-buf-len 0
'sample-queue-len 0
'device-bits 0)))
(define (player-at-second)
(hash-ref (player-status) 'at-second 0.0))
(define (player-volume)
(hash-ref (player-status) 'volume 100.0))
(define (player-bufsize)
(hash-ref (player-status) 'buf-size 0))
(define (player-reuse-buf-len)
(hash-ref (player-status) 'reuse-buf-len 0))
(define (player-sample-queue-len)
(hash-ref (player-status) 'sample-queue-len 0))
(define (cond-seek duration)
(when (>= (round current-seconds) 10)
(when (and (= current-file-id test-file3-id) (not seeked))
(set! seeked #t)
(let ((perc (exact->inexact (* (/ (- duration 15) duration) 100.0))))
(info-sound "Seeking to ~a%" perc)
(audio-seek current-audio-h perc)))))
(define (cond-volume)
(when (= (round current-seconds) 20)
(ao-player-set-volume! player 70.0))
(when (= (round current-seconds) 25)
(ao-player-set-volume! player 30))
(when (= (round current-seconds) 30)
(ao-player-set-volume! player 100))
(when (= (round current-seconds) 35)
(ao-player-set-volume! player 150))
(when (= (round current-seconds) 40)
(ao-player-set-volume! player 100)))
(define (audio-play type ao-type handle buf-info buffer buf-len)
;(dbg-sound "~a ~a ~a ~a ~a" type ao-type handle buf-info buf-len)
(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 buf-info 'bits-per-sample))
(bytes-per-sample (/ bits-per-sample 8))
(channels (hash-ref buf-info 'channels))
(bytes-per-sample-all-channels (* channels bytes-per-sample))
(duration (hash-ref buf-info 'duration)))
;; Fire-and-forget naar de player-place. De player opent/sluit intern
;; opnieuw wanneer bits/rate/channels wijzigen.
;(dbg-sound "Playing ~a" buf-info)
;(sync-log-sound)
(ao-player-play! player
current-file-id
second
duration
buf-info
buffer
buf-len
ao-type)
;(dbg-sound "played")
;(sync-log-sound)
(let ((duration* (inexact->exact (round duration))))
(define (second-printer buf-seconds)
(let* ((st (player-status))
(s (inexact->exact (round (hash-ref st 'at-second 0.0)))))
(unless (= s current-seconds)
(set! current-seconds s)
(let ((minutes (quotient s 60))
(seconds (remainder s 60))
(tminutes (quotient duration* 60))
(tseconds (remainder duration* 60))
(volume (hash-ref st 'volume 100.0)))
(info-sound
(sprintf "At time: %02d:%02d (%02d:%02d) - %d - volume: %d"
minutes seconds
tminutes tseconds
buf-seconds
volume))))))
(let* ((st (player-status))
(buf-size (hash-ref st 'buf-size 0))
(buf-seconds
(exact->inexact
(/ buf-size bytes-per-sample-all-channels rate))))
(second-printer buf-seconds)
(cond-seek duration)
(cond-volume)
(when (> buf-seconds 10)
(info-sound "Reuse buf/Sample queue: ~a/~a"
(hash-ref st 'reuse-buf-len 0)
(hash-ref st 'sample-queue-len 0))
(letrec ((waiter
(lambda ()
(let* ((st (player-status))
(buf-size-left (hash-ref st 'buf-size 0))
(buf-seconds-left
(exact->inexact
(/ buf-size-left
bytes-per-sample-all-channels
rate))))
(if (< buf-seconds-left 3.0)
(info-sound "Seconds in buffer left: ~a"
buf-seconds-left)
(begin
(sleep 0.5)
(second-printer buf-seconds-left)
(cond-volume)
(cond-seek duration)
(waiter)))))))
(waiter)
(let ((st (player-status)))
(info-sound "Reuse buf/Sample queue: ~a/~a"
(hash-ref st 'reuse-buf-len 0)
(hash-ref st 'sample-queue-len 0)))))))))
(define (audio-meta type ao-type handle meta)
(dbg-sound "type: ~a" type)
(dbg-sound "ao-type: ~a" ao-type)
(dbg-sound "meta: ~a" meta))
(define (play-one file file-id)
(let ((audio-h (audio-open file audio-meta audio-play)))
(set! current-file-id file-id)
(set! current-audio-h audio-h)
(audio-read audio-h)))
(define (play)
(set! player (make-ao-player #:wav-output-file wav-output-file))
(set! current-seconds 0)
(set! seeked #f)
(displayln (player-status))
(play-one test-file3 test-file3-id)
;; Bij overgang naar volgend bestand: queue leegmaken, zodat oude buffers
;; niet doorlopen in de volgende track.
(ao-player-clear! player)
(info-sound "Opening next file: ~a" test-file4)
(set! current-seconds 0)
(play-one test-file4 test-file4-id)
(ao-player-close! player)
(set! player #f))
(play)
+4 -8
View File
@@ -1,16 +1,12 @@
#lang racket/base
(require "libao.rkt"
"audio-decoder.rkt"
"taglib.rkt"
(require "taglib.rkt"
"audio-sniffer.rkt"
"ao-player.rkt"
"audio-player.rkt"
)
(provide (all-from-out "libao.rkt")
(all-from-out "audio-decoder.rkt")
(all-from-out "taglib.rkt")
(provide (all-from-out "taglib.rkt")
(all-from-out "audio-sniffer.rkt")
(all-from-out "ao-player.rkt")
(all-from-out "audio-player.rkt")
)