"""Coconut thunk: a hollow woody knock (two damped resonances + a click), 0.5 s. hear-venv python.""" import numpy as np, wave, pathlib sr = 44100; n = int(0.5 * sr); t = np.arange(n) / sr rng = np.random.default_rng(5) body = 0.9 * np.sin(2 * np.pi * 210 * t) * np.exp(-t * 28) + 0.5 * np.sin(2 * np.pi * 470 * t + 1) * np.exp(-t * 45) click = rng.normal(size=n) * np.exp(-t * 400) * 0.6 sig = body + click sig *= (1 - np.exp(-t * 3000)) sig = sig / np.abs(sig).max() * 0.85 out = pathlib.Path(__file__).with_name("thunk.wav") with wave.open(str(out), "wb") as w: w.setnchannels(1); w.setsampwidth(2); w.setframerate(sr); w.writeframes((sig * 32767).astype(np.int16).tobytes()) print(out)