Generated sound effects, made from code instead of sound files
libstormgames.sfx makes sound effects with numpy and scipy, so a game can use them without shipping sound files, and every game that asks for the same sound with the same seed gets exactly the same samples. The sounds come from Grave Racer and match it sample for sample. The modules are synth (waves, filters, envelopes, loops), impacts, ui, rewards, materials, creatures, babble, vehicles, ambience and alerts. sfx.make_sound turns a sound into a pygame Sound for the mixer as it is set up, turning down only a sound that would go past full scale. sfx.add_sounds adds generated sounds by name, keeping any sound file of the same name. The menus' menu-move and menu-select sounds are generated when a game has no file for them. sfx and scipy are only imported then, so a game that ships both files, or never uses sfx, is not slowed down or made to need scipy. The tests check every sound against a stored fingerprint, so none can change by accident; tools/update-sfx-fingerprints.py remakes them after a deliberate change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31e7472fd1
commit
f164697cf6
19 files changed
+2084
No files matched your search
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Remake tests/data/sfx_fingerprints.npz from the sounds the library makes now.
|
||||
|
||||
Run this only after listening to a sound that was changed on purpose, since it
|
||||
makes the tests accept whatever the generators make now. From the library root:
|
||||
|
||||
python tools/update-sfx-fingerprints.py
|
||||
"""
|
||||
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
import numpy as np
|
||||
|
||||
libraryRoot = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(libraryRoot / "tests"))
|
||||
import sfx_cases # noqa: E402
|
||||
|
||||
moduleNames = ("synth", "impacts", "ui", "rewards", "materials", "creatures", "babble", "vehicles", "ambience",
|
||||
"alerts")
|
||||
|
||||
|
||||
def load_modules():
|
||||
packageName = "_sfx_fingerprint_library"
|
||||
package = ModuleType(packageName)
|
||||
package.__path__ = [str(libraryRoot)]
|
||||
sys.modules[packageName] = package
|
||||
return {name: importlib.import_module(f"{packageName}.sfx.{name}") for name in moduleNames}
|
||||
|
||||
|
||||
def main():
|
||||
cases = sfx_cases.cases(load_modules())
|
||||
prints = {name: sfx_cases.fingerprint(make()) for name, make in cases.items()}
|
||||
outputPath = libraryRoot / "tests" / "data" / "sfx_fingerprints.npz"
|
||||
np.savez_compressed(outputPath, **prints)
|
||||
print(f"Wrote fingerprints of {len(prints)} sounds to {outputPath}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user