Added volume controle on sample level.
libao-async will adjust the volume of the samples.
This commit is contained in:
@@ -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))
|
||||
|
||||
17
libao.rkt
17
libao.rkt
@@ -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))
|
||||
)
|
||||
|
||||
@@ -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))))
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
(define version-major 0)
|
||||
(define version-minor 1)
|
||||
(define version-patch 0)
|
||||
(define version-patch 1)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Internal functions
|
||||
|
||||
Reference in New Issue
Block a user