80 lines
2.4 KiB
Racket
80 lines
2.4 KiB
Racket
#lang racket/base
|
|
|
|
(require racket/runtime-path
|
|
"private/utils.rkt"
|
|
"libmpg123-ffi.rkt"
|
|
"audio-decoder.rkt"
|
|
)
|
|
|
|
(provide mp3-ffi-read-test
|
|
decoder-read-test
|
|
test-file1
|
|
test-file2
|
|
test-file3
|
|
test-file4
|
|
test-file5)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; test audio
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(define-runtime-path tests "../racket-audio-test")
|
|
|
|
(define test-file1 (build-path tests "idyll.mp3"))
|
|
(define test-file2 (build-path tests "idyll.flac"))
|
|
(define test-file3 (build-path tests "mahler-1.mp3"))
|
|
(define test-file4 (build-path tests "mahler-2.mp3"))
|
|
(define test-file5 (build-path tests "mahler-1.opus"))
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; test functions
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; mp3 read test ffi
|
|
|
|
(define (mp3-ffi-read-test)
|
|
(let* ((file test-file1)
|
|
(state #f)
|
|
(audio '())
|
|
(formats '())
|
|
(h (mpg123-ffi-decoder-handler))
|
|
)
|
|
(h 'new)
|
|
(h 'init file)
|
|
(let loop ()
|
|
(h 'read
|
|
(λ (kind pos buf done)
|
|
(set! state kind)
|
|
(set! audio (cons (list kind pos done) audio)))
|
|
(λ (pos rate channels sample-bits sample-bytes length)
|
|
(set! formats (cons (list rate channels sample-bits sample-bytes length) formats))))
|
|
(unless (eq? state 'done)
|
|
(loop)))
|
|
(h 'close)
|
|
(h 'delete)
|
|
|
|
(displayln (format "got ~a audio samples (~a)" (length audio) (car audio)))
|
|
(displayln (format "got ~a formats (~a)" (length formats) (car formats)))
|
|
))
|
|
|
|
;;; decoder read test
|
|
|
|
(define (decoder-read-test file)
|
|
(let* ((state #f)
|
|
(audio '())
|
|
(formats '())
|
|
(h (audio-open file
|
|
(λ (reader-type ao-type handle meta)
|
|
(set! formats (cons (list reader-type ao-type meta) formats)))
|
|
(λ (reader-type ao-type handle buf-info audio-buffer buf-len)
|
|
(set! audio
|
|
(cons (list reader-type ao-type buf-info buf-len) audio)))
|
|
)))
|
|
(audio-read h)
|
|
|
|
(displayln (format "got ~a audio samples (~a)" (length audio) (car audio)))
|
|
(displayln (format "got ~a formats (~a)" (length formats) (car formats)))
|
|
)
|
|
)
|
|
|