diff --git a/README.md b/README.md index 085747e..d67ae49 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,7 @@ The modules: - `ambience`: looping voices `BubblingVoice`, `DrippingVoice`, `GurglingVoice`, `BouncingSpringVoice`, `RatchetVoice`, and `PatternVoice` for any repeating pattern of sounds - `alerts`: live voices `ProximityWarningVoice`, `FallingScreamVoice`, `WhistlingFallVoice`, `ChatteringVoice` +- `movement`: `jump` - `synth`: the building blocks, for making new sounds Voices make sound a block at a time, for a game with its own live mixer. To diff --git a/sfx/__init__.py b/sfx/__init__.py index cecb990..7aef85c 100644 --- a/sfx/__init__.py +++ b/sfx/__init__.py @@ -26,6 +26,7 @@ The modules: - vehicles: skids, and live voices for road surfaces and wind. - ambience: loops such as bubbling, dripping and repeating patterns. - alerts: live voices for warnings, falling screams, whistles and chattering. +- movement: a jump. Generated sounds need numpy and scipy. Nothing else in libstormgames imports this package, so a game that does not use it does not need scipy. diff --git a/sfx/movement.py b/sfx/movement.py new file mode 100644 index 0000000..d11ff7e --- /dev/null +++ b/sfx/movement.py @@ -0,0 +1,22 @@ +"""Movement sounds: jumping.""" + +import numpy as np + +from .synth import sampleRate + + +def jump(seconds=0.24, low=300.0, high=1000.0): + """A triangle tone springing straight up in pitch from low to high as it fades out. + + The tone holds full volume for its first 0.04 seconds, then fades out over + the rest along a half sine. + """ + times = np.arange(int(sampleRate * seconds)) / sampleRate + frequency = low + (high - low) * times / seconds + # Start halfway through the cycle, at the triangle's lowest point. + phases = np.cumsum(frequency) / sampleRate + 0.5 + triangle = 2.0 * np.abs(2.0 * (phases % 1.0) - 1.0) - 1.0 + fadeSeconds = min(0.2, seconds) + fade = np.clip((times - (seconds - fadeSeconds)) / fadeSeconds, 0.0, 1.0) + envelope = 0.5 * (1.0 + np.cos(np.pi * fade)) + return 0.3 * triangle * envelope diff --git a/tests/data/sfx_fingerprints.npz b/tests/data/sfx_fingerprints.npz index 04aa51c..ebca3c1 100644 Binary files a/tests/data/sfx_fingerprints.npz and b/tests/data/sfx_fingerprints.npz differ diff --git a/tests/sfx_cases.py b/tests/sfx_cases.py index 8d770a3..b417f62 100644 --- a/tests/sfx_cases.py +++ b/tests/sfx_cases.py @@ -20,6 +20,7 @@ def cases(modules): vehicles = modules["vehicles"] ambience = modules["ambience"] alerts = modules["alerts"] + movement = modules["movement"] sampleRate = synth.sampleRate blockSize = synth.blockSize @@ -175,6 +176,8 @@ def cases(modules): "alerts.whistling_fall": lambda: record(alerts.WhistlingFallVoice(1), 2.0, ramp("pitchFactor", 1.2, 0.8)), "alerts.chattering": lambda: record(alerts.ChatteringVoice(1), 2.0, ramp("pitchFactor", 1.3, 0.7)), + "movement.jump": movement.jump, + "synth.make_loop": lambda: synth.make_loop(record(ambience.BubblingVoice(3), 2.0), 0.2), "synth.join": lambda: synth.join(ui.menu_move(), vehicles.tyre_scrub_turn(1)), } diff --git a/tests/test_sfx.py b/tests/test_sfx.py index 15b3114..c347ddc 100644 --- a/tests/test_sfx.py +++ b/tests/test_sfx.py @@ -23,7 +23,7 @@ import sfx_cases # noqa: E402 libraryRoot = Path(__file__).resolve().parents[1] moduleNames = ("synth", "impacts", "ui", "rewards", "materials", "creatures", "babble", "vehicles", "ambience", - "alerts") + "alerts", "movement") def load_sfx(): diff --git a/tools/update-sfx-fingerprints.py b/tools/update-sfx-fingerprints.py index 7306b70..e55ebc8 100755 --- a/tools/update-sfx-fingerprints.py +++ b/tools/update-sfx-fingerprints.py @@ -19,7 +19,7 @@ sys.path.insert(0, str(libraryRoot / "tests")) import sfx_cases # noqa: E402 moduleNames = ("synth", "impacts", "ui", "rewards", "materials", "creatures", "babble", "vehicles", "ambience", - "alerts") + "alerts", "movement") def load_modules():