#lang racket
(require (planet clements/portaudio:3:1)
(planet clements/portaudio:3:1/devices)
ffi/vector)
(provide diagnose-sound-playing
host-api)
(define sample-rates '(44100.0 48000.0))
(define s16vec-len 24000)
(define s16vec (make-s16vector (* 2 s16vec-len)))
(for ([i s16vec-len])
(define sample
(inexact->exact
(floor
(* 32767 (* 0.2 (sin (* i 440.0 2.0 pi (/ 1.0 44100.0))))))))
(s16vector-set! s16vec (* i 2) sample)
(s16vector-set! s16vec (add1 (* i 2)) sample))
(define (diagnose-sound-playing)
(pa-maybe-initialize)
(define host-apis (all-host-apis))
(printf "found ~s host API(s): ~s\n"
(length host-apis)
host-apis)
(printf "trying each one in turn.\n")
(for ([api host-apis])
(printf "trying api ~s:\n" api)
(host-api api)
(for ([sr sample-rates])
(printf "trying to play at sample rate ~s:\n" sr)
(with-handlers ([exn:fail?
(lambda (exn)
(fprintf
(current-error-port)
"playing sound failed with message: ~s\n"
(exn-message exn)))])
(s16vec-play s16vec 0 s16vec-len sr)
(sleep (+ 1.0 (/ s16vec-len sr)))
(printf "...finished.\n"))))
(printf "~a" followup-message))
(define followup-message
#<<|
If playback at 44100.0 failed and playback at another sample rate
succeeded using Windows 7, you probably need to manually set the
sample rate of that playback device to 44100 Hz, by right-clicking
on the volume icon and then digging through menus (properties, advanced).
|
)