-
Notifications
You must be signed in to change notification settings - Fork 0
/
sine-example.ss
32 lines (24 loc) · 1.08 KB
/
sine-example.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(import (prefix (soundio) soundio:))
(define pi 3.1415926535)
(define two-pi (* 2 pi))
(define sine (lambda (time freq)
(sin (* two-pi freq time))))
(define square (lambda (time freq)
(let ([ft (* two-pi freq time)])
(+ (- (* 2 (floor ft))
(floor (* 2 ft)))
1))))
(define write-callback (lambda (time channel)
(let ([k 100]
[sample 0.0])
(do ([i 0 (+ i 1)]
[sample 0.0 (+ sample (sine time (+ 440.0 i)))])
((= i k) (/ sample k))))))
(define square-callback (lambda (time channel)
(let ([k 20]
[sample 0.0])
(do ([i 0 (+ i 1)]
[sample 0.0 (+ sample (square time (+ 440.0 i)))])
((= i k) (/ sample k 2))))))
(define my-out (soundio:open-default-out-stream write-callback))
(soundio:start-out-stream my-out)