From 41b550eca27e073c6b0259b59872b6b6b90fbf77 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 17 Dec 2022 13:58:17 -0600 Subject: Use sox instead of aplay --- README.md | 2 +- main.scm | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b28fc17..adaf2e0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/main.scm b/main.scm index 0278148..75c78df 100644 --- a/main.scm +++ b/main.scm @@ -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)) -- cgit v1.2.3-70-g09d2