"""Cowbell clank for a friend's bell, from scratch. A real cowbell is a bent sheet: a few strong inharmonic modes, a hard metallic strike, fast decay. Writes clank.wav (and clank_soft.wav, the clapper barely touching). Claude Opus 5.5 (Tessel), 2026-10-12. Run with local/hear-venv python (numpy).""" import wave from pathlib import Path import numpy as np SR = 44100 OUT = Path(__file__).parent rng = np.random.default_rng(7) def clank(amp=1.0, dur=1.1, seed=0): t = np.arange(int(SR * dur)) / SR r = np.random.default_rng(seed) # modes (Hz, relative level, decay s): the two loud ones a bit less than a fifth apart give the "tonk" modes = [(562, 1.0, 0.42), (835, 0.75, 0.30), (1276, 0.32, 0.18), (1703, 0.22, 0.12), (2610, 0.12, 0.07), (3480, 0.07, 0.05)] y = np.zeros_like(t) for f, lv, d in modes: f = f * (1 + r.normal(0, 0.004)) # each strike slightly different beat = 1 + 0.08 * np.sin(2 * np.pi * (2.5 + r.random()) * t) # sheet metal isn't symmetric: slow beating y += lv * beat * np.exp(-t / d) * np.sin(2 * np.pi * f * t + r.random() * 6.28) # the strike: a short click of filtered noise n = r.normal(0, 1, len(t)) * np.exp(-t / 0.004) n = np.convolve(n, np.ones(6) / 6, mode="same") y += 0.6 * n # tiny attack ramp so it doesn't pop y *= np.minimum(1, t / 0.0008) y = y / np.max(np.abs(y)) * 0.8 * amp return y def write(name, y): pcm = (np.clip(y, -1, 1) * 32767).astype(np.int16) with wave.open(str(OUT / name), "wb") as w: w.setnchannels(1) w.setsampwidth(2) w.setframerate(SR) w.writeframes(pcm.tobytes()) write("clank.wav", clank(1.0, seed=1)) # soft: clapper glancing; fewer high modes, quieter s = clank(0.5, dur=0.8, seed=2) s = np.convolve(s, np.ones(4) / 4, mode="same") write("clank_soft.wav", s) print("ok")