diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib.scm | 3 | ||||
-rw-r--r-- | music.scm | 25 |
3 files changed, 17 insertions, 13 deletions
@@ -2,4 +2,4 @@ Lambeat is a new way to make music using functional programming. It's heavily influenced by [Bytebeat](https://dollchan.net/bytebeat) and initially started out as an reimplementation of Bytebeat in Scheme. Since then, it's grown to be a delightful new way to make music with code. ## Get started -First, install [Sox](https://sox.sourceforge.net/) and clone this repo. Write some music in `music.scm`. Enjoy your music with `guile lambeat.scm | play -r 8000 -t s16 -`! +First, install [Sox](https://sox.sourceforge.net/) and clone this repo. Write some music in `music.scm`. Enjoy your music with `guile --fresh-auto-compile lambeat.scm | play -r 8000 -t s16 -`! @@ -1,3 +1,4 @@ +; Saw wave with a period of 1 second (define (saw t) ( let ((m (floor-remainder (+ t (/ 1 4)) 1))) (if (< m 1/2) @@ -5,6 +6,7 @@ (- 3 (* 4 m))) )) +; Creates a note (define (note freq start len) ( lambda (t) ( if (or (< t start) (>= t (+ start len))) @@ -13,6 +15,7 @@ ) )) +; Gets the frequency of a particular pitch (define (getfreq octave pitch) ( * 55 (ash 1 octave) (expt 2 (/ pitch 13)) )) @@ -1,18 +1,19 @@ (include "lib.scm") -(define (melody t) (+ - ((note (getfreq 3 4) 0 1/4) t) - ((note (getfreq 3 8) 1/4 1/4) t) - ((note (getfreq 3 4) 3/4 1/4) t) - ((note (getfreq 3 11) 1 1/4) t) - ((note (getfreq 3 4) 5/4 1/4) t) - ((note (getfreq 3 2) 3/2 1/4) t) - ((note (getfreq 3 8) 7/4 1/4) t) - ((note (getfreq 3 4) 9/4 1/4) t) - ((note (getfreq 3 11) 5/2 1/4) t) - ((note (getfreq 3 4) 11/4 1/4) t) +(define (melody t) ( + apply + (map + (lambda (octave pitch start len) ((note (getfreq octave pitch) start len) t)) + ;'(3) + ;(cons (* 3 (sin t)) '()) + ;'(0) + ;'(6.28) + '(3 3 3 3 3 3 3 3 3 3) + '(4 8 4 11 4 2 8 4 11 4) + '(0 1/4 3/4 1 5/4 3/2 7/4 9/4 5/2 11/4) + '(1/4 1/4 1/4 1/4 1/4 1/4 1/4 1/4 1/4 1/4) + ) )) (define (music t) ( - melody (floor-remainder t 3) + melody (floor-remainder t 6.28) )) |