audio decoding
This commit is contained in:
+36
-2
@@ -24,7 +24,7 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(define-struct audio-reader
|
(define-struct audio-reader
|
||||||
(exts open reader seeker stopper))
|
(exts valid? open reader seeker stopper))
|
||||||
|
|
||||||
;; audiotype, audio-reader
|
;; audiotype, audio-reader
|
||||||
(define audio-readers (make-hash))
|
(define audio-readers (make-hash))
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
(hash-set! audio-readers
|
(hash-set! audio-readers
|
||||||
'flac
|
'flac
|
||||||
(make-audio-reader '("flac")
|
(make-audio-reader '("flac")
|
||||||
|
flac-valid?
|
||||||
flac-open
|
flac-open
|
||||||
flac-read
|
flac-read
|
||||||
flac-seek
|
flac-seek
|
||||||
@@ -84,7 +85,40 @@
|
|||||||
(-> (or/c string? path?) boolean?)
|
(-> (or/c string? path?) boolean?)
|
||||||
(let ((f (build-path file)))
|
(let ((f (build-path file)))
|
||||||
(let ((e (format "~a" (path-get-extension f))))
|
(let ((e (format "~a" (path-get-extension f))))
|
||||||
(audio-valid-ext? e))))
|
(if (audio-valid-ext? e)
|
||||||
|
(let ((reader (find-reader file)))
|
||||||
|
(if (eq? reader #f)
|
||||||
|
#f
|
||||||
|
(audio-reader-valid? file)))
|
||||||
|
#f))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; cb-stream-info will be called with
|
||||||
|
; - audio-type: symbol?
|
||||||
|
; - handle: audio-handle?
|
||||||
|
; - meta: hash?
|
||||||
|
; Meta information must at least contain:
|
||||||
|
; ('duration . seconds) - duration of the audio in seconds (or fractions): double
|
||||||
|
; ('bits-per-sample . integer) - number of audio bits per sample
|
||||||
|
; ('channels . integer) - number of audio channels
|
||||||
|
; ('sample-rate . integer) - number of samples per second per channel
|
||||||
|
; ('total-samples . integer) - total number of samples of the audio
|
||||||
|
;
|
||||||
|
; cb-audio will be called with
|
||||||
|
; - audio-type: symbol?
|
||||||
|
; - handle: audio-handle?
|
||||||
|
; - buf-info: hash?
|
||||||
|
; - buffer: cpointer? - contains data to be fed to ao - must be owned / released by the driver
|
||||||
|
; the ao-async backend will copy the data
|
||||||
|
; - buf-size: integer? - contains the size of the data
|
||||||
|
; buf-info must at least contain:
|
||||||
|
; ('duration . seconds) - duration of the audio in seconds (or fractions): double
|
||||||
|
; ('bits-per-sample . integer) - number of audio bits per sample
|
||||||
|
; ('channels . integer) - number of audio channels
|
||||||
|
; ('sample-rate . integer) - number of samples per second per channel
|
||||||
|
; ('total-samples . integer) - total number of samples of the audio
|
||||||
|
; (sample . integer) - the current sample the audio buffer applies to.
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(define/contract (audio-open audio-file cb-stream-info cb-audio)
|
(define/contract (audio-open audio-file cb-stream-info cb-audio)
|
||||||
(-> (or/c string? path?) procedure? procedure? audio-handle?)
|
(-> (or/c string? path?) procedure? procedure? audio-handle?)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"private/utils.rkt")
|
"private/utils.rkt")
|
||||||
|
|
||||||
(provide flac-open
|
(provide flac-open
|
||||||
|
flac-valid?
|
||||||
flac-read
|
flac-read
|
||||||
flac-read-meta
|
flac-read-meta
|
||||||
flac-stream-state
|
flac-stream-state
|
||||||
@@ -20,6 +21,9 @@
|
|||||||
;; Functions to do the good stuff
|
;; Functions to do the good stuff
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(define (flac-valid? flac-file*)
|
||||||
|
#t)
|
||||||
|
|
||||||
(define (flac-open flac-file* cb-stream-info cb-audio)
|
(define (flac-open flac-file* cb-stream-info cb-audio)
|
||||||
(let ((flac-file (if (path? flac-file*) (path->string flac-file*) flac-file*)))
|
(let ((flac-file (if (path? flac-file*) (path->string flac-file*) flac-file*)))
|
||||||
(if (file-exists? flac-file)
|
(if (file-exists? flac-file)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
(bytes-per-sample-all-channels (* channels bytes-per-sample))
|
(bytes-per-sample-all-channels (* channels bytes-per-sample))
|
||||||
(duration (hash-ref buf-info 'duration))
|
(duration (hash-ref buf-info 'duration))
|
||||||
)
|
)
|
||||||
|
(displayln buf-info)
|
||||||
(when (eq? ao-h #f)
|
(when (eq? ao-h #f)
|
||||||
(set! ao-h (ao-open-live bits-per-sample rate channels 'big-endian)))
|
(set! ao-h (ao-open-live bits-per-sample rate channels 'big-endian)))
|
||||||
;(displayln 'ao-play)
|
;(displayln 'ao-play)
|
||||||
|
|||||||
Reference in New Issue
Block a user