"""Pop sound packs for Settings > Pop sound: popk__.wav in Assets/Audio. Sources are eleven_raw/pk__{0,1}.wav (see eleven_batch_popsounds.sh); "retro" is synthesized here. "Classic" is the original pop_01..pop_10 set and isn't touched. Every pack ends up with four variants: the strongest transients of both candidates, topped up with pitch-shifted copies. """ import numpy as np from scipy import signal import master as M from master import SR SEQ = {"crisp": 0.25, "chunky": 0.32, "balloon": 0.3, "cork": 0.35, "bloop": 0.22, "mouth": 0.25} SINGLE = {"pew": 0.35, "duck": 0.42, "boing": 0.55, "bonk": 0.38, "meow": 0.65, "toot": 0.45, "boom": 1.3} VARIANTS = 4 def pitch(x, factor): return M.fade(signal.resample(x, int(len(x) / factor)), 0, 12) def top_up(clips): shifts = [1.08, 0.92, 1.15, 0.86] k = 0 base = list(clips) while len(clips) < VARIANTS: clips.append(pitch(base[k % len(base)], shifts[k % len(shifts)])) k += 1 return clips[:VARIANTS] def seq_pack(name, max_len): pieces = [] for k in (0, 1): x = M.mono(M.raw(f"pk_{name}_{k}.wav")) segs = M.slice_seq(x, max_len=max_len + 0.1, min_gap=0.12, rel_db=-24) top = max(pk for _, pk, _ in segs) pieces += [(pk / top, s) for s, pk, _ in segs if pk > top * M.db(-12)] pieces.sort(key=lambda p: -p[0]) return [M.clean(s, start_db=-26, tail_db=-46, max_len=max_len) for _, s in pieces[:VARIANTS]] def single_pack(name, max_len): out = [] for k in (0, 1): x = M.mono(M.raw(f"pk_{name}_{k}.wav")) out.append(M.clean(x, start_db=-26, tail_db=-50, max_len=max_len, fout_ms=min(250, max_len * 300))) return out def boom(clips): """The raw booms are almost pure sub-bass (inaudible on laptop speakers): saturate them for harmonics and add a hit transient.""" out = [] for i, x in enumerate(clips): x = pitch(x, 1.25 + 0.2 * i) # lift the fundamental out of the sub range x = x / (np.abs(x).max() + 1e-9) sat = np.tanh(x * 5.0) n = int(0.025 * SR) hit = np.random.default_rng(i).normal(0, 1, n) * np.exp(-np.arange(n) / SR * 160) y = sat * 0.8 + x * 0.4 y[:n] += M.lowpass(hit, 3000) * 0.6 out.append(M.fade(M.highpass(y, 45), 0.5, 300)) return out def retro(): """Square-wave chiptune blips with a quick downward pitch sweep.""" out = [] for f0 in (880, 988, 1175, 1319): n = int(0.11 * SR) t = np.arange(n) / SR f = f0 * np.exp(-t * 9) ph = 2 * np.pi * np.cumsum(f) / SR x = np.sign(np.sin(ph)) * 0.5 + np.sign(np.sin(ph * 2)) * 0.12 x *= np.exp(-t * 26) out.append(M.fade(M.lowpass(x, 7000), 0.5, 20)) return out def main(): packs = {} for name, ml in SEQ.items(): packs[name] = top_up(seq_pack(name, ml)) for name, ml in SINGLE.items(): packs[name] = top_up(single_pack(name, ml)) packs["boom"] = boom(packs["boom"]) packs["retro"] = retro() for name, clips in packs.items(): print(name) for i, c in enumerate(clips): M.write(f"popk_{name}_{i + 1}", c, -3 if name in SEQ else -5) if __name__ == "__main__": main()