yue/main.scm
2022-12-17 14:13:14 -06:00

42 lines
760 B
Scheme

(use-modules (ice-9 binary-ports))
(define bitrate 8000)
(define (saw t) (
let ((m (floor-remainder (+ t (/ 1 4)) 1)))
(if (< m 1/2)
(- (* 4 m) 1)
(- 3 (* 4 m)))
))
(define (note freq start len) (
lambda (t) (
if (or (< t start) (>= t (+ start len)))
0
(saw (* freq t))
)
))
(define (music t) (+
((note 523.25 0 1) t)
((note 587.33 1 1) t)
((note 659.25 2 1) t)
((note 698.46 3 1) t)
((note 783.99 4 1) t)
))
(define (play t) (
cons (music t) (if (< t 5)
(play (+ t (/ 1 bitrate)))
'()
)
))
;(display (play 0))
(for-each (lambda (a) (
let ((b (modulo (inexact->exact (round (* (+ a 2) 32768))) 65536)))
cons
(put-u8 (current-output-port) (modulo b 256))
(put-u8 (current-output-port) (quotient b 256))
)) (play 0))