aboutsummaryrefslogtreecommitdiff
path: root/beepemu2
diff options
context:
space:
mode:
authorAnthony Wang2022-12-27 18:56:11 -0600
committerAnthony Wang2022-12-27 18:56:11 -0600
commit6e7454cbe1b8e524dc2cff682596bf1e9e0b8c10 (patch)
treebf4e0d8b06d065f79e7d38e727e43f52e681c26d /beepemu2
parentaf5e81248958bf7f57f2cb56742bef96c1942e70 (diff)
Add new megalovania beep emulatorHEADmaster
Diffstat (limited to 'beepemu2')
-rwxr-xr-xbeepemu235
1 files changed, 35 insertions, 0 deletions
diff --git a/beepemu2 b/beepemu2
new file mode 100755
index 0000000..fdc10dd
--- /dev/null
+++ b/beepemu2
@@ -0,0 +1,35 @@
+#!/usr/bin/fish -c python beepemu2 | play -r 100000 -t s16 -
+import math
+import struct
+import sys
+
+def saw(t):
+ t = t % 1
+ if t < 0.25:
+ return 4*t
+ elif t < 0.75:
+ return 2-4*t
+ else:
+ return 4*t-4
+
+t,s = 0,0
+flag = ''
+flags = {}
+with open("megalovania.sh") as f:
+ for x in f.read().split():
+ if x == 'beep':
+ pass
+ elif x[0] == '-':
+ flag = x[1]
+ else:
+ flags[flag] = int(x)
+ if flag == 'l' and x != '-l':
+ t += flags['D']
+ while s < t:
+ sys.stdout.buffer.write(struct.pack('h', 0))
+ s += 1/100
+ flags['D'] = 0
+ t += flags['l']
+ while s < t:
+ sys.stdout.buffer.write(struct.pack('h', int(math.e**(-flags['f']/500)*2**14*saw(flags['f']*s/1000))))
+ s += 1/100