#!/usr/bin/env python3 """Generates exit.wav for the FredyGames build of Dave Gnukem. The original data/sounds/exit.ogg is a track by Eric Matyas (soundimage.org), whose terms are not in the game's repository, so this build leaves it out and plays this sound instead: a short rising arpeggio made from square waves. It is original to the FredyGames build and released under CC0 1.0 (public domain). python3 -I make-exit-sound.py Output is deterministic: 16-bit mono PCM, 22050 Hz. """ import math import struct import sys import wave RATE = 22050 NOTES = [(523.25, 0.09), (659.25, 0.09), (783.99, 0.09), (1046.5, 0.09), (1318.5, 0.28)] def main(path): out = [] for freq, length in NOTES: n = int(RATE * length) for i in range(n): t = i / RATE sq = 1.0 if math.sin(2 * math.pi * freq * t) >= 0 else -1.0 env = min(1.0, t / 0.004) * math.exp(-t * 6) * min(1.0, (n - i) / (RATE * 0.01)) out.append(0.35 * sq * env) with wave.open(path, "wb") as w: w.setnchannels(1) w.setsampwidth(2) w.setframerate(RATE) w.writeframes(b"".join(struct.pack("