aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--lib.scm3
-rw-r--r--music.scm25
3 files changed, 17 insertions, 13 deletions
diff --git a/README.md b/README.md
index 035afd2..f9bb795 100644
--- a/README.md
+++ b/README.md
@@ -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 -`!
diff --git a/lib.scm b/lib.scm
index 66d2a0e..6c86521 100644
--- a/lib.scm
+++ b/lib.scm
@@ -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))
))
diff --git a/music.scm b/music.scm
index a45111f..1098ab3 100644
--- a/music.scm
+++ b/music.scm
@@ -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)
))