test.rkt
#lang racket/base

(require "main.rkt"
         (prefix-in sf: "sample-format-struct.rkt"))

(define pi 3.14159265358979)

(define rate (* 3 5 7 #xb #xd))
; ...because even multiples of 2 are boring

(define sample-format (sf:make #x10 rate 1 big-endian #"M"))

(define (simple-harmonics device)
  (let loop ((boop 0)) 
           (play
            device
            (list->bytes
             (for/list ((i (in-range 0 rate)))
               (define level (sin (/ (* i pi boop 110) rate)))
               (inexact->exact (floor (+ #x20 (* #x20 level)))))))
           (loop (+ boop 1))))

(define (music-of-the-spheres device)
    (let loop ((boop 1)) 
           (play
            device
            (list->bytes
             (for/list ((i (in-range 0 rate)))
               (define level (sin (/ (* i pi boop 2) rate)))
               (inexact->exact (floor (+ #x20 (* #x20 level)))))))
           (loop (* boop 2))))

(let ((device #f))
  (dynamic-wind
   (λ () (set! device (open #:format sample-format)))
   (λ () (music-of-the-spheres device))
   (λ ()
     (when device
       (close device)))))