From 495b1fa59b9f8dea09692b2930af82efe27f2c17 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 6 Jan 2023 20:13:43 -0600 Subject: Compose an actual song --- example.wav | Bin 0 -> 256046 bytes lambeat.scm | 4 +-- lib.scm | 2 +- music.scm | 84 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 example.wav diff --git a/example.wav b/example.wav new file mode 100644 index 0000000..33aff17 Binary files /dev/null and b/example.wav differ diff --git a/lambeat.scm b/lambeat.scm index 1bcc730..10b08b5 100644 --- a/lambeat.scm +++ b/lambeat.scm @@ -6,7 +6,7 @@ ; Get the music as a list sampled at the bitrate (define (play t end) - (cons (* 1/4 (tri (* t (music t)))) + (cons (music t) (if (< t end) (play (+ t (/ 1 bitrate)) end) '()))) @@ -16,4 +16,4 @@ (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)) + (play 0 16)) diff --git a/lib.scm b/lib.scm index 6ce6cf8..f0f9c6a 100644 --- a/lib.scm +++ b/lib.scm @@ -14,4 +14,4 @@ ; Gets the frequency of a particular pitch (define (getfreq octave pitch) - (* 55 (ash 1 octave) (expt 2 (/ pitch 13)))) + (* 55 (ash 1 octave) (expt 2 (/ pitch 12)))) diff --git a/music.scm b/music.scm index f994c6d..51b948d 100644 --- a/music.scm +++ b/music.scm @@ -1,25 +1,75 @@ (include "lib.scm") +; https://musiclab.chromeexperiments.com/Song-Maker/song/5761928473608192 +; https://musiclab.chromeexperiments.com/Song-Maker/song/6414430911070208 (define (melody t) + (apply + (map (lambda (x) + (apply (lambda (octave pitch start len) ((note (getfreq octave pitch) start len) (- t 32))) x)) + '( + ; (2 5 0 1/4) + ; (3 0 1 1/2) + ; (2 8 3 1/4) + ; (2 7 4 1/2) + ; (2 5 6 1/4) + ; (3 1 7 1/4) + ; (3 0 8 1/4) + + ; (2 5 0 4) + ; (3 0 8 4) + ; (2 3 18 1) + ; (2 10 20 1) + ; (3 0 22 1) + ; (3 1 24 1) + ; (3 0 26 1) + ; (2 10 27 1) + ; (2 5 28 1) + ; (3 0 30 1) + ; (2 5 32 4) + ; (3 0 38 4) + ; (2 3 42 1) + ; (3 1 44 1) + ; (3 1 48 1) + ; (2 10 49 1) + ; (3 0 50 1) + ; (3 1 51 1) + ; (2 10 52 1) + ; (2 8 53 1) + ; (2 10 54 1) + ; (3 0 56 1) + ; (3 1 58 1) + ; (3 0 60 1) + ; (2 8 62 1) + (2 5 1 2) + (3 0 7 2) + (2 10 15 2) + (3 1 19 2) + (3 0 21 2) + (2 10 29 1) + (3 0 30 2) + )))) + +(define (base 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) - (3 0 9 1) - (2 10 10 1) - (2 8 12 1) - (2 7 15 1) - (2 8 17 1) - (2 7 18 1) - (3 3 19 1) - (2 8 21 1) - (3 0 22 1) - (3 3 23 1) - (3 5 25 1) - (3 0 30 1) - (3 3 31 1))))) + (1 5 1 1) + (1 8 4 1) + (2 5 7 1) + (2 0 9 1) + (1 10 10 1) + (1 8 12 1) + (1 7 15 1) + (1 8 17 1) + (1 7 18 1) + (2 3 19 1) + (1 8 21 1) + (2 0 22 1) + (2 3 23 1) + (2 5 25 1) + (2 5 29 1) + (2 0 30 1) + (2 3 31 1))))) (define (music t) - (melody (* t 8))) + (+ (* 1/2 (tri (* t (melody (floor-remainder (* t 8) 64))))) + (* 1/4 (tri (* t (base (floor-remainder (* t 8) 32))))))) -- cgit v1.2.3-70-g09d2