diff options
Diffstat (limited to 'main.scm')
-rw-r--r-- | main.scm | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -1,23 +1,34 @@ (use-modules (ice-9 binary-ports)) +(define bitrate 8000) + (define (note freq start len) ( lambda (t) ( if (or (< t start) (>= t (+ start len))) 0 - freq + (sin (* 2 (acos -1) freq t)) ) )) -(define (music t) ( - * t (logand 42 (ash t -10)) +(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 (modulo (music t) 256) (if (< t 100000) - (play (+ t 1)) + cons (music t) (if (< t 5) + (play (+ t (/ 1 bitrate))) '() ) )) -; (display (play 0)) -(map (lambda (c) (put-u8 (current-output-port) c)) (play 0)) +;(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)) |