Reformat files to idiomatic Scheme
This commit is contained in:
parent
230494f347
commit
4f243c6f49
22
lambeat.scm
22
lambeat.scm
|
@ -5,17 +5,15 @@
|
|||
(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))
|
||||
|
|
20
lib.scm
20
lib.scm
|
@ -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))))
|
||||
|
|
19
music.scm
19
music.scm
|
@ -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 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)))
|
||||
|
|
Loading…
Reference in a new issue