Files
grass-cutters/Tools/audio/finalize_v2.py
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
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>
2026-11-06 18:44:40 +06:00

98 lines
4.7 KiB
Python

"""v2 sounds (gadgets, build mode, machines, sectors): picked ElevenLabs candidates → Assets/Audio.
Run after eleven_batch_v2.sh. Uses the helpers from master.py / finalize.py.
"""
import os
import numpy as np
import master as M
from finalize import compress, gate, resample_pitch, seg
from master import SR
def m(name):
return M.mono(M.raw(name))
def pop_burst(n, span, seed, jitter_pitch=0.25):
"""Rapid burst of the game's own bubble pops (pop_01..10), denser at the start."""
rng = np.random.default_rng(seed)
pops = [M.load(os.path.join(M.OUT, f"pop_{i:02d}.wav")) for i in range(1, 11)]
out = np.zeros(int((span + 0.4) * SR))
for k in range(n):
t = span * (rng.random() ** 1.8)
p = pops[rng.integers(len(pops))]
p = resample_pitch(p, 1 + (rng.random() - 0.5) * jitter_pitch)
a = int(t * SR)
g = 0.45 + 0.55 * rng.random()
out[a:a + len(p)] += p[: len(out) - a] * g
return out
def mix(a, b, gb=1.0, offset=0.0):
o = int(offset * SR)
n = max(len(a), o + len(b))
out = np.zeros(n)
out[: len(a)] += a
out[o:o + len(b)] += b * gb * np.abs(a).max() / (np.abs(b).max() + 1e-9)
return out
def single_click(x, idx=0, max_len=0.06):
s = M.slice_seq(x, max_len=max_len, min_gap=0.03, rel_db=-12)
s.sort(key=lambda p: -p[1])
return M.clean(s[idx][0], start_db=-26, tail_db=-46, max_len=max_len, fout_ms=10)
def oneshots():
M.write("build_place", M.clean(m("build_place_1.wav"), start_db=-26, tail_db=-50, max_len=0.26, fout_ms=60), -3)
M.write("build_remove", M.clean(m("build_remove_0.wav"), start_db=-26, tail_db=-50, max_len=0.32, fout_ms=80), -3)
M.write("build_rotate", single_click(m("build_rotate_1.wav"), 0, 0.07), -8)
M.write("vac_suck", M.clean(m("vac_suck_0.wav"), start_db=-30, tail_db=-46, max_len=0.45, fout_ms=40), -5)
M.write("vac_shoot", M.clean(m("vac_shoot_0.wav"), start_db=-30, tail_db=-48, max_len=0.42, fout_ms=60), -3)
M.write("bomb_throw", M.clean(m("bomb_throw_0.wav"), start_db=-36, tail_db=-46, max_len=0.25, lead_ms=0, fout_ms=40), -6)
M.write("bomb_fuse", M.clean(m("bomb_fuse_1.wav"), start_db=-30, tail_db=-40, max_len=0.85, fout_ms=150), -9)
boom = M.clean(m("bomb_boom_0.wav"), start_db=-30, tail_db=-50, max_len=1.4, fout_ms=250)
boom = mix(boom, pop_burst(70, 0.55, 7), 0.8, 0.005)
M.write("bomb_boom", np.tanh(boom / np.abs(boom).max() * 1.4), -1.5)
M.write("opener_saw", M.clean(m("opener_saw_0.wav"), start_db=-30, tail_db=-46, max_len=0.8, fout_ms=150), -8)
thunk = M.clean(seg(m("press_squash_0.wav"), 0.0, 0.5), start_db=-30, tail_db=-50, max_len=0.45, fout_ms=80)
press = mix(thunk, pop_burst(30, 0.4, 11), 0.75, 0.07)
M.write("press_squash", M.fade(np.tanh(press / np.abs(press).max() * 1.3), 0, 60), -2.5)
crunch = compress(M.clean(m("compactor_crunch_1.wav"), start_db=-30, tail_db=-50, max_len=1.0, fout_ms=150), -24, 5)
M.write("compactor_crunch", np.tanh(crunch / np.abs(crunch).max() * 2.0), -3)
shutter = compress(M.clean(m("gate_shutter_0.wav"), start_db=-34, tail_db=-46, max_len=2.1, fout_ms=300), -18, 4)
M.write("gate_shutter", shutter, -4)
M.write("gate_unlock", M.clean(m("gate_unlock_0.wav"), start_db=-30, tail_db=-55, max_len=1.7, fout_ms=300), -2.5)
M.write("perk_unlock", M.clean(m("perk_unlock_1.wav"), start_db=-30, tail_db=-55, max_len=1.2, fout_ms=300), -3)
M.write("giant_roll_creak", M.clean(m("giant_roll_creak_1.wav"), start_db=-34, tail_db=-46, max_len=1.5, fout_ms=250), -4)
# double honk from one long honk
h = M.clean(m("truck_horn_1.wav"), start_db=-30, tail_db=-50, max_len=0.5, fout_ms=40)
first = M.fade(h[: int(0.18 * SR)], 1, 30)
second = M.fade(h[: int(0.34 * SR)], 1, 60)
horn = np.zeros(int(0.26 * SR) + len(second))
horn[: len(first)] += first
horn[int(0.26 * SR):] += second
M.write("truck_horn", horn, -9)
M.write("sector_clear", M.clean(M.raw("sector_clear_0.wav"), start_db=-36, tail_db=-55, max_len=2.6, fout_ms=400), -4) # stereo UI jingle
def loops():
bl = M.highpass(m("blower_loop_0.wav"), 60)
M.write("blower_loop", M.loop_xfade(seg(bl, 0.5, 4.75), 0.8), -8)
vac = M.highpass(m("vac_loop_0.wav"), 50)
M.write("vac_loop", M.loop_xfade(seg(vac, 0.35, 3.95), 0.5), -11)
hum = M.highpass(m("machine_hum_0.wav"), 40)
M.write("machine_hum_loop", M.loop_xfade(seg(hum, 0.2, 5.8), 0.6), -14)
rr = compress(M.highpass(m("roll_rumble_1.wav"), 30), -22, 5)
rng = np.random.default_rng(3)
rum = M.lowpass(M.lowpass(rng.standard_normal(len(rr)), 90), 90) # low body under the crackle
rr = rr + rum * 0.5 * np.abs(rr).max() / (np.abs(rum).max() + 1e-9)
M.write("roll_rumble_loop", M.loop_xfade(seg(rr, 0.4, 6.4), 0.6), -10)
if __name__ == "__main__":
oneshots()
loops()