diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | main.scm | 25 |
2 files changed, 19 insertions, 8 deletions
@@ -1,4 +1,4 @@ # Lambeat Bytebeat in Scheme -You can use `guile main.scm | aplay` to try it out. I'm working on a better audio output method. +You can use `guile main.scm | play -r 8000 -t s16 -v 0.25 -` to try it out. @@ -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)) |