A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1077 lines
44 KiB
Python
1077 lines
44 KiB
Python
"""OCEAN SWEEPERS procedural SFX generator.
|
|
|
|
Synthesises the water / rocket / machine / UI sounds for Ocean Sweepers into Assets/Audio
|
|
(WAV 44.1 kHz 16-bit, mono except waves_loop which is stereo). Reuses helpers from synth.py.
|
|
|
|
Run: python -I Tools/audio/ocean_sfx.py [name ...] (no names = render everything)
|
|
add --no-preview to skip the spectrogram PNGs in Tools/audio/ocean_preview/
|
|
|
|
Only the file names listed in SOUNDS are ever written; existing assets are never touched.
|
|
Loops are rendered with a pre-roll (filter start-up discarded) plus an extra crossfade
|
|
tail that is blended into the head (equal-power for noise, linear for periodic tonal parts),
|
|
and periodic tonal parts use frequencies with an integer number of cycles per loop.
|
|
"""
|
|
import os
|
|
import sys
|
|
import wave
|
|
|
|
import numpy as np
|
|
from scipy import signal
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, HERE) # -I drops the script dir from sys.path
|
|
import synth as S # noqa: E402 (helpers only; synth.write is never called)
|
|
|
|
SR = S.SR
|
|
ROOT = os.path.dirname(os.path.dirname(HERE))
|
|
OUT = os.path.join(ROOT, "Assets", "Audio")
|
|
PREVIEW = os.path.join(HERE, "ocean_preview")
|
|
|
|
t_axis, rng, db = S.t_axis, S.rng, S.db
|
|
bandpass, lowpass, highpass, peak = S.bandpass, S.lowpass, S.highpass, S.peak
|
|
sweep_sine, exp_env, adsr, place, reverb, soft_clip = S.sweep_sine, S.exp_env, S.adsr, S.place, S.reverb, S.soft_clip
|
|
bell, marimba, wrap_tail = S.bell, S.marimba, S.wrap_tail
|
|
|
|
|
|
# ----------------------------------------------------------------------------- helpers
|
|
|
|
def N(sec):
|
|
return int(round(sec * SR))
|
|
|
|
|
|
def rms(x):
|
|
return float(np.sqrt(np.mean(np.square(x)) + 1e-20))
|
|
|
|
|
|
def nrm(x):
|
|
"""Scale to unit RMS so mix weights below are relative RMS levels."""
|
|
return x / rms(x)
|
|
|
|
|
|
def white(n, seed):
|
|
return rng(seed).standard_normal(n)
|
|
|
|
|
|
def pink(n, seed):
|
|
X = np.fft.rfft(white(n, seed))
|
|
f = np.fft.rfftfreq(n, 1 / SR)
|
|
f[0] = f[1]
|
|
return nrm(np.fft.irfft(X / np.sqrt(f), n))
|
|
|
|
|
|
def brown(n, seed, hp=20):
|
|
return nrm(highpass(np.cumsum(white(n, seed)), hp, 2))
|
|
|
|
|
|
def smooth_rand(n, rate, seed):
|
|
"""Smooth random control signal in roughly [-1, 1] with ~`rate` Hz movement."""
|
|
r = rng(seed)
|
|
k = int(n / SR * rate) + 4
|
|
pts = r.uniform(-1, 1, k)
|
|
tp = np.linspace(0, n / SR + 2 / rate, k)
|
|
x = np.interp(np.arange(n) / SR, tp, pts)
|
|
sos = signal.butter(2, min(rate * 1.2, SR * 0.4), fs=SR, output="sos")
|
|
x = signal.sosfiltfilt(sos, x)
|
|
return x / (np.max(np.abs(x)) + 1e-9)
|
|
|
|
|
|
def svf(x, fc, q=0.707, mode="band"):
|
|
"""TPT state-variable filter with per-sample cutoff (stable under fast modulation).
|
|
band output is normalised to unity gain at the centre frequency."""
|
|
x = np.asarray(x, dtype=np.float64)
|
|
n = len(x)
|
|
fc = np.broadcast_to(np.asarray(fc, dtype=np.float64), (n,))
|
|
qq = np.broadcast_to(np.asarray(q, dtype=np.float64), (n,))
|
|
g = np.tan(np.pi * np.clip(fc, 10, SR * 0.45) / SR)
|
|
k = 1.0 / qq
|
|
a1 = 1.0 / (1.0 + g * (g + k))
|
|
a2 = g * a1
|
|
a3 = g * a2
|
|
out = np.empty(n)
|
|
ic1 = ic2 = 0.0
|
|
xs, A1, A2, A3, K = x.tolist(), a1.tolist(), a2.tolist(), a3.tolist(), k.tolist()
|
|
o = [0.0] * n
|
|
m = {"band": 0, "low": 1, "high": 2}[mode]
|
|
for i in range(n):
|
|
v0 = xs[i]
|
|
v3 = v0 - ic2
|
|
v1 = A1[i] * ic1 + A2[i] * v3
|
|
v2 = ic2 + A2[i] * ic1 + A3[i] * v3
|
|
ic1 = 2.0 * v1 - ic1
|
|
ic2 = 2.0 * v2 - ic2
|
|
if m == 0:
|
|
o[i] = K[i] * v1
|
|
elif m == 1:
|
|
o[i] = v2
|
|
else:
|
|
o[i] = v0 - K[i] * v1 - v2
|
|
out[:] = o
|
|
return out
|
|
|
|
|
|
def bubble(f0, tau, rise=1.5, amp=1.0):
|
|
"""Minnaert-style bubble: damped sine whose pitch rises as it nears the surface."""
|
|
t = t_axis(tau * 6)
|
|
f = f0 * (1 + rise * t / (tau * 3))
|
|
x = np.sin(2 * np.pi * np.cumsum(f) / SR) * np.exp(-t / tau)
|
|
a = max(1, N(0.0006))
|
|
x[:a] *= np.linspace(0, 1, a)
|
|
return x * amp
|
|
|
|
|
|
def bubbles(n, rate, fmin, fmax, seed, tau=(0.006, 0.02), rise=(0.5, 2.5), env=None, t0=0.0, t1=None):
|
|
"""Poisson field of bubbles in buffer of n samples (between t0..t1 s); env scales amplitude."""
|
|
r = rng(seed)
|
|
out = np.zeros(n)
|
|
t1 = n / SR if t1 is None else t1
|
|
count = r.poisson(rate * (t1 - t0))
|
|
for _ in range(count):
|
|
at = t0 + r.random() * (t1 - t0)
|
|
f = np.exp(np.log(fmin) + r.random() * np.log(fmax / fmin))
|
|
tu = tau[0] + r.random() * (tau[1] - tau[0])
|
|
b = bubble(f, tu, rise[0] + r.random() * (rise[1] - rise[0]), 0.25 + 0.75 * r.random() ** 2)
|
|
if env is not None:
|
|
b = b * env[min(N(at), n - 1)]
|
|
place(out, b, at)
|
|
return out
|
|
|
|
|
|
def droplets(n, rate, seed, fmin=1400, fmax=4500, t0=0.0, t1=None, env=None):
|
|
"""Tiny water drops: high bubble plinks with a little click."""
|
|
r = rng(seed)
|
|
out = np.zeros(n)
|
|
t1 = n / SR if t1 is None else t1
|
|
for _ in range(r.poisson(rate * (t1 - t0))):
|
|
at = t0 + r.random() * (t1 - t0)
|
|
f = fmin * (fmax / fmin) ** r.random()
|
|
d = bubble(f, 0.004 + 0.009 * r.random(), 1.5 + 2.5 * r.random())
|
|
k = N(0.0015)
|
|
d[:k] += highpass(r.standard_normal(k), 3000) * np.exp(-np.arange(k) / (0.0003 * SR)) * 0.4
|
|
a = 0.2 + 0.8 * r.random() ** 2
|
|
if env is not None:
|
|
a *= env[min(N(at), n - 1)]
|
|
place(out, d * a, at)
|
|
return out
|
|
|
|
|
|
def impulses(n, density, seed):
|
|
"""Random-sign impulses; density (events/s) may be an array."""
|
|
r = rng(seed)
|
|
dens = np.broadcast_to(np.asarray(density, dtype=float), (n,))
|
|
hit = r.random(n) < dens / SR
|
|
return hit * (r.random(n) ** 2) * np.sign(r.standard_normal(n))
|
|
|
|
|
|
def modes(freqs, taus, amps, dur, seed=0):
|
|
"""Struck resonant object: sum of exponentially damped sines."""
|
|
t = t_axis(dur)
|
|
r = rng(seed)
|
|
x = np.zeros_like(t)
|
|
for f, tau, a in zip(freqs, taus, amps):
|
|
f2 = f * (1 + 0.004 * (r.random() - 0.5))
|
|
x += a * np.sin(2 * np.pi * f2 * t) * np.exp(-t / tau)
|
|
k = N(0.0004)
|
|
x[:k] *= np.linspace(0, 1, k)
|
|
e = min(len(x), N(0.01))
|
|
x[-e:] *= np.linspace(1, 0, e) # no click where the render window ends
|
|
return x
|
|
|
|
|
|
def thump(f0, f1, dur, tau, curve=6, attack=0.001):
|
|
x, _ = sweep_sine(f0, f1, dur, curve=curve)
|
|
return x * exp_env(len(x), tau, attack=attack)
|
|
|
|
|
|
def click(seed, lo=2000, hi=9000, tau=0.0015, dur=0.01):
|
|
n = N(dur)
|
|
return bandpass(white(n, seed), lo, hi) * np.exp(-np.arange(n) / (tau * SR))
|
|
|
|
|
|
def mix(*parts):
|
|
"""Sum arrays of different lengths (zero-padded to the longest)."""
|
|
out = np.zeros(max(len(p) for p in parts))
|
|
for p in parts:
|
|
out[:len(p)] += p
|
|
return out
|
|
|
|
|
|
def smoothstep(x):
|
|
x = np.clip(x, 0, 1)
|
|
return x * x * (3 - 2 * x)
|
|
|
|
|
|
def env_pts(n, pts):
|
|
"""Piecewise-linear envelope from (time_s, value) points."""
|
|
tp, vp = zip(*pts)
|
|
return np.interp(np.arange(n) / SR, tp, vp)
|
|
|
|
|
|
def fit(x, dur, fout=0.03, fin=0.0005):
|
|
"""Cut/pad to exactly dur seconds with short fades so it starts and ends at zero."""
|
|
n = N(dur)
|
|
y = np.zeros(n) if x.ndim == 1 else np.zeros((n, x.shape[1]))
|
|
m = min(n, len(x))
|
|
y[:m] = x[:m]
|
|
return S.fade(y, fin, fout) if y.ndim == 1 else np.stack([S.fade(y[:, c], fin, fout) for c in range(y.shape[1])], 1)
|
|
|
|
|
|
def loopify(x, L, xf, pre=0.0, power=True):
|
|
"""x rendered with pre-roll `pre` and at least L+xf after it. The crossfade tail (the
|
|
signal's own continuation past L) is blended into the head, so sample L-1 -> 0 at the wrap
|
|
is the signal's natural next step. power=True: equal-power (uncorrelated noise),
|
|
False: linear (correlated / periodic content)."""
|
|
p, n, k = N(pre), N(L), N(xf)
|
|
y = x[p:p + n + k]
|
|
assert len(y) == n + k, "loop render too short"
|
|
out = y[:n].copy()
|
|
w = np.linspace(0.0, 1.0, k, endpoint=False)
|
|
if power:
|
|
wi, wo = np.sqrt(w), np.sqrt(1 - w)
|
|
else:
|
|
wi, wo = w, 1 - w
|
|
if y.ndim == 2:
|
|
wi, wo = wi[:, None], wo[:, None]
|
|
out[:k] = y[:k] * wi + y[n:n + k] * wo
|
|
return out
|
|
|
|
|
|
def tone_freq(f, L):
|
|
"""Snap f so that it has an integer number of cycles in L seconds."""
|
|
return round(f * L) / L
|
|
|
|
|
|
# ----------------------------------------------------------------------------- vacuum / water handling
|
|
|
|
def suck_loop():
|
|
L, xf, pre = 2.0, 0.4, 0.3
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
# airy hiss of the nozzle
|
|
hiss = nrm(bandpass(white(n, 11), 2500, 11000)) * (1 + 0.15 * smooth_rand(n, 9, 12))
|
|
# hose roar with pipe resonances, wandering centre
|
|
nz = white(n, 13)
|
|
roar = svf(nz, 750 * 2 ** (0.4 * smooth_rand(n, 3, 14)), q=1.1)
|
|
roar = nrm(roar + 0.5 * peak(nz, 430, 6) + 0.35 * peak(nz, 1180, 7))
|
|
# slurpy turbulent water: formant-ish fast-moving narrow band, choppy
|
|
chop = (0.5 + 0.5 * smooth_rand(n, 11, 16)) ** 2
|
|
slurp = nrm(svf(white(n, 15), 650 * 2 ** (0.8 * smooth_rand(n, 13, 17)), q=3.5)) * (0.25 + chop)
|
|
# gurgle bubbles being dragged up the hose
|
|
bub = bubbles(n, 38, 230, 1200, 18, tau=(0.006, 0.022), rise=(0.8, 2.8))
|
|
deep = bubbles(n, 7, 120, 260, 19, tau=(0.02, 0.04), rise=(0.5, 1.2))
|
|
rumble = nrm(lowpass(brown(n, 20), 180)) * (0.8 + 0.2 * smooth_rand(n, 4, 21))
|
|
noise_part = 0.55 * hiss + 0.9 * roar + 0.75 * nrm(slurp) + 1.6 * nrm(bub) + 0.9 * nrm(deep) + 0.6 * rumble
|
|
noise_part = lowpass(highpass(noise_part, 40), 12000)
|
|
# electric motor whine (periodic: integer cycles per loop)
|
|
f = tone_freq(212, L)
|
|
mot = lowpass(signal.sawtooth(2 * np.pi * f * t), 1400) * 0.6 + np.sin(2 * np.pi * 2 * f * t) * 0.3
|
|
mot += np.sin(2 * np.pi * tone_freq(1696, L) * t) * 0.08
|
|
loop = loopify(noise_part, L, xf, pre, True) + 0.22 * loopify(mot, L, xf, pre, False)
|
|
return soft_clip(loop / np.max(np.abs(loop)) * 1.2, 1.2)
|
|
|
|
|
|
def suck_start():
|
|
dur = 0.4
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
# rising airflow "fwoo"
|
|
fc = 260 * (2400 / 260) ** smoothstep(t / 0.28)
|
|
whoosh = svf(white(n, 31), fc, q=1.3) * env_pts(n, [(0, 0), (0.035, 0.6), (0.14, 1.0), (0.3, 0.75), (0.4, 0.7)])
|
|
x += 0.7 * whoosh
|
|
# low "oomp" with rising pitch
|
|
tt = t_axis(0.25)
|
|
f = 65 + 105 * (tt / 0.25) ** 0.6
|
|
oomp = np.sin(2 * np.pi * np.cumsum(f) / SR) * np.minimum(1, tt / 0.012) * np.exp(-tt / 0.09)
|
|
place(x, oomp * 0.9, 0.005)
|
|
# motor spin-up
|
|
fm = 212 - 160 * np.exp(-t / 0.08)
|
|
mot = lowpass(signal.sawtooth(2 * np.pi * np.cumsum(fm) / SR), 1400) * smoothstep(t / 0.2) * 0.12
|
|
x += mot
|
|
# hiss and first slurps
|
|
x += bandpass(white(n, 32), 2500, 10000) * smoothstep((t - 0.05) / 0.2) * 0.12
|
|
x += bubbles(n, 40, 250, 1100, 33, t0=0.16, t1=0.38) * 0.35
|
|
return fit(x, dur, fout=0.08)
|
|
|
|
|
|
def suck_stop():
|
|
dur = 0.5
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
fm = 50 + 162 * np.exp(-t / 0.09)
|
|
x += lowpass(signal.sawtooth(2 * np.pi * np.cumsum(fm) / SR), 1200) * np.exp(-t / 0.12) * 0.13
|
|
x += bandpass(white(n, 41), 2500, 10000) * np.exp(-t / 0.05) * 0.18
|
|
x += svf(white(n, 42), 900 * np.exp(-t / 0.15) + 200, q=1.2) * np.exp(-t / 0.07) * 0.5
|
|
# pressure release "thup"
|
|
place(x, thump(150, 70, 0.12, 0.03) * 0.6, 0.0)
|
|
# release gurgle: three falling glugs
|
|
for k, (at, f) in enumerate([(0.07, 330), (0.15, 260), (0.24, 210)]):
|
|
g = bubble(f, 0.028, 0.9) * (0.75 - 0.15 * k)
|
|
place(x, g, at)
|
|
m = N(0.06)
|
|
place(x, svf(white(m, 43 + k), f * 2.2, q=3) * np.sin(np.linspace(0, np.pi, m)) * 0.25, at - 0.01)
|
|
# drips
|
|
place(x, bubble(1150, 0.012, 3.0) * 0.45, 0.34)
|
|
place(x, bubble(1350, 0.010, 3.4) * 0.3, 0.44)
|
|
place(x, click(47, 3000, 9000) * 0.15, 0.34)
|
|
return fit(x, dur, fout=0.02)
|
|
|
|
|
|
def gulp():
|
|
dur = 0.25
|
|
n = N(dur)
|
|
x = np.zeros(n)
|
|
m = N(0.09)
|
|
tm = np.arange(m) / SR
|
|
sl = svf(white(m, 51), 550 * (1800 / 550) ** (tm / 0.09), q=3.0) * np.sin(np.pi * tm / 0.09) ** 1.5
|
|
place(x, sl * 1.0, 0.0)
|
|
# the gulp: resonant tone dropping quickly ("glk")
|
|
tt = t_axis(0.14)
|
|
f = 170 + 380 * np.exp(-tt / 0.018)
|
|
g = np.sin(2 * np.pi * np.cumsum(f) / SR) * np.minimum(1, tt / 0.002) * np.exp(-tt / 0.04)
|
|
g += 0.3 * np.sin(4 * np.pi * np.cumsum(f) / SR) * np.exp(-tt / 0.02)
|
|
place(x, g * 0.9, 0.075)
|
|
place(x, thump(140, 70, 0.1, 0.035) * 0.6, 0.08)
|
|
place(x, bubble(420, 0.02, 1.8) * 0.5, 0.11)
|
|
place(x, bubble(700, 0.012, 2.2) * 0.25, 0.15)
|
|
return fit(reverb(x, 0.06, dur=0.25, decay=0.05), dur, fout=0.03)
|
|
|
|
|
|
def tank_full():
|
|
dur = 0.6
|
|
n = N(dur)
|
|
x = np.zeros(n)
|
|
for at, f in [(0.0, 1046.5), (0.12, 1318.5)]:
|
|
tt = t_axis(0.11)
|
|
b = np.sin(2 * np.pi * f * tt) + 0.22 * np.sin(2 * np.pi * 3 * f * tt) + 0.08 * np.sin(2 * np.pi * 5 * f * tt)
|
|
b *= np.minimum(1, tt / 0.003) * np.clip((0.11 - tt) / 0.03, 0, 1) ** 1.5
|
|
place(x, b * 0.38, at)
|
|
# slosh-glug
|
|
m = N(0.34)
|
|
tm = np.arange(m) / SR
|
|
sl = svf(white(m, 61), 280 + 500 * np.sin(np.pi * tm / 0.34) ** 2, q=2.0) * np.sin(np.pi * tm / 0.34) ** 2
|
|
place(x, sl * 0.45, 0.24)
|
|
place(x, bubble(230, 0.04, 0.8) * 0.8, 0.27)
|
|
place(x, bubble(185, 0.045, 0.7) * 0.7, 0.39)
|
|
place(x, thump(110, 70, 0.15, 0.05) * 0.4, 0.265)
|
|
place(x, bubbles(N(0.3), 30, 400, 1200, 62), 0.3)
|
|
return fit(reverb(x, 0.1, dur=0.4, decay=0.1, bright=7000), dur, fout=0.05)
|
|
|
|
|
|
def pour_loop():
|
|
L, xf, pre = 1.5, 0.35, 0.3
|
|
n = N(L + xf + pre)
|
|
nz = white(n, 71)
|
|
# splattery stream: noise gated by fast random grains
|
|
gr = np.abs(smooth_rand(n, 70, 72)) ** 1.5
|
|
splat = nrm(bandpass(nz, 700, 7500)) * (0.3 + gr)
|
|
# metal funnel: impulses through narrow resonances + short comb (tube)
|
|
imp = impulses(n, 900, 73) + 0.05 * white(n, 74)
|
|
metal = sum(a * peak(imp, f, 35) for f, a in [(540, 1.0), (1270, 0.8), (2210, 0.6), (3480, 0.45), (5050, 0.3)])
|
|
D = N(0.0031)
|
|
comb = signal.lfilter([1.0], np.r_[1.0, np.zeros(D - 1), -0.55], bandpass(nz, 400, 5000))
|
|
body = nrm(lowpass(white(n, 75), 300)) * (0.8 + 0.2 * smooth_rand(n, 5, 76))
|
|
bub = bubbles(n, 34, 300, 1600, 77, tau=(0.005, 0.016))
|
|
x = 1.0 * splat + 0.45 * nrm(metal) + 0.35 * nrm(comb) + 0.5 * body + 0.9 * nrm(bub)
|
|
x = highpass(x, 60)
|
|
return loopify(x, L, xf, pre, True)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- splashes / swimming
|
|
|
|
def splash(seed, size=1.0, dur=0.6):
|
|
r = rng(seed)
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
# impact slap
|
|
k = N(0.03)
|
|
slap = lowpass(white(k, seed), 3500) * exp_env(k, 0.006 * size, attack=0.0003)
|
|
place(x, slap * 0.5, 0.0)
|
|
# cavity "plop" (rising pitch)
|
|
place(x, bubble(260 / size, 0.035 * size, 1.4) * 0.8, 0.008)
|
|
place(x, thump(130 / size ** 0.5, 55, 0.2, 0.03 * size) * 0.6 * size, 0.0)
|
|
# spray burst
|
|
spray = svf(white(n, seed + 1), 3200 * np.exp(-t / (0.4 * size)) + 1200, q=0.6)
|
|
place(x, spray * exp_env(n, 0.09 * size, attack=0.006) * 1.1, 0.004)
|
|
body = bandpass(white(n, seed + 2), 250, 2500) * exp_env(n, 0.06 * size, attack=0.004)
|
|
x += body * 0.9
|
|
# droplets falling back, decaying density
|
|
denv = np.exp(-np.maximum(t - 0.08, 0) / (0.18 * size))
|
|
x += droplets(n, 70 * size, seed + 3, 1100, 4200, 0.05, dur * 0.85, env=denv) * 0.5
|
|
x += bubbles(n, 40, 500, 1800, seed + 4, t0=0.04, t1=0.35 * size, env=denv) * 0.35
|
|
x = svf(x, 5000 + 12000 * np.exp(-t / 0.12), q=0.6, mode="low")
|
|
return reverb(x, 0.08, dur=0.4, decay=0.1, bright=8000)
|
|
|
|
|
|
def splash_small():
|
|
return fit(splash(81, 1.0, 0.6), 0.6, fout=0.08)
|
|
|
|
|
|
def splash_big():
|
|
dur = 1.4
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
# boom of a heavy body entering
|
|
place(x, thump(95, 38, 0.6, 0.14, curve=4) * 1.0, 0.0)
|
|
x += lowpass(white(n, 91), 220) * exp_env(n, 0.12, attack=0.002) * 0.9
|
|
place(x, bubble(120, 0.08, 1.6) * 0.7, 0.02)
|
|
# main crash: bright burst that darkens
|
|
crash = svf(white(n, 92), 6500 * np.exp(-t / 0.35) + 900, q=0.55, mode="low")
|
|
x += crash * env_pts(n, [(0, 0), (0.015, 1.0), (0.12, 0.8), (0.5, 0.3), (1.4, 0.0)]) ** 1.3 * 1.1
|
|
# water column falling back (second hump), splattery
|
|
gr = 0.35 + np.abs(smooth_rand(n, 60, 93)) ** 1.5
|
|
sheet = bandpass(white(n, 94), 600, 6500) * gr
|
|
x += sheet * env_pts(n, [(0, 0), (0.25, 0.1), (0.45, 0.6), (0.7, 0.45), (1.3, 0.0)]) * 0.75
|
|
denv = env_pts(n, [(0, 0.3), (0.2, 1.0), (0.6, 0.8), (1.35, 0.0)])
|
|
x += droplets(n, 90, 95, 900, 4000, 0.08, 1.3, env=denv) * 0.55
|
|
x += bubbles(n, 70, 300, 2000, 96, t0=0.05, t1=1.1, env=np.exp(-t / 0.4)) * 0.4
|
|
x = soft_clip(x / np.max(np.abs(x)) * 1.4, 1.2)
|
|
x = svf(x, 4000 + 13000 * np.exp(-t / 0.2), q=0.6, mode="low") # spray darkens as it settles
|
|
return fit(reverb(x, 0.12, dur=0.7, decay=0.18, bright=7000), dur, fout=0.15)
|
|
|
|
|
|
def swim_stroke(seed, pitch=1.0):
|
|
dur = 0.5
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
place(x, lowpass(white(N(0.02), seed), 5000) * exp_env(N(0.02), 0.004) * 0.35, 0.0)
|
|
# pull-through swish
|
|
m = N(0.32)
|
|
tm = np.arange(m) / SR
|
|
fc = pitch * (420 + 900 * np.sin(np.pi * np.minimum(tm / 0.26, 1)) ** 1.5)
|
|
sw = svf(white(m, seed + 1), fc, q=1.4) * np.sin(np.pi * tm / 0.32) ** 2
|
|
place(x, sw * 0.9, 0.01)
|
|
churn = bandpass(white(m, seed + 2), 200 * pitch, 900 * pitch) * (0.5 + 0.5 * smooth_rand(m, 25, seed + 3)) ** 2
|
|
place(x, churn * np.sin(np.pi * tm / 0.32) * 0.6, 0.03)
|
|
x += bubbles(n, 28, 320 * pitch, 1000 * pitch, seed + 4, t0=0.04, t1=0.33) * 0.4
|
|
x += droplets(n, 14, seed + 5, 1500, 3600, 0.22, 0.46, env=np.exp(-np.maximum(t - 0.25, 0) / 0.12)) * 0.35
|
|
return fit(reverb(x, 0.06, dur=0.3, decay=0.08), dur, fout=0.06)
|
|
|
|
|
|
def swim_stroke_1():
|
|
return swim_stroke(101, 1.0)
|
|
|
|
|
|
def swim_stroke_2():
|
|
return swim_stroke(111, 0.85)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- ocean ambience
|
|
|
|
def waves_loop():
|
|
L, xf, pre = 8.0, 1.5, 0.5
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
chans = []
|
|
for c in range(2):
|
|
s = 200 + 50 * c
|
|
# distant surf: pink noise with slow swells (periodic in L)
|
|
ph = 0.9 * c
|
|
sw = 0.5 + 0.25 * np.sin(2 * np.pi * 2 * t / L + ph) + 0.15 * np.sin(2 * np.pi * 3 * t / L + 1.7 + ph) \
|
|
+ 0.1 * np.sin(2 * np.pi * 5 * t / L + 0.4)
|
|
sw = np.clip(sw, 0.05, None)
|
|
surf = nrm(lowpass(highpass(pink(n, s), 60), 900)) * sw
|
|
breakhiss = nrm(bandpass(pink(n, s + 1), 1500, 6000)) * np.roll(sw, N(0.35)) ** 2
|
|
wind = nrm(svf(white(n, s + 2), 650 * 2 ** (0.6 * smooth_rand(n, 0.35, s + 3)), q=0.9)) \
|
|
* (0.6 + 0.4 * smooth_rand(n, 0.25, s + 4))
|
|
bed = 1.0 * surf + 0.35 * breakhiss + 0.18 * wind
|
|
chans.append(loopify(highpass(bed, 40), L, xf, pre, True))
|
|
bed = np.stack(chans, 1)
|
|
# lapping against floats: events folded around the loop -> seamless by construction
|
|
r = rng(260)
|
|
ev = np.zeros((N(L + 1.0), 2))
|
|
at = 0.2
|
|
k = 0
|
|
while at < L:
|
|
m = N(0.5)
|
|
tm = np.arange(m) / SR
|
|
lap = svf(white(m, 270 + k), 450 + 600 * np.exp(-tm / 0.05), q=1.4) * exp_env(m, 0.06, attack=0.012)
|
|
plok = np.zeros(m)
|
|
place(plok, bubble(170 + 220 * r.random(), 0.025 + 0.015 * r.random(), 0.9) * 0.7, 0.01)
|
|
place(plok, droplets(N(0.4), 8, 280 + k, 1200, 3000) * 0.6, 0.05)
|
|
e = lap * 0.9 + plok * 0.6
|
|
e *= 0.5 + 0.5 * r.random()
|
|
p = r.uniform(-0.8, 0.8)
|
|
a = (p + 1) * np.pi / 4
|
|
place(ev[:, 0], e * np.cos(a), at)
|
|
place(ev[:, 1], e * np.sin(a), at)
|
|
at += 0.55 + r.random() * 1.1
|
|
k += 1
|
|
ev = np.stack([wrap_tail(lowpass(ev[:, 0], 4500), L), wrap_tail(lowpass(ev[:, 1], 4500), L)], 1)
|
|
# quiet gurgles under the floats (also folded)
|
|
gl = np.zeros(N(L + 0.5))
|
|
gl += bubbles(len(gl), 3, 120, 320, 290, tau=(0.02, 0.04), rise=(0.5, 1.0))
|
|
gl = wrap_tail(gl, L)
|
|
out = bed / rms(bed) + 0.33 * ev / rms(ev) + 0.25 * np.stack([gl, gl * 0.7], 1) / rms(gl)
|
|
return out
|
|
|
|
|
|
def swell_roar():
|
|
dur = 5.0
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
tc = 3.0 # crash time
|
|
app = np.clip(t / tc, 0, 1)
|
|
# approaching rumble: darker and quieter far away, opening up as it nears
|
|
rumble = svf(brown(n, 301), 110 + 900 * app ** 2.2, q=0.7, mode="low")
|
|
rumble = nrm(rumble) * (0.08 + 0.92 * app ** 2.3) * np.where(t < tc, 1, np.exp(-(t - tc) / 0.9))
|
|
sub = nrm(lowpass(white(n, 302), 60, 4)) * (app ** 2) * np.where(t < tc, 1, np.exp(-(t - tc) / 0.6))
|
|
# rolling roar of the breaking face
|
|
roll = 0.6 + 0.4 * np.sin(2 * np.pi * np.cumsum(1.6 + 2.0 * app) / SR) ** 2
|
|
face = nrm(svf(white(n, 303), 300 + 1500 * app ** 2, q=0.8)) * app ** 3 * roll
|
|
face *= np.where(t < tc, 1, np.exp(-(t - tc) / 0.5))
|
|
x = 1.0 * rumble + 0.8 * sub + 0.55 * face
|
|
# the crash
|
|
m = n - N(tc)
|
|
tm = np.arange(m) / SR
|
|
crash = svf(white(m, 304), 8000 * np.exp(-tm / 0.5) + 1500, q=0.5, mode="low")
|
|
crash *= np.minimum(1, tm / 0.03) * np.exp(-tm / 0.55)
|
|
wash = bandpass(white(m, 305), 300, 4500) * (0.4 + np.abs(smooth_rand(m, 40, 306)) ** 1.5)
|
|
wash *= np.minimum(1, tm / 0.15) * np.exp(-tm / 0.75) * (0.75 + 0.25 * np.sin(2 * np.pi * 2.6 * tm) ** 2)
|
|
hit = np.zeros(m)
|
|
place(hit, thump(80, 32, 1.0, 0.3, curve=4), 0.0)
|
|
hit += lowpass(white(m, 307), 250) * np.minimum(1, tm / 0.01) * np.exp(-tm / 0.35)
|
|
fz_env = np.minimum(1, tm / 0.2) * np.exp(-tm / 0.7)
|
|
fizz = bandpass(white(m, 308), 3500, 11000) * (0.3 + np.abs(smooth_rand(m, 120, 309))) * fz_env
|
|
fizz += bubbles(m, 260, 900, 4500, 310, tau=(0.002, 0.007), rise=(1.5, 3.5), env=fz_env) * 3.0
|
|
cr = nrm(crash) * 1.3 + nrm(wash) * 0.8 + nrm(hit) * 0.9 + nrm(fizz) * 0.3
|
|
x[N(tc):] += cr[: n - N(tc)] * 0.9
|
|
x = soft_clip(x / np.max(np.abs(x)) * 1.5, 1.3)
|
|
x = reverb(x, 0.12, dur=1.2, decay=0.35, bright=5000)
|
|
return fit(x, dur, fout=0.3, fin=0.05)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- rockets
|
|
|
|
def rocket_countdown():
|
|
dur = 0.35
|
|
x = np.zeros(N(dur))
|
|
f = 1480.0
|
|
tt = t_axis(0.13)
|
|
b = np.sin(2 * np.pi * f * tt) + 0.25 * np.sin(2 * np.pi * 3 * f * tt) + 0.08 * np.sin(2 * np.pi * 5 * f * tt)
|
|
b += 0.15 * np.sin(2 * np.pi * f / 2 * tt)
|
|
b *= np.minimum(1, tt / 0.002) * np.clip((0.13 - tt) / 0.025, 0, 1)
|
|
place(x, b, 0.0)
|
|
return fit(reverb(x, 0.12, dur=0.3, decay=0.06, bright=9000), dur, fout=0.04)
|
|
|
|
|
|
def roar_core(n, seed):
|
|
"""Rocket exhaust: sub + rumbly low roar + crackly mid. Returns (sub, low, mid) unit-RMS."""
|
|
sub = nrm(lowpass(brown(n, seed), 85, 4))
|
|
low = nrm(lowpass(white(n, seed + 1), 380, 2)) * (0.75 + 0.25 * smooth_rand(n, 7, seed + 2))
|
|
imp = impulses(n, 140, seed + 3)
|
|
genv = signal.lfilter([1.0], [1.0, -0.996], np.abs(imp))
|
|
genv /= np.percentile(genv, 99.5) + 1e-9
|
|
mid = nrm(bandpass(white(n, seed + 4), 350, 2400) * (0.35 + np.clip(genv, 0, 1.5)))
|
|
return sub, low, mid
|
|
|
|
|
|
def rocket_launch():
|
|
dur = 7.0
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
# ignition sequence: accelerating igniter crackle + rising hiss
|
|
ign = np.clip(t / 0.5, 0, 1) * (t < 0.6)
|
|
cr = impulses(n, 40 + 900 * ign ** 2, 401) * (t < 0.62)
|
|
x += bandpass(signal.lfilter([1.0], [1.0, -0.7], cr), 1200, 7000) * 0.6
|
|
x += bandpass(white(n, 402), 1500, 6000) * smoothstep((t - 0.1) / 0.4) * (t < 0.7) * np.clip((0.7 - t) / 0.2, 0, 1) * 0.08
|
|
ti = 0.45
|
|
place(x, thump(90, 34, 1.2, 0.3, curve=4) * 0.9, ti)
|
|
place(x, lowpass(white(N(0.4), 403), 1500) * exp_env(N(0.4), 0.07, attack=0.003) * 0.7, ti)
|
|
# main roar
|
|
sub, low, mid = roar_core(n, 410)
|
|
env = smoothstep((t - ti) / 0.9) * np.where(t < 2.6, 1.0, np.exp(-(t - 2.6) / 1.5))
|
|
# distance: top end closes as it climbs away
|
|
fc = np.where(t < 1.4, 1200 + 2800 * smoothstep((t - ti) / 0.9), 4000 * np.exp(-(t - 1.4) / 2.2) + 350)
|
|
body = 1.0 * sub + 0.9 * low + 0.42 * mid
|
|
body = svf(body, fc, q=0.6, mode="low")
|
|
# sub stays longer than the highs (far rumble)
|
|
body += 0.35 * sub * np.where(t < 2.6, 0, 1 - np.exp(-(t - 2.6) / 0.8))
|
|
roar = body * env
|
|
roar = soft_clip(roar / np.max(np.abs(roar)) * 1.6, 1.4)
|
|
x = x / (np.max(np.abs(x)) + 1e-9) * 0.5 + roar
|
|
x = reverb(x, 0.15, dur=1.8, decay=0.6, bright=3500)
|
|
x = lowpass(x, 7000)
|
|
return fit(x, dur, fout=0.4)
|
|
|
|
|
|
def rocket_land():
|
|
dur = 4.0
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
tl = 2.95 # touchdown
|
|
sub, low, mid = roar_core(n, 450)
|
|
app = smoothstep(t / tl)
|
|
env = (0.12 + 0.88 * app ** 1.6) * np.where(t < tl, 1, np.exp(-(t - tl) / 0.035))
|
|
# throttle pulses of the retro thrusters
|
|
pulse = 0.82 + 0.18 * np.sin(2 * np.pi * np.cumsum(3 + 3 * app) / SR) ** 2
|
|
nozzle = nrm(svf(white(n, 455), 950 - 450 * app, q=2.0)) # descending nozzle tone
|
|
body = 1.0 * sub + 0.85 * low + 0.4 * mid + 0.3 * nozzle
|
|
body = svf(body, 700 + 3300 * app ** 1.5, q=0.6, mode="low")
|
|
roar = body * env * pulse
|
|
x = roar / np.max(np.abs(roar))
|
|
x = soft_clip(x * 1.4, 1.3) * 0.85
|
|
# touchdown clunk: heavy thump + big metal modes + leg rattle
|
|
hit = np.zeros(n)
|
|
place(hit, thump(70, 30, 1.0, 0.25, curve=4) * 1.0, tl)
|
|
place(hit, modes([182, 405, 733, 1130, 1710], [0.35, 0.25, 0.16, 0.1, 0.06], [0.6, 0.45, 0.35, 0.2, 0.12], 1.0, 460), tl + 0.004)
|
|
place(hit, lowpass(white(N(0.3), 461), 600) * exp_env(N(0.3), 0.05, attack=0.001) * 0.8, tl)
|
|
for k, dt in enumerate([0.06, 0.11, 0.19]):
|
|
place(hit, modes([1350 + 300 * k, 2900 + 200 * k], [0.03, 0.02], [0.3, 0.2], 0.12, 462 + k) * (0.35 - 0.08 * k), tl + dt)
|
|
x += hit / np.max(np.abs(hit)) * 1.0
|
|
# pressure hiss after cut
|
|
m = n - N(tl)
|
|
tm = np.arange(m) / SR
|
|
hs = svf(white(m, 470), 5000 - 1800 * np.minimum(tm / 1.0, 1), q=0.5) * np.minimum(1, tm / 0.03) * np.exp(-tm / 0.35)
|
|
place(x, hs * 0.35, tl + 0.02)
|
|
x = reverb(x, 0.12, dur=1.2, decay=0.35, bright=4000)
|
|
return fit(lowpass(x, 9000), dur, fout=0.25, fin=0.1)
|
|
|
|
|
|
def cargo_load():
|
|
dur = 0.6
|
|
n = N(dur)
|
|
x = np.zeros(n)
|
|
m = N(0.16)
|
|
tm = np.arange(m) / SR
|
|
suck = svf(white(m, 501), 2600 * (300 / 2600) ** (tm / 0.16), q=1.2) * np.sin(np.pi * tm / 0.16) ** 1.2
|
|
place(x, suck * 0.6, 0.0)
|
|
place(x, thump(150, 52, 0.25, 0.07) * 0.9, 0.05) # whump
|
|
tc = 0.2
|
|
place(x, modes([820, 1960, 3120, 4400], [0.04, 0.025, 0.015, 0.01], [0.6, 0.45, 0.3, 0.15], 0.2, 502), tc)
|
|
place(x, click(503, 1500, 8000, 0.002) * 0.7, tc)
|
|
place(x, thump(115, 60, 0.15, 0.04) * 0.8, tc)
|
|
place(x, modes([1150, 2750], [0.02, 0.012], [0.3, 0.2], 0.1, 504) * 0.5, tc + 0.045) # latch settle
|
|
m = N(0.35)
|
|
hs = bandpass(white(m, 505), 2500, 9000) * np.minimum(1, np.arange(m) / (0.01 * SR)) * exp_env(m, 0.09)
|
|
place(x, hs * 0.18, tc + 0.03)
|
|
return fit(reverb(x, 0.08, dur=0.4, decay=0.1), dur, fout=0.06)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- machines / props
|
|
|
|
def barrel_clunk():
|
|
dur = 0.4
|
|
x = np.zeros(N(dur))
|
|
place(x, thump(105, 72, 0.3, 0.07) * 0.8, 0.0)
|
|
hol = modes([178, 309, 452, 688, 1015], [0.085, 0.065, 0.045, 0.03, 0.018], [0.7, 0.5, 0.35, 0.22, 0.12], 0.35, 601)
|
|
place(x, hol, 0.0)
|
|
place(x, lowpass(bandpass(white(N(0.03), 602), 300, 3000), 2500) * exp_env(N(0.03), 0.005) * 0.6, 0.0)
|
|
# small settle bounce
|
|
place(x, mix(thump(100, 75, 0.15, 0.04) * 0.6, modes([182, 312, 455], [0.05, 0.04, 0.03], [0.5, 0.35, 0.2], 0.15, 603)) * 0.3, 0.11)
|
|
return fit(reverb(x, 0.07, dur=0.3, decay=0.07), dur, fout=0.05)
|
|
|
|
|
|
def canister_clank():
|
|
dur = 0.4
|
|
x = np.zeros(N(dur))
|
|
f1 = [612, 1497, 2384, 3275, 4410, 5930]
|
|
place(x, modes(f1, [0.22, 0.15, 0.1, 0.07, 0.05, 0.03], [0.6, 0.55, 0.4, 0.3, 0.2, 0.12], 0.4, 701), 0.0)
|
|
place(x, click(702, 2000, 10000, 0.0015) * 0.8, 0.0)
|
|
place(x, thump(170, 90, 0.08, 0.025) * 0.5, 0.0)
|
|
f2 = [f * 1.04 for f in f1[:4]]
|
|
place(x, modes(f2, [0.12, 0.08, 0.05, 0.03], [0.5, 0.45, 0.3, 0.2], 0.3, 703) * 0.4, 0.085)
|
|
place(x, click(704, 2500, 10000, 0.001) * 0.3, 0.085)
|
|
return fit(reverb(x, 0.08, dur=0.3, decay=0.08, bright=10000), dur, fout=0.05)
|
|
|
|
|
|
def ice_clink():
|
|
dur = 0.5
|
|
x = np.zeros(N(dur))
|
|
place(x, thump(120, 58, 0.25, 0.06) * 0.9, 0.0)
|
|
place(x, lowpass(white(N(0.08), 801), 650) * exp_env(N(0.08), 0.02, attack=0.0005) * 0.7, 0.0)
|
|
place(x, modes([340, 790], [0.03, 0.02], [0.4, 0.25], 0.1, 802), 0.0)
|
|
glass = modes([2650, 4230, 6120, 8350], [0.14, 0.09, 0.055, 0.03], [0.4, 0.3, 0.2, 0.12], 0.5, 803)
|
|
place(x, glass * 1.1, 0.004)
|
|
place(x, modes([3110, 5050, 7420], [0.07, 0.045, 0.025], [0.35, 0.25, 0.15], 0.3, 804) * 0.35, 0.155)
|
|
cr = impulses(N(0.1), 1500, 805) * np.exp(-np.arange(N(0.1)) / (0.025 * SR))
|
|
place(x, highpass(cr, 3000) * 0.5, 0.002)
|
|
return fit(reverb(x, 0.1, dur=0.4, decay=0.1, bright=11000), dur, fout=0.05)
|
|
|
|
|
|
def filler_fill():
|
|
dur = 1.2
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
tf = 0.93
|
|
prog = np.clip(t / tf, 0, 1)
|
|
gate = smoothstep(t / 0.04) * np.clip((tf - t) / 0.04, 0, 1)
|
|
rush = svf(white(n, 901), 330 * (2200 / 330) ** prog ** 1.2, q=4.0)
|
|
splat = lowpass(bandpass(white(n, 902), 1000, 6000), 7000) * (0.4 + np.abs(smooth_rand(n, 60, 903)) ** 1.5)
|
|
flow = lowpass(white(n, 904), 300)
|
|
bub = np.zeros(n)
|
|
r = rng(905)
|
|
for _ in range(40):
|
|
at = 0.03 + r.random() * (tf - 0.08)
|
|
p = at / tf
|
|
place(bub, bubble(300 * (1 + 3 * p) * (0.8 + 0.4 * r.random()), 0.006 + 0.01 * r.random(), 1.5) * (0.3 + 0.7 * r.random()), at)
|
|
x += (1.2 * nrm(rush) + 0.22 * nrm(splat) + 0.3 * nrm(flow) + 0.55 * nrm(bub)) * gate
|
|
x *= 0.5
|
|
# cap twist: ratchet ticks then a firm click
|
|
for k, at in enumerate([0.97, 1.0, 1.03]):
|
|
place(x, mix(click(910 + k, 2000, 7000, 0.0012), modes([2450], [0.006], [0.4], 0.03, 913)) * 0.45, at)
|
|
place(x, mix(click(914, 1500, 8000, 0.002) * 1.2, modes([1850, 3900], [0.012, 0.008], [0.6, 0.35], 0.05, 915),
|
|
thump(240, 150, 0.04, 0.01) * 0.5) * 0.8, 1.08)
|
|
return fit(reverb(x, 0.07, dur=0.3, decay=0.07), dur, fout=0.05)
|
|
|
|
|
|
def steam_hiss():
|
|
dur = 1.2
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
place(x, thump(120, 60, 0.1, 0.03) * 0.5, 0.0)
|
|
place(x, lowpass(white(N(0.06), 1001), 2200) * exp_env(N(0.06), 0.015) * 0.6, 0.0)
|
|
env = env_pts(n, [(0, 0), (0.012, 1.0), (0.25, 0.85), (1.2, 0.0)]) ** 1.6
|
|
hiss = svf(white(n, 1002), 6500 - 2800 * np.minimum(t / 1.1, 1), q=0.55) + 0.4 * highpass(white(n, 1003), 7000)
|
|
hiss = highpass(hiss, 1500) * (1 + 0.12 * smooth_rand(n, 28, 1004))
|
|
x += hiss * env * 0.75
|
|
x += droplets(n, 25, 1005, 1800, 4500, 0.0, 0.25) * 0.25 # condensate spits
|
|
return fit(reverb(x, 0.1, dur=0.5, decay=0.12), dur, fout=0.08)
|
|
|
|
|
|
def freezer_crunch():
|
|
dur = 1.0
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
th = 0.22
|
|
# hydraulic press stroke
|
|
m = N(th + 0.02)
|
|
tm = np.arange(m) / SR
|
|
fw = 170 + 110 * smoothstep(tm / th)
|
|
wh = lowpass(signal.sawtooth(2 * np.pi * np.cumsum(fw) / SR), 1100) * smoothstep(tm / 0.12) * 0.18
|
|
wh += bandpass(white(m, 1101), 800, 3500) * smoothstep(tm / th) * 0.08
|
|
place(x, wh, 0.0)
|
|
# thump
|
|
place(x, thump(78, 36, 0.6, 0.13, curve=4) * 1.0, th)
|
|
place(x, lowpass(white(N(0.2), 1102), 320) * exp_env(N(0.2), 0.05, attack=0.001) * 0.8, th)
|
|
place(x, modes([218, 515, 940], [0.09, 0.05, 0.03], [0.5, 0.3, 0.15], 0.3, 1103) * 0.6, th)
|
|
# icy crunch: dense fracture grains + a few bigger cracks
|
|
mc = N(0.45)
|
|
tc = np.arange(mc) / SR
|
|
dens = 2600 * np.exp(-tc / 0.15)
|
|
imp = impulses(mc, dens, 1104)
|
|
grains = signal.lfilter([1.0], [1.0, -0.6], imp)
|
|
crunch = bandpass(grains, 1200, 9500) * np.minimum(1, tc / 0.003)
|
|
r = rng(1105)
|
|
for k in range(10):
|
|
at = r.random() ** 1.8 * 0.3
|
|
cm = N(0.02)
|
|
crk = peak(white(cm, 1110 + k), 900 + r.random() * 3500, 3) * exp_env(cm, 0.003 + 0.004 * r.random())
|
|
place(crunch, crk * (0.6 + 0.6 * r.random()) * np.exp(-at / 0.15), at)
|
|
place(x, crunch * 1.5, th + 0.003)
|
|
for k in range(5): # crystal tinkles of shards
|
|
f = 3000 + 4000 * r.random()
|
|
place(x, modes([f, f * 1.47], [0.04, 0.025], [0.3, 0.15], 0.15, 1120 + k) * 0.25, th + 0.12 + r.random() * 0.45)
|
|
# cold release hiss
|
|
mh = N(0.35)
|
|
hs = bandpass(white(mh, 1130), 2500, 9000) * np.minimum(1, np.arange(mh) / (0.02 * SR)) * exp_env(mh, 0.1)
|
|
place(x, hs * 0.12, 0.66)
|
|
return fit(reverb(x, 0.1, dur=0.5, decay=0.12), dur, fout=0.06)
|
|
|
|
|
|
def pump_loop():
|
|
L, xf, pre = 2.0, 0.4, 0.3
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
f = tone_freq(118, L)
|
|
mot = np.sin(2 * np.pi * f * t) * 0.5 + lowpass(signal.sawtooth(2 * np.pi * f * t), 900) * 0.3 + np.sin(4 * np.pi * f * t) * 0.18
|
|
mot += np.sin(2 * np.pi * tone_freq(1416, L) * t) * 0.04 # brush whine
|
|
mot *= 1 + 0.1 * np.sin(2 * np.pi * 15 * t)
|
|
puls = 0.75 + 0.25 * np.sin(2 * np.pi * 7.5 * t) ** 2 # impeller pulsation (15 cycles / loop)
|
|
flow = nrm(bandpass(white(n, 1201), 300, 2200)) * puls
|
|
gurg = nrm(svf(white(n, 1202), 500 * 2 ** (0.7 * smooth_rand(n, 9, 1203)), q=3.0)) * (0.3 + (0.5 + 0.5 * smooth_rand(n, 8, 1204)) ** 2)
|
|
bub = nrm(bubbles(n, 18, 300, 1200, 1205))
|
|
rum = nrm(lowpass(white(n, 1206), 200))
|
|
water = highpass(0.8 * flow + 0.5 * gurg + 0.5 * bub + 0.4 * rum, 50)
|
|
return loopify(water, L, xf, pre, True) * 0.7 + 0.35 * loopify(mot, L, xf, pre, False)
|
|
|
|
|
|
def boat_loop():
|
|
L, xf, pre = 2.0, 0.4, 0.3
|
|
# putt-putt firing: 15 Hz (30 per loop), placed periodically and folded -> exactly periodic
|
|
nl = N(L)
|
|
eng = np.zeros(nl + N(0.3))
|
|
r = rng(1300)
|
|
cyc = 30
|
|
per = nl / cyc
|
|
for c in range(cyc):
|
|
m = N(0.08)
|
|
p = lowpass(r.standard_normal(m), 650) * exp_env(m, 0.011, attack=0.001)
|
|
tone = np.sin(2 * np.pi * 78 * t_axis(0.08)) * exp_env(m, 0.02, attack=0.001)
|
|
amp = 1.0 if c % 2 == 0 else 0.62
|
|
amp *= 0.9 + 0.2 * r.random()
|
|
i = int(c * per + r.integers(0, 40))
|
|
eng[i:i + m] += (p * 0.7 + tone * 0.8) * amp
|
|
eng = wrap_tail(eng, L)
|
|
t = np.arange(nl) / SR
|
|
# exhaust hum: additive band-limited saw at 30 Hz (60 cycles / loop, no filter start-up transient)
|
|
eng += sum(np.sin(2 * np.pi * 30 * h * t) / h / (1 + (30 * h / 260) ** 4) for h in range(1, 12)) * 0.12
|
|
eng = soft_clip(eng / np.max(np.abs(eng)) * 1.3, 1.2)
|
|
# mechanical rattle + water churn (noise, crossfaded)
|
|
n = N(L + xf + pre)
|
|
tn = np.arange(n) / SR
|
|
rattle = nrm(bandpass(white(n, 1301), 1500, 4500)) * (0.7 + 0.3 * np.sin(2 * np.pi * 15 * tn) ** 2)
|
|
churn = nrm(bandpass(white(n, 1302), 250, 3500)) * (0.35 + (0.5 + 0.5 * smooth_rand(n, 12, 1303)) ** 2)
|
|
wake = nrm(svf(white(n, 1304), 380 * 2 ** (0.6 * smooth_rand(n, 2, 1305)), q=1.2))
|
|
spray = nrm(bandpass(white(n, 1306), 3000, 9000))
|
|
bub = nrm(bubbles(n, 25, 250, 900, 1307))
|
|
water = highpass(0.06 * rattle + 0.55 * churn + 0.45 * wake + 0.12 * spray + 0.3 * bub, 50)
|
|
water = loopify(water, L, xf, pre, True)
|
|
return eng / rms(eng) * 1.0 + water / rms(water) * 0.55
|
|
|
|
|
|
def hover_loop():
|
|
L, xf, pre = 2.0, 0.4, 0.3
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
fb = tone_freq(168, L)
|
|
blade = sum(a * np.sin(2 * np.pi * fb * h * t + h) for h, a in [(1, 1.0), (2, 0.45), (3, 0.25), (4, 0.12)])
|
|
blade = blade * (1 + 0.15 * np.sin(2 * np.pi * 1.5 * t))
|
|
nz = white(n, 1401)
|
|
whoosh = nrm(svf(nz, 700 * 2 ** (0.5 * smooth_rand(n, 0.8, 1402)), q=0.6)) * (1 + 0.3 * np.sin(2 * np.pi * fb * t))
|
|
whoosh *= 0.85 + 0.15 * smooth_rand(n, 1.5, 1403)
|
|
sub = nrm(bandpass(white(n, 1404), 35, 130))
|
|
air = nrm(bandpass(white(n, 1405), 3000, 8500))
|
|
noise = highpass(1.0 * whoosh + 0.6 * sub + 0.15 * air, 30)
|
|
return loopify(noise, L, xf, pre, True) + 0.22 * loopify(blade, L, xf, pre, False)
|
|
|
|
|
|
def drone_water_loop():
|
|
L, xf, pre = 2.0, 0.4, 0.3
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
tonal = np.zeros(n)
|
|
for k, f in enumerate([186.0, 191.5, 198.0, 204.5]): # integer cycles per 2 s -> periodic
|
|
vib = 1.5 * np.sin(2 * np.pi * (2 + k) * t + k) # integer-cycle wobble
|
|
ph = 2 * np.pi * (f * t) + vib * 0.6
|
|
v = signal.sawtooth(ph + k * 1.3, 0.35)
|
|
tonal += lowpass(v, 1600) * (0.9 + 0.1 * np.sin(2 * np.pi * (1 + k) * t / L))
|
|
tonal = lowpass(tonal, 2200)
|
|
nz = nrm(bandpass(white(n, 1501), 250, 2400)) * (1 + 0.25 * np.sin(2 * np.pi * 191.5 * t))
|
|
mist = nrm(bandpass(white(n, 1502), 4000, 9000))
|
|
drops = nrm(droplets(n, 30, 1503, 2200, 5000))
|
|
noise = highpass(0.5 * nz + 0.12 * mist + 0.25 * drops, 60)
|
|
return 0.8 * loopify(tonal, L, xf, pre, False) / rms(tonal) + 0.45 * loopify(noise, L, xf, pre, True)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- UI / meta
|
|
|
|
def brass(f, dur, vel=1.0):
|
|
n = N(dur + 0.35)
|
|
t = np.arange(n) / SR
|
|
vib = 1 + 0.005 * np.sin(2 * np.pi * 5.5 * t) * np.clip((t - 0.15) / 0.2, 0, 1)
|
|
x = np.zeros(n)
|
|
for k, d in enumerate([-0.004, 0.0, 0.0045]):
|
|
x += signal.sawtooth(2 * np.pi * np.cumsum(f * (1 + d) * vib) / SR + k)
|
|
fc = 600 + 2800 * np.exp(-t / 0.12) + 1100 * np.minimum(t / 0.05, 1)
|
|
x = svf(x / 3, fc, q=0.9, mode="low")
|
|
env = adsr(n, 0.018, 0.12, 0.75, 0.3, hold=max(dur - 0.14, 0))
|
|
return x * env * vel
|
|
|
|
|
|
def milestone():
|
|
dur = 2.5
|
|
x = np.zeros(N(dur + 1.0))
|
|
run = [(392.0, 0.0, 0.09), (523.25, 0.1, 0.09), (659.25, 0.2, 0.09), (783.99, 0.3, 0.12)]
|
|
for f, at, ln in run:
|
|
place(x, brass(f, ln, 0.6), at)
|
|
place(x, bell(f * 2, 0.6, int(f)) * 0.12, at)
|
|
tf = 0.45
|
|
for f in [261.63, 392.0, 523.25, 659.25, 783.99, 1046.5]:
|
|
place(x, brass(f, 1.25, 0.42), tf)
|
|
place(x, thump(98, 60, 0.8, 0.25, curve=3) * 0.4, tf) # timpani-ish low hit
|
|
place(x, bandpass(white(N(1.2), 1601), 4000, 12000) * exp_env(N(1.2), 0.35, attack=0.004) * 0.12, tf)
|
|
for k, f in enumerate([1046.5, 1318.5, 1568.0, 2093.0, 2637.0]):
|
|
place(x, bell(f, 1.3, 1610 + k, 1.2) * (0.2 - 0.025 * k), tf + 0.05 + 0.06 * k)
|
|
x = reverb(x, 0.25, dur=1.6, decay=0.45, bright=8000)
|
|
x = soft_clip(x / np.max(np.abs(x)) * 1.2, 1.1)
|
|
return fit(x, dur, fout=0.5)
|
|
|
|
|
|
def stamp():
|
|
dur = 0.4
|
|
x = np.zeros(N(dur))
|
|
m = N(0.04)
|
|
place(x, svf(white(m, 1701), np.linspace(800, 2400, m), q=1.0) * np.sin(np.linspace(0, np.pi, m)) ** 2 * 0.12, 0.0)
|
|
ts = 0.035
|
|
place(x, thump(100, 52, 0.3, 0.06) * 1.0, ts)
|
|
place(x, modes([212, 385, 628, 940], [0.05, 0.035, 0.022, 0.015], [0.5, 0.4, 0.25, 0.12], 0.25, 1702), ts)
|
|
place(x, highpass(white(N(0.03), 1703), 900) * exp_env(N(0.03), 0.006) * 0.7, ts)
|
|
place(x, bandpass(white(N(0.05), 1704), 300, 1400) * exp_env(N(0.05), 0.012) * 0.6, ts)
|
|
place(x, S.crinkle(1705, 0.15, 500, 1500, 7000) * 0.06, ts + 0.02)
|
|
x = soft_clip(x / np.max(np.abs(x)) * 1.5, 1.4)
|
|
return fit(reverb(x, 0.08, dur=0.35, decay=0.08), dur, fout=0.05)
|
|
|
|
|
|
def pen_scratch_loop():
|
|
L, xf, pre = 1.0, 0.25, 0.2
|
|
n = N(L + xf + pre)
|
|
t = np.arange(n) / SR
|
|
# stroke speed: back-and-forth scribble (~7 strokes/s) with lifts
|
|
spd = np.abs(np.sin(2 * np.pi * np.cumsum(3.5 + 1.0 * smooth_rand(n, 2, 1801)) / SR)) ** 0.7
|
|
spd *= np.clip(0.6 + 0.6 * smooth_rand(n, 2.5, 1802), 0, 1)
|
|
scr = svf(white(n, 1803), 2600 + 2600 * spd, q=1.1) * spd ** 1.4
|
|
grit = highpass(signal.lfilter([1.0], [1.0, -0.5], impulses(n, 400 + 3500 * spd, 1804)), 2500) * spd
|
|
x = lowpass(highpass(nrm(scr) + 0.5 * nrm(grit), 400), 9000)
|
|
return loopify(x, L, xf, pre, True)
|
|
|
|
|
|
def paper_whoosh():
|
|
dur = 0.6
|
|
n = N(dur)
|
|
t = np.arange(n) / SR
|
|
x = np.zeros(n)
|
|
place(x, S.crinkle(1901, 0.06, 1200, 1500, 9000) * 0.5, 0.0) # flick
|
|
ffl = 30 - 14 * t / dur
|
|
fl = (0.5 + 0.5 * np.sin(2 * np.pi * np.cumsum(ffl) / SR)) ** 3
|
|
flutter = bandpass(white(n, 1902), 700, 5000) * fl
|
|
whoosh = svf(white(n, 1903), 2600 * (500 / 2600) ** (t / dur), q=1.0)
|
|
env = env_pts(n, [(0, 0), (0.06, 1.0), (0.18, 0.8), (0.6, 0.0)]) ** 1.5
|
|
x += (0.6 * flutter + 0.9 * whoosh) * env
|
|
return fit(x, dur, fout=0.08)
|
|
|
|
|
|
# ----------------------------------------------------------------------------- registry / output
|
|
|
|
# name: (render fn, kind, target) one-shot target = peak dBFS; loop target = (rms dBFS, peak ceiling dBFS)
|
|
SOUNDS = {
|
|
"suck_loop": (suck_loop, "loop", (-17, -3)),
|
|
"suck_start": (suck_start, "oneshot", -1),
|
|
"suck_stop": (suck_stop, "oneshot", -1),
|
|
"gulp": (gulp, "oneshot", -1),
|
|
"tank_full": (tank_full, "oneshot", -1),
|
|
"pour_loop": (pour_loop, "loop", (-20, -4)),
|
|
"splash_small": (splash_small, "oneshot", -1),
|
|
"splash_big": (splash_big, "oneshot", -1),
|
|
"swim_stroke_1": (swim_stroke_1, "oneshot", -1),
|
|
"swim_stroke_2": (swim_stroke_2, "oneshot", -1),
|
|
"waves_loop": (waves_loop, "loop", (-21, -4)),
|
|
"swell_roar": (swell_roar, "oneshot", -1),
|
|
"rocket_countdown": (rocket_countdown, "oneshot", -1),
|
|
"rocket_launch": (rocket_launch, "oneshot", -1),
|
|
"rocket_land": (rocket_land, "oneshot", -1),
|
|
"cargo_load": (cargo_load, "oneshot", -1),
|
|
"barrel_clunk": (barrel_clunk, "oneshot", -1),
|
|
"canister_clank": (canister_clank, "oneshot", -1),
|
|
"ice_clink": (ice_clink, "oneshot", -1),
|
|
"filler_fill": (filler_fill, "oneshot", -1),
|
|
"steam_hiss": (steam_hiss, "oneshot", -1),
|
|
"freezer_crunch": (freezer_crunch, "oneshot", -1),
|
|
"pump_loop": (pump_loop, "loop", (-20, -4)),
|
|
"boat_loop": (boat_loop, "loop", (-18, -3)),
|
|
"hover_loop": (hover_loop, "loop", (-20, -4)),
|
|
"drone_water_loop": (drone_water_loop, "loop", (-21, -4)),
|
|
"milestone": (milestone, "oneshot", -1),
|
|
"stamp": (stamp, "oneshot", -1),
|
|
"pen_scratch_loop": (pen_scratch_loop, "loop", (-22, -5)),
|
|
"paper_whoosh": (paper_whoosh, "oneshot", -1),
|
|
}
|
|
|
|
|
|
def master(x, kind, target):
|
|
x = np.asarray(x, dtype=np.float64)
|
|
x = x - x.mean(axis=0)
|
|
if kind == "oneshot":
|
|
return x * (db(target) / np.max(np.abs(x)))
|
|
r, ceil = target
|
|
x = x * (db(r) / rms(x))
|
|
pk = np.max(np.abs(x))
|
|
if pk > db(ceil):
|
|
x = x * (db(ceil) / pk)
|
|
return x
|
|
|
|
|
|
def to_int16(x):
|
|
return np.clip(np.round(x * 32767), -32768, 32767).astype(np.int16)
|
|
|
|
|
|
def write_wav(name, x):
|
|
assert name in SOUNDS
|
|
data = to_int16(x)
|
|
with wave.open(os.path.join(OUT, name + ".wav"), "wb") as w:
|
|
w.setnchannels(1 if data.ndim == 1 else 2)
|
|
w.setsampwidth(2)
|
|
w.setframerate(SR)
|
|
w.writeframes(data.tobytes())
|
|
return data
|
|
|
|
|
|
def stats(name, data, kind):
|
|
x = data.astype(np.float64) / 32768
|
|
pk = 20 * np.log10(np.max(np.abs(x)) + 1e-12)
|
|
r = 20 * np.log10(rms(x))
|
|
ch = "st" if x.ndim == 2 else "mono"
|
|
line = f" {name:18s} {len(x) / SR:5.2f}s {ch:4s} peak {pk:6.1f} dBFS rms {r:6.1f} dBFS"
|
|
if kind == "loop":
|
|
xs = x if x.ndim == 2 else x[:, None]
|
|
worst = 0.0
|
|
for c in range(xs.shape[1]):
|
|
d = np.abs(np.diff(xs[:, c]))
|
|
p99 = np.percentile(d, 99)
|
|
seam = abs(xs[0, c] - xs[-1, c])
|
|
# also compare slope continuity (2nd difference) across the wrap
|
|
wrap = np.r_[xs[-2:, c], xs[:2, c]]
|
|
curv = abs(np.diff(wrap, 2)).max()
|
|
curv99 = np.percentile(np.abs(np.diff(xs[:, c], 2)), 99)
|
|
worst = max(worst, seam / (p99 + 1e-12), curv / (curv99 + 1e-12))
|
|
line += f"\n ch{c}: seam |x[-1]-x[0]| = {seam * 32768:6.0f} lsb, median |dx| = {np.median(d) * 32768:5.0f}, p99 |dx| = {p99 * 32768:5.0f}, wrap curvature/p99 = {curv / (curv99 + 1e-12):.2f}"
|
|
line += f"\n seam {'OK' if worst < 1.0 else 'CHECK'} (worst ratio to p99 = {worst:.2f})"
|
|
# windowed RMS continuity across the wrap
|
|
m = mono(x)
|
|
w = N(0.05)
|
|
a, b = rms(m[-w:]), rms(m[:w])
|
|
line += f"; RMS last/first 50 ms = {20 * np.log10(a / b):+.1f} dB"
|
|
print(line)
|
|
|
|
|
|
def mono(x):
|
|
return x if x.ndim == 1 else x.mean(axis=1)
|
|
|
|
|
|
def spectrogram_png(name, data):
|
|
import matplotlib
|
|
matplotlib.use("Agg")
|
|
import matplotlib.pyplot as plt
|
|
x = mono(data.astype(np.float64) / 32768)
|
|
f, tt, Sx = signal.spectrogram(x, SR, nperseg=2048, noverlap=2048 - 256, window="hann")
|
|
Sdb = 10 * np.log10(Sx + 1e-14)
|
|
fig, (a0, a1) = plt.subplots(2, 1, figsize=(9, 4.8), gridspec_kw={"height_ratios": [1, 3]}, sharex=True)
|
|
tw = np.arange(len(x)) / SR
|
|
a0.plot(tw, x, lw=0.4, color="#2a6fb0")
|
|
a0.set_ylim(-1, 1)
|
|
a0.set_title(f"{name} ({len(x) / SR:.2f}s)")
|
|
mx = Sdb.max()
|
|
a1.pcolormesh(tt, f[1:], Sdb[1:], vmin=mx - 80, vmax=mx, shading="auto", cmap="magma")
|
|
a1.set_yscale("log")
|
|
a1.set_ylim(30, 20000)
|
|
a1.set_ylabel("Hz")
|
|
a1.set_xlabel("s")
|
|
a1.set_xlim(0, len(x) / SR)
|
|
fig.tight_layout()
|
|
fig.savefig(os.path.join(PREVIEW, name + ".png"), dpi=80)
|
|
plt.close(fig)
|
|
|
|
|
|
def main(argv):
|
|
preview = "--no-preview" not in argv
|
|
names = [a for a in argv if not a.startswith("--")] or list(SOUNDS)
|
|
os.makedirs(PREVIEW, exist_ok=True)
|
|
for name in names:
|
|
fn, kind, target = SOUNDS[name]
|
|
x = master(fn(), kind, target)
|
|
data = write_wav(name, x)
|
|
stats(name, data, kind)
|
|
if preview:
|
|
spectrogram_png(name, data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|