#lang racket
(require "./rsound.rkt"
"./sequencer.rkt")
(provide play/s
play/s/f
current-time/s)
(define (play/s snd)
(unless (rsound? snd)
(raise-type-error 'play/s "rsound" 0 snd))
(play/s/f snd (current-time/s)))
(define (play/s/f snd frame)
(unless (rsound? snd)
(raise-type-error 'play/s/f "rsound" 0 snd frame))
(unless (nonnegative-integer? frame)
(raise-type-error 'play/s/f "nonnegative integer" 1 snd frame))
(maybe-initialize)
(queue-for-playing! sound-heap snd frame))
(define sound-heap (make-unplayed-heap))
(define-values (signal/block/unsafe current-time/s)
(heap->signal/block/unsafe sound-heap))
(define already-started? #f)
(define (maybe-initialize)
(when (not already-started?)
(signal/block-play/unsafe signal/block/unsafe (default-sample-rate))
(set! already-started? #t)))