aboutsummaryrefslogtreecommitdiff
path: root/music.nim
diff options
context:
space:
mode:
Diffstat (limited to 'music.nim')
-rw-r--r--music.nim273
1 files changed, 273 insertions, 0 deletions
diff --git a/music.nim b/music.nim
new file mode 100644
index 0000000..0ad3e3f
--- /dev/null
+++ b/music.nim
@@ -0,0 +1,273 @@
+import musiclib
+
+# Number of times to sample each second
+let bitrate = 44100
+
+let intro = [
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(6,4,2),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(3,4,0),
+
+ n(1,2,11),
+ n(1,3,3),
+ n(1,3,6),
+ n(3,3,10),
+
+ n(1,2,8),
+ n(1,3,0),
+ n(1,3,3),
+ n(8,3,7),
+]
+
+let melody = [
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(1,4,2),
+ n(1,4,3),
+ n(1,4,7),
+ n(2,4,8),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(1,4,0),
+ n(1,4,1),
+ n(1,4,5),
+ n(2,4,8),
+
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(1,4,2),
+ n(1,4,3),
+ n(1,4,10),
+ n(2,4,3),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(1,4,0),
+ n(1,4,10),
+ n(1,4,8),
+ n(2,4,10),
+
+
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(1,4,2),
+ n(1,4,3),
+ n(1,4,7),
+ n(2,4,8),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(1,4,0),
+ n(1,4,1),
+ n(1,4,5),
+ n(2,4,1),
+
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(1,4,2),
+ n(1,4,3),
+ n(1,4,10),
+ n(1,4,8),
+ n(1,4,7),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(1,4,0),
+ n(1,4,10),
+ n(1,4,8),
+ n(2,4,10),
+]
+
+let bass = [
+ n(1,1,3),
+ n(1,1,10),
+ n(1,1,1),
+ n(1,1,8),
+ n(1,1,3),
+ n(1,2,3),
+ n(1,1,1),
+ n(1,1,10),
+]
+
+let melody2 = [
+ n(1,0,0),
+ n(1,5,10),
+ n(1,5,8),
+ n(1,5,7),
+ n(1,5,8),
+ n(3,5,7,2),
+
+ n(1,5,3),
+ n(1,4,10),
+ n(6,5,1,2),
+
+ n(1/2,5,0,2),
+ n(1/2,5,1,2),
+ n(3,5,3,2),
+ n(1/2,5,10,2),
+ n(7/2,5,3,2),
+
+ n(8,0,0),
+
+ n(1,0,0),
+ n(1,5,3),
+ n(1,5,10),
+ n(1,5,10),
+ n(4/3,5,10),
+ n(4/3,5,8),
+ n(4/3,5,7),
+
+ n(1,0,0),
+ n(1,5,1),
+ n(1,5,8),
+ n(1,5,8),
+ n(4/3,5,8),
+ n(4/3,5,8),
+ n(4/3,5,10),
+
+ n(8,0,0),
+
+ n(1,0,0),
+ n(5,5,3,2),
+ n(2,5,10,2),
+]
+
+let melody3 = [
+ n(1,0,0),
+ n(1,5,10),
+ n(1/2,5,8,2/3),
+ n(1/2,5,7,2/3),
+ n(1/4,5,8,1/2),
+ n(1/4,5,7,1/2),
+ n(1/4,5,8,1/2),
+ n(1/4,5,7,1/2),
+ n(1,5,8),
+ n(3,5,7,2),
+
+ n(1,5,3),
+ n(1,4,10),
+ n(1,5,1),
+ n(5,5,7,2),
+
+ n(1/2,5,7),
+ n(1/2,5,10),
+ n(1/4,5,7),
+ n(1/4,5,10),
+ n(1/4,5,7),
+ n(1/4,5,10),
+ n(1,6,3),
+ n(2,5,3,2),
+ n(1/2,6,3),
+ n(5/2,5,3,2),
+
+ n(1/2,5,10),
+ n(1/2,5,8),
+ n(1/2,5,7),
+ n(1/2,5,8),
+ n(1/2,5,7),
+ n(1/2,5,3),
+ n(1/2,4,10),
+ n(1/2,5,1),
+ n(1/2,5,0),
+ n(1/2,4,10),
+ n(1/2,4,8),
+ n(1/2,4,10),
+ n(1/2,5,3),
+ n(1/2,5,7),
+ n(1/2,5,3),
+ n(1/2,5,10),
+
+ n(4/3,5,7),
+ n(4/3,6,3),
+ n(4/3,6,3),
+ n(4/3,6,2),
+ n(4/3,5,10),
+ n(4/3,5,7),
+
+ n(3,5,5),
+ n(2,5,7),
+ n(2,5,8),
+ n(1,6,1),
+
+ n(1,5,3),
+ n(1,5,5),
+ n(2,5,7),
+ n(1,5,3),
+ n(1,5,8),
+ n(2,5,10),
+
+ n(3/2,6,0),
+ n(3/2,6,1),
+ n(5,6,3,2),
+]
+
+let outro = [
+ n(1,3,3),
+ n(1,3,7),
+ n(1,3,10),
+ n(1,4,2),
+ n(1,4,3),
+ n(1,4,7),
+ n(2,4,8),
+
+ n(1,3,1),
+ n(1,3,5),
+ n(1,3,8),
+ n(1,4,0),
+ n(1,4,1),
+ n(1,4,5),
+ n(2,4,8),
+
+ n(1,2,11),
+ n(1,3,3),
+ n(1,3,6),
+ n(1,3,10),
+ n(1.5,3,11),
+ n(1.5,4,3),
+ n(3,4,8),
+
+ n(1.5,2,8),
+ n(1.5,3,0),
+ n(2,3,3),
+ n(16,3,7,2),
+]
+
+from std/algorithm import sort
+
+# Process all lists of notes
+var music: seq[ProcessedNote] = @[]
+music.process(intro, 0, 4)
+music.process(melody, 8, 4)
+music.process(melody, 24, 4)
+music.process(bass, 24, gain=1.5)
+music.process(bass, 32, gain=1.5)
+music.process(melody, 40, 4)
+music.process(melody2, 40, 4)
+music.process(bass, 40, gain=1.5)
+music.process(bass, 48, gain=1.5)
+music.process(melody, 56, 4)
+music.process(melody3, 56, 4)
+music.process(bass, 56, gain=1.5)
+music.process(bass, 64, gain=1.5)
+music.process(outro, 72, 4)
+music.sort()
+
+# Print out music encoded in s16 to standard output
+for i in (0 * bitrate ..< 84 * bitrate):
+ let bytes = cast[array[4, uint8]](music.at(i / bitrate))
+ doAssert 4 == stdout.writeBytes(bytes, 0, 4)