diff --git a/audio-decoder.rkt b/audio-decoder.rkt index 9b46883..9a54039 100644 --- a/audio-decoder.rkt +++ b/audio-decoder.rkt @@ -24,7 +24,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-struct audio-reader - (exts open reader seeker stopper)) + (exts valid? open reader seeker stopper)) ;; audiotype, audio-reader (define audio-readers (make-hash)) @@ -32,6 +32,7 @@ (hash-set! audio-readers 'flac (make-audio-reader '("flac") + flac-valid? flac-open flac-read flac-seek @@ -84,7 +85,40 @@ (-> (or/c string? path?) boolean?) (let ((f (build-path file))) (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) (-> (or/c string? path?) procedure? procedure? audio-handle?) diff --git a/flac-decoder.rkt b/flac-decoder.rkt index f068485..abc5de7 100644 --- a/flac-decoder.rkt +++ b/flac-decoder.rkt @@ -6,6 +6,7 @@ "private/utils.rkt") (provide flac-open + flac-valid? flac-read flac-read-meta flac-stream-state @@ -20,6 +21,9 @@ ;; Functions to do the good stuff ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (define (flac-valid? flac-file*) + #t) + (define (flac-open flac-file* cb-stream-info cb-audio) (let ((flac-file (if (path? flac-file*) (path->string flac-file*) flac-file*))) (if (file-exists? flac-file) diff --git a/play-test.rkt b/play-test.rkt index d887e58..bf01e45 100644 --- a/play-test.rkt +++ b/play-test.rkt @@ -36,6 +36,7 @@ (bytes-per-sample-all-channels (* channels bytes-per-sample)) (duration (hash-ref buf-info 'duration)) ) + (displayln buf-info) (when (eq? ao-h #f) (set! ao-h (ao-open-live bits-per-sample rate channels 'big-endian))) ;(displayln 'ao-play)