mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +00:00
cleanup (#764)
This commit is contained in:
1 parent
4163b31b02
commit
83ec5708ed
852 files changed
+4844
-46144
No files matched your search
@@ -22,15 +22,13 @@ FPS = 60
|
||||
ev = json.load(open(sys.argv[1] if len(sys.argv) > 1 else 'events.json'))
|
||||
OUT = sys.argv[2] if len(sys.argv) > 2 else 'droiddeck-boot-sound.wav'
|
||||
FRAMES = round(ev['DUR'] * FPS) + 1
|
||||
N = int(np.ceil(FRAMES / FPS * SR)) # exactly the video length
|
||||
N = int(np.ceil(FRAMES / FPS * SR))
|
||||
rng = np.random.default_rng(20260925)
|
||||
|
||||
# note frequencies
|
||||
def hz(n): return 440.0 * 2 ** ((n - 69) / 12)
|
||||
D2 = 440.0 * 2 ** ((38 - 69) / 12)
|
||||
D3, A3, D4, E4, Fs4, A4, B4, Cs5, D5, E5, Fs5, A5, D6 = [hz(n) for n in (50, 57, 62, 64, 66, 69, 71, 73, 74, 76, 78, 81, 86)]
|
||||
|
||||
# ------------------------------------------------------------------ building blocks
|
||||
def tt(dur): return np.arange(int(dur * SR)) / SR
|
||||
|
||||
def edge(x, a_ms=1.0, r_ms=4.0):
|
||||
@@ -70,7 +68,6 @@ def put(t0, st, gain=1.0):
|
||||
if i >= N: return
|
||||
j = min(N, i + st.shape[1]); MIX[:, i:j] += gain * st[:, :j - i]
|
||||
|
||||
# ------------------------------------------------------------------ instruments
|
||||
def wood(amp, f0=520, size=1.0, thump=0.0, dur=.35):
|
||||
"""Hard wood / toy-block clack. thump adds body for heavy landings."""
|
||||
r = [1, 1.93, 2.81, 4.13, 5.62]
|
||||
@@ -142,24 +139,19 @@ def bell(f, amp, dur=1.6):
|
||||
y = np.sin(2 * np.pi * f * t + 1.1 * np.exp(-t / .3) * np.sin(2 * np.pi * 3.5 * f * t)) * np.exp(-t / .7)
|
||||
return edge(y * amp, a_ms=2, r_ms=40)
|
||||
|
||||
# ------------------------------------------------------------------ tracks from the engine
|
||||
tr = {k: np.array(v) for k, v in ev['tr'].items()}
|
||||
TT = tr['t']; dT = TT[1] - TT[0]
|
||||
def at(name, t): return np.interp(t, TT, tr[name])
|
||||
def speed(xk, yk):
|
||||
return np.hypot(np.gradient(tr[xk], dT), np.gradient(tr[yk], dT))
|
||||
X2PAN = 1 / 330 # world units to stereo pan
|
||||
X2PAN = 1 / 330
|
||||
drops = ev['drops']; T_L = ev['T_L']; LOCK = ev['LOCK']; HOP = ev['HOP']
|
||||
events_log = []
|
||||
def log(t, what): events_log.append((round(t, 3), what))
|
||||
|
||||
# ------------------------------------------------------------------ cue sheet
|
||||
# Kept deliberately sparse: one sound per story beat, with silence between them.
|
||||
|
||||
tsamp = np.arange(N) / SR
|
||||
|
||||
# 1. the stack: each piece lands on a muted note of the final chord (D, A, A-echo, F#);
|
||||
# the lock then plays them all together
|
||||
ai = drops['archDrop']['impacts']
|
||||
put(ai[0]['t'], pan(tock(D3, .40, decay=.5, sub=.8), .1)); log(ai[0]['t'], 'legs land: D')
|
||||
|
||||
@@ -171,21 +163,18 @@ for k, imp in enumerate(bi[:2]):
|
||||
di = drops['domeDrop']['impacts']
|
||||
put(di[0]['t'], pan(tock(Fs4, .28, decay=.45, sub=.45), -.05)); log(di[0]['t'], 'bowl lands: F#')
|
||||
|
||||
# 2-3. the balancing act and the jump play in silence: the stack and the lock carry it
|
||||
|
||||
# 4. lock: one snap, then a four-note chord that rings out
|
||||
put(LOCK, pan(tock(D3, .24, decay=.28, sub=.8), 0)); log(LOCK, 'lock: soft landing in the stack voice')
|
||||
for f, a, p, off in ((D3, .24, -.1, 0), (A3, .28, .2, .02), (D4, .30, -.2, .04), (Fs4, .26, .15, .06)):
|
||||
put(LOCK + .018 + off, pan(epiano(f, a, decay=1.3 if f < 300 else 1.1), p))
|
||||
log(LOCK + .018, 'D chord')
|
||||
|
||||
# ------------------------------------------------------------------ room, master
|
||||
def room_ir(dur=1.1, rt60=.75):
|
||||
t = tt(dur); tau = rt60 / 6.9; irs = []
|
||||
for ch in range(2):
|
||||
n = rng.standard_normal(len(t))
|
||||
ir = lp(n, 7000) * np.exp(-t / (tau * .6)) * .5 + lp(n, 2200) * np.exp(-t / tau)
|
||||
ir[:int(.011 * SR)] = 0 # pre-delay
|
||||
ir[:int(.011 * SR)] = 0
|
||||
for d_ms, g in ((13, .5), (19, .35), (27, .3), (38, .2)):
|
||||
ir[int((d_ms + ch * 1.3) * SR / 1000)] += g
|
||||
irs.append(ir / np.sqrt(np.sum(ir ** 2)))
|
||||
@@ -196,13 +185,12 @@ out = MIX + .14 * wet
|
||||
out = hp(out, 28)
|
||||
fade = np.ones(N); nf = int(.45 * SR); fade[-nf:] = np.cos(np.linspace(0, np.pi / 2, nf)) ** 2
|
||||
out *= fade
|
||||
# gentle peak control: soft-knee compress only the loudest transients, then normalise
|
||||
pk = np.max(np.abs(out)); x = out / pk
|
||||
knee = .5; ax = np.abs(x); over = ax > knee
|
||||
x[over] = np.sign(x[over]) * (knee + (1 - knee) * np.tanh((ax[over] - knee) / (1 - knee)))
|
||||
L0, L1 = int((LOCK + .06) * SR), int((LOCK + .76) * SR)
|
||||
body_rms = np.sqrt(np.mean(x[:, L0:L1].mean(0) ** 2))
|
||||
out = x * (10 ** (-14.9 / 20) / body_rms) # chord body held at the level the team liked (-14.9 dB RMS)
|
||||
out = x * (10 ** (-14.9 / 20) / body_rms)
|
||||
assert np.max(np.abs(out)) < 10 ** (-1 / 20), 'would clip'
|
||||
|
||||
import wave
|
||||
|
||||
Reference in new issue
Block a user