Added volume controle on sample level.

libao-async will adjust the volume of the samples.
This commit is contained in:
2026-04-21 10:10:29 +02:00
parent 8182b17096
commit a7caad7fa4
4 changed files with 39 additions and 5 deletions

View File

@@ -16,6 +16,8 @@
ao_bufsize_async
ao_clear_async
ao_pause_async
ao_set_volume_async
ao_volume_async
make-BufferInfo_t
)
@@ -88,3 +90,8 @@
;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))

View File

@@ -18,6 +18,8 @@
ao-bufsize-async
ao-clear-async
ao-pause
ao-set-volume!
ao-volume
ao-valid?
ao-valid-bits?
ao-valid-rate?
@@ -177,7 +179,20 @@
(ffi:ao_bufsize_async (ao-handle-async-player handle))
)
(define (ao-clear-async handle)
(rc:define/contract (ao-set-volume! handle percentage)
(rc:-> ao-handle? number? void?)
(ffi:ao_set_volume_async (ao-handle-async-player handle)
(if (integer? percentage)
(exact->inexact percentage)
percentage))
)
(rc:define/contract (ao-volume handle)
(rc:-> ao-handle? number?)
(ffi:ao_volume_async (ao-handle-async-player handle))
)
(rc:define/contract (ao-clear-async handle)
(rc:-> ao-handle? void?)
(ffi:ao_clear_async (ao-handle-async-player handle))
)

View File

@@ -48,16 +48,18 @@
(seconds (remainder s 60))
(tminutes (quotient duration 60))
(tseconds (remainder duration 60))
(volume (ao-volume ao-h))
)
(displayln (format "At time: ~a:~a (~a:~a) - ~a"
(displayln (format "At time: ~a:~a (~a:~a) - ~a - volume: ~a"
minutes seconds
tminutes tseconds
buf-seconds
volume
))))))))
(let* ((buf-size (ao-bufsize-async ao-h))
(buf-seconds (exact->inexact (/ buf-size bytes-per-sample-all-channels rate))))
(second-printer buf-seconds)
(when (> buf-seconds 30)
(when (> buf-seconds 10)
(letrec ((waiter (λ ()
(let ((buf-seconds-left (exact->inexact
(/ (ao-bufsize-async ao-h)
@@ -66,8 +68,18 @@
(if (< buf-seconds-left 2.0)
(displayln (format "Seconds in buffer left: ~a" buf-seconds-left))
(begin
(sleep 1)
(sleep 0.5)
(second-printer buf-seconds)
(when (= (round current-seconds) 20)
(ao-set-volume! ao-h 70.0))
(when (= (round current-seconds) 25)
(ao-set-volume! ao-h 30))
(when (= (round current-seconds) 30)
(ao-set-volume! ao-h 100))
(when (= (round current-seconds) 35)
(ao-set-volume! ao-h 150))
(when (= (round current-seconds) 40)
(ao-set-volume! ao-h 100))
(waiter)))))
))
(waiter))))

View File

@@ -26,7 +26,7 @@
(define version-major 0)
(define version-minor 1)
(define version-patch 0)
(define version-patch 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal functions