#lang racket
(require (planet gcr/libvorbisfile))
(define AL_FORMAT_STEREO16
(dynamic-require '(planet gcr/openal)
'AL_FORMAT_STEREO16))
(define open-device
(dynamic-require '(planet gcr/openal)
'open-device))
(define create-context
(dynamic-require '(planet gcr/openal)
'create-context))
(define gen-sources
(dynamic-require '(planet gcr/openal)
'gen-sources))
(define stream-port-to-source
(dynamic-require '(planet gcr/openal)
'stream-port-to-source))
(define play-source
(dynamic-require '(planet gcr/openal)
'play-source))
(define set-current-context
(dynamic-require '(planet gcr/openal)
'set-current-context))
(define destroy-context!
(dynamic-require '(planet gcr/openal)
'destroy-context!))
(define close-device!
(dynamic-require '(planet gcr/openal)
'close-device!))
(define device (open-device #f))
(define context (create-context device))
(set-current-context context)
(define filename (vector-ref (current-command-line-arguments) 0))
(printf "Playing file ~a\n" filename)
(define m (open-vorbis-file filename))
(printf "Rate: ~a Channels: ~a Length: ~a sec\n"
(vorbis-frequency m)
(vorbis-channels m)
(vorbis-length-time m))
(define vorbis-binary (make-vorbis-input-port m 0 2 1))
(define source (car (gen-sources 1)))
(define stream-thread
(stream-port-to-source vorbis-binary
source
AL_FORMAT_STEREO16
(vorbis-frequency m)))
(play-source source)
(thread-wait stream-thread)
(set-current-context #f)
(destroy-context! context)
(close-device! device)
(close-vorbis-file! m)