24 lines
935 B
Python
24 lines
935 B
Python
"""Original fictional distant hum; no sampled real-world attacks."""
|
|
from pathlib import Path
|
|
import math
|
|
import json
|
|
import struct
|
|
import wave
|
|
|
|
target = Path(__file__).resolve().parents[1] / "do-otboy/assets/audio/approach.wav"
|
|
story = json.loads((target.parents[2] / "data/phone_story.json").read_text(encoding="utf-8"))
|
|
duration = story["timeline"]["impact"] - story["timeline"]["hum"]
|
|
rate = 22050
|
|
samples = []
|
|
for i in range(round(rate * duration)):
|
|
t = i / rate
|
|
envelope = min(1, t / 2) * min(1, (duration - t) / .3)
|
|
signal = .22 * math.sin(2 * math.pi * (68 * t + .6 * t * t))
|
|
signal += .08 * math.sin(2 * math.pi * 137 * t)
|
|
signal += .03 * math.sin(2 * math.pi * 281 * t)
|
|
samples.append(struct.pack("<h", int(signal * envelope * 32767)))
|
|
with wave.open(str(target), "wb") as output:
|
|
output.setparams((1, 2, rate, 0, "NONE", "not compressed"))
|
|
output.writeframes(b"".join(samples))
|
|
print(target)
|