#!/usr/bin/env python3 """Sound effects for the FredyGames build of Circuit Artist (ours, GPL-3.0-or-later like the rest of the build). The game's own .wav files have no stated author, so the build leaves them out and synthesizes these six short blips instead (sine and triangle tones with a decay envelope). Deterministic: same bytes every run. usage: gen-sounds.py """ import math, struct, sys, wave, os RATE = 44100 def render(parts): """parts: list of (start_s, dur_s, f0, f1, shape, gain). Returns 16-bit samples.""" total = max(s + d for s, d, *_ in parts) buf = [0.0] * int(total * RATE + 1) for start, dur, f0, f1, shape, gain in parts: n = int(dur * RATE) phase = 0.0 for i in range(n): t = i / n f = f0 + (f1 - f0) * t phase += 2 * math.pi * f / RATE if shape == 'sine': v = math.sin(phase) elif shape == 'tri': v = 2 / math.pi * math.asin(math.sin(phase)) else: # square, soft v = math.copysign(1.0, math.sin(phase)) * 0.6 env = min(1.0, i / (0.004 * RATE)) * (1 - t) ** 2 buf[int(start * RATE) + i] += v * env * gain return [max(-32767, min(32767, int(round(x * 32767)))) for x in buf] def write(path, samples): with wave.open(path, 'wb') as w: w.setnchannels(1); w.setsampwidth(2); w.setframerate(RATE) w.writeframes(b''.join(struct.pack('