Changes
3 changed files (+25/-36)
-
-
@@ -5,17 +5,15 @@ ; Bitrate is the number time to sample the music function each second(define bitrate 8000) ; Get the music as a list sampled at the bitrate (define (play t end) ( cons (* 1/4 (tri (* t (music t)))) (if (< t end) (play (+ t (/ 1 bitrate)) end) '() ) )) (define (play t end) (cons (* 1/4 (tri (* t (music t)))) (if (< t end) (play (+ t (/ 1 bitrate)) end) '()))) ; Output the list in the s16 raw audio format (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 4)) (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 4))
-
-
-
@@ -1,21 +1,17 @@; Triangle wave with a period of 1 second (define (tri t) ( let ((m (floor-remainder (+ t (/ 1 4)) 1))) (define (tri t) (let ((m (floor-remainder (+ t (/ 1 4)) 1))) (if (< m 1/2) (- (* 4 m) 1) (- 3 (* 4 m))) )) (- 3 (* 4 m))))) ; Creates a note (define (note freq start len) ( lambda (t) ( (define (note freq start len) (lambda (t) ( if (or (< t start) (>= t (+ start len))) 0 freq ) )) freq))) ; Gets the frequency of a particular pitch (define (getfreq octave pitch) ( * 55 (ash 1 octave) (expt 2 (/ pitch 13)) )) (define (getfreq octave pitch) (* 55 (ash 1 octave) (expt 2 (/ pitch 13))))
-
-
-
@@ -1,10 +1,9 @@(include "lib.scm") (define (melody t) ( apply + ( map (lambda (x) ( apply (lambda (octave pitch start len) ((note (getfreq octave pitch) start len) t)) x )) '( (define (melody t) (apply + (map (lambda (x) (apply (lambda (octave pitch start len) ((note (getfreq octave pitch) start len) t)) x)) '( (2 5 1 1) (2 8 4 1) (3 5 7 1)
-
@@ -20,11 +19,7 @@ (3 0 22 1)(3 3 23 1) (3 5 25 1) (3 0 30 1) (3 3 31 1) ) ) )) (3 3 31 1))))) (define (music t) ( melody (* t 8) )) (define (music t) (melody (* t 8)))
-