Changes
3 changed files (+258/-63)
-
-
@@ -3,3 +3,5 @@ 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 --fresh-auto-compile lambeat.scm | play -r 8000 -t s16 -`! For the Python version, use `pypy3 music.py | play -r 44100 -t s16 -` to listen and `pypy3 music.py | sox -r 44100 -t s16 - example.wav` to save to a file.
-
-
-
-
@@ -7,69 +7,248 @@ # Number of times to sample each secondbitrate = 44100 intro = [ (1, 3, 3), (1, 3, 7), (1, 3, 10), (3, 4, 2), (1, 3, 1), (1, 3, 5), (1, 3, 8), (3, 4, 0), (1, 2, 11), (1, 3, 3), (1, 3, 6), (2, 3, 10), (1 / 2, 3, 9, 1 / 2), (1 / 2, 3, 8, 1 / 2), (6, 3, 7, 1 / 2), (1,3,3), (1,3,7), (1,3,10), (6,4,2), (1,3,1), (1,3,5), (1,3,8), (3,4,0), (1,2,11), (1,3,3), (1,3,6), (3,3,10), (1,2,8), (1,3,0), (1,3,3), (8,3,7), ] melody = [ (3, 3, 7), (3, 3, 3), (3, 3, 8), (2, 3, 7), (2, 3, 5), (3, 3, 7), (2, 3, 3), (2, 2, 10), (2, 3, 0), (6, 3, 3), (1,3,3), (1,3,7), (1,3,10), (1,4,2), (1,4,3), (1,4,7), (2,4,8), (1,3,1), (1,3,5), (1,3,8), (1,4,0), (1,4,1), (1,4,5), (2,4,8), (1,3,3), (1,3,7), (1,3,10), (1,4,2), (1,4,3), (1,4,10), (2,4,3), (1,3,1), (1,3,5), (1,3,8), (1,4,0), (1,4,10), (1,4,8), (2,4,10), (1,3,3), (1,3,7), (1,3,10), (1,4,2), (1,4,3), (1,4,7), (2,4,8), (1,3,1), (1,3,5), (1,3,8), (1,4,0), (1,4,1), (1,4,5), (2,4,1), (1,3,3), (1,3,7), (1,3,10), (1,4,2), (1,4,3), (1,4,10), (1,4,8), (1,4,7), (1,3,1), (1,3,5), (1,3,8), (1,4,0), (1,4,10), (1,4,8), (2,4,10), ] bass = [ (1, 0, 7), (1, 2, 7), (1, 2, 7), (1, 0, 7), (1, 2, 3), (1, 2, 3), (1, 0, 7), (1, 2, 8), (1, 2, 8), (1, 0, 7), (1, 2, 7), (1, 0, 7), (1, 2, 5), (1, 0, 7), (1, 2, 7), (1, 2, 7), (1, 0, 7), (1, 2, 3), (1, 0, 7), (1, 1, 10), (1, 0, 7), (1, 2, 0), (1, 0, 7), (1, 2, 3), (1, 2, 3), (1, 0, 7), (1, 2, 3), (1, 2, 3), (1,1,3), (1,1,10), (1,1,1), (1,1,8), (1,1,3), (1,2,3), (1,1,1), (1,1,10), ] melody2 = [ (1,0,0), (1,5,10), (1,5,8), (1,5,7), (1,5,8), (3,5,7,2), (1,5,3), (1,4,10), (6,5,1,2), (1/2,5,0,2), (1/2,5,1,2), (3,5,3,2), (1/2,5,10,2), (7/2,5,3,2), (8,0,0), (1,0,0), (1,5,3), (1,5,10), (1,5,10), (4/3,5,10), (4/3,5,8), (4/3,5,7), (1,0,0), (1,5,1), (1,5,8), (1,5,8), (4/3,5,8), (4/3,5,8), (4/3,5,10), (8,0,0), (1,0,0), (5,5,3,2), (2,5,10,2), ] melody3 = [ (1,0,0), (1,5,10), (1/2,5,8,2/3), (1/2,5,7,2/3), (1/4,5,8,1/2), (1/4,5,7,1/2), (1/4,5,8,1/2), (1/4,5,7,1/2), (1,5,8), (3,5,7,2), (1,5,3), (1,4,10), (1,5,1), (5,5,7,2), (1/2,5,7), (1/2,5,10), (1/4,5,7), (1/4,5,10), (1/4,5,7), (1/4,5,10), (1,6,3), (2,5,3,2), (1/2,6,3), (5/2,5,3,2), (1/2,5,10), (1/2,5,8), (1/2,5,7), (1/2,5,8), (1/2,5,7), (1/2,5,3), (1/2,4,10), (1/2,5,1), (1/2,5,0), (1/2,4,10), (1/2,4,8), (1/2,4,10), (1/2,5,3), (1/2,5,7), (1/2,5,3), (1/2,5,10), (4/3,5,7), (4/3,6,3), (4/3,6,3), (4/3,6,2), (4/3,5,10), (4/3,5,7), (3,5,5), (2,5,7), (2,5,8), (1,6,1), (1,5,3), (1,5,5), (2,5,7), (1,5,3), (1,5,8), (2,5,10), (3/2,6,0), (3/2,6,1), (5,6,3,2), ] music = [] outro = [ (1,3,3), (1,3,7), (1,3,10), (1,4,2), (1,4,3), (1,4,7), (2,4,8), (1,3,1), (1,3,5), (1,3,8), (1,4,0), (1,4,1), (1,4,5), (2,4,8), (1,2,11), (1,3,3), (1,3,6), (1,3,10), (1.5,3,11), (1.5,4,3), (3,4,8), (1.5,2,8), (1.5,3,0), (2,3,3), (16,3,7), ] def process(notes, start, speed=1, gain=1): """
-
@@ -80,15 +259,28 @@ for note in notes:vol = 1 if len(note) == 4: vol = note[3] music.append((t, t + note[0] / speed, note[1], note[2], vol * gain)) t += note[0] / speed start = min(t, t + note[0] / speed) end = max(t, t + note[0] / speed) music.append((start, end, note[1], note[2], vol * gain)) t = end # Process all lists of notes process(intro, 0, 3) process(melody, 8, 3) process(bass, 8, 3, 1 / 2) # And sort them music = [] process(intro, 0, 4) process(melody, 8, 4) process(melody, 24, 4) process(bass, 24) process(bass, 32) process(melody, 40, 4) process(melody2, 40, 4) process(bass, 40) process(bass, 48) process(melody, 56, 4) process(melody3, 56, 4) process(bass, 56) process(bass, 64) process(outro, 72, 4) music.sort()
-
@@ -110,8 +302,9 @@ # Y = sum([math.sin(2 * i * math.pi * t * f) * math.exp(-0.0004 * 2 * math.pi * t * f) / 2**i for i in range(1, 4)])# Y += Y * Y * Y # Y *= 1 + 16 * t * math.exp(-6 * t) w = 2 * math.pi * f Y = 0.6 * math.sin(w * t) * math.exp(-0.0015 * w * t) Y += 0.4 * math.sin(2 * w * t) * math.exp(-0.0015 * w * t) Y = 0.6 * math.sin(w * t) * math.exp(-0.001 * w * t) Y += 0.2 * math.sin(2 * w * t) * math.exp(-0.001 * w * t) Y += 0.05 * math.sin(3 * w * t) * math.exp(-0.001 * w * t) Y += Y * Y * Y Y *= 1 + 16 * t * math.exp(-6 * t) return Y
-
@@ -133,5 +326,5 @@ return int(2**12 * ret)# Print out music encoded in s16 to standard output for i in range(0 * bitrate, 16 * bitrate): for i in range(0 * bitrate, 84 * bitrate): sys.stdout.buffer.write(struct.pack("h", at(i / bitrate)))
-