"""Original synthesized SFX. No samples or third-party audio. Reproducible PCM.""" from pathlib import Path import math, random, struct, wave, json ROOT = Path(__file__).resolve().parents[1] OUT = ROOT / 'assets/audio' RATE = 24000 def create(name, duration, tones=(), noise=0.0, decay=8, sweep=0.0): rng = random.Random(name) values = [] low = 0.0 for i in range(round(RATE * duration)): t = i / RATE env = min(1, t/.006) * min(1, (duration-t)/.035) * math.exp(-decay*t/duration) low = .72*low + .28*rng.uniform(-1,1) sample = noise * low for hz, weight, delay in tones: tt = max(0,t-delay) if t >= delay: sample += weight * math.sin(2*math.pi*(hz*tt+sweep*tt*tt)) * math.exp(-2*tt/duration) values.append(sample*env) peak = max(abs(x) for x in values) or 1 pcm = b''.join(struct.pack('