A8: Synthesized sound effects and an adaptive score
Every sound is made by scripts in tools/audio/ and committed as a WAV in assets/audio/ with a manifest of hashes and levels: - dsp.gd: seeded noise, wavetable oscillators, filters, envelopes and struck modes. recipes.gd: 50 effects (footsteps on five surfaces, a report per weapon, impacts, carpentry building and breaking, the tide's bell, foghorn, surge and lighthouse, player, ambience, menus). - score.gd: an original eight-bar tune and chords in D Dorian, 6/8, rendered as four looping layers (drone, frame drum, concertina, fiddle). - loudness.gd and check.gd: per-category loudness targets, a -1 dBFS peak ceiling and the mix order (the tide loudest). make audio and make audio-check. In the client, SoundDirector turns FX records, footsteps, building, the tide and the player's own hurts into sounds, placed on 3D voices at the event so gunfire and footsteps come from their direction. MusicDirector fades the score's layers with the tide on an AudioStreamSynchronized, full in menus. MenuSounds knocks for buttons. Closes #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
extends TestCase
|
||||
|
||||
## A8: every sound is generated by the scripts in tools/audio/, the files in
|
||||
## assets/audio/ are exactly what those scripts make, and they pass the loudness rules.
|
||||
|
||||
const Bake = preload("res://tools/audio/bake.gd")
|
||||
const Check = preload("res://tools/audio/check.gd")
|
||||
const Loudness = preload("res://tools/audio/loudness.gd")
|
||||
const Wav = preload("res://tools/audio/wav.gd")
|
||||
|
||||
|
||||
func test_the_files_pass_the_loudness_check() -> void:
|
||||
var found: Array[String] = Check.problems()
|
||||
assert_eq(found, [] as Array[String], "\n".join(found))
|
||||
|
||||
|
||||
func test_every_file_regenerates_byte_for_byte() -> void:
|
||||
var manifest: Dictionary = Bake.read_manifest()
|
||||
for sound: String in Bake.names():
|
||||
var baked: Dictionary = Bake.bake(sound)
|
||||
assert_eq(baked["entry"]["sha256"], manifest.get(sound, {}).get("sha256", ""), "%s regenerates to the committed file" % sound)
|
||||
|
||||
|
||||
func test_nothing_in_the_folder_comes_from_elsewhere() -> void:
|
||||
var names: Array[String] = Bake.names()
|
||||
for file: String in DirAccess.get_files_at(Bake.OUT_DIR):
|
||||
if file.ends_with(".import") or file == "manifest.json":
|
||||
continue
|
||||
assert_true(file.ends_with(".wav"), "%s is a generated WAV" % file)
|
||||
assert_true(names.has(file.get_basename()), "%s is made by a recipe" % file)
|
||||
|
||||
|
||||
func test_provenance_names_the_generators() -> void:
|
||||
var provenance: String = FileAccess.get_file_as_string("res://assets/PROVENANCE.md")
|
||||
for script: String in ["tools/audio/recipes.gd", "tools/audio/score.gd", "tools/audio/generate.gd"]:
|
||||
assert_true(provenance.contains(script), "PROVENANCE.md names %s" % script)
|
||||
|
||||
|
||||
func test_every_sound_loads_and_loops_only_where_it_should() -> void:
|
||||
for sound: String in Bake.names():
|
||||
var stream: AudioStreamWAV = SoundBank.stream(sound) as AudioStreamWAV
|
||||
assert_not_null(stream, "%s loads" % sound)
|
||||
if stream == null:
|
||||
continue
|
||||
assert_eq(stream.loop_mode != AudioStreamWAV.LOOP_DISABLED, Bake.loops(sound), "%s loops only if it should" % sound)
|
||||
assert_near(stream.get_length(), float(Bake.read_manifest()[sound]["seconds"]), 0.01, "%s's length" % sound)
|
||||
SoundBank.clear()
|
||||
|
||||
|
||||
func test_the_mix_puts_the_tide_on_top() -> void:
|
||||
var manifest: Dictionary = Bake.read_manifest()
|
||||
var loudest_other: float = -180.0
|
||||
var quietest_tide: float = 0.0
|
||||
for sound: String in manifest:
|
||||
var level: float = float(manifest[sound]["loudness_db"])
|
||||
if manifest[sound]["category"] == "tide":
|
||||
quietest_tide = minf(quietest_tide, level)
|
||||
else:
|
||||
loudest_other = maxf(loudest_other, level)
|
||||
assert_true(quietest_tide > loudest_other, "the foghorn, bell, surge and lighthouse are the loudest sounds")
|
||||
|
||||
|
||||
func test_the_loudness_rules_catch_bad_levels() -> void:
|
||||
assert_eq(Loudness.problems("x", -0.2, -12.0, -12.0).size(), 1, "a peak over the ceiling")
|
||||
assert_eq(Loudness.problems("x", -6.0, -9.0, -12.0).size(), 1, "too loud")
|
||||
assert_eq(Loudness.problems("x", -6.0, -16.0, -12.0).size(), 1, "too quiet without being held by the peak")
|
||||
assert_eq(Loudness.problems("x", -1.05, -14.0, -12.0).size(), 0, "held down a little by the peak ceiling")
|
||||
assert_eq(Loudness.problems("x", -3.0, -12.4, -12.0).size(), 0, "on target")
|
||||
var mix: Array[String] = Loudness.mix_problems({
|
||||
"horn": {"category": "tide", "loudness": -14.0},
|
||||
"gun": {"category": "weapon", "loudness": -13.0},
|
||||
"wind": {"category": "ambience", "loudness": -20.0},
|
||||
})
|
||||
assert_eq(mix.size(), 1, "a gun as loud as the tide is caught: %s" % [mix])
|
||||
|
||||
|
||||
func test_wav_round_trip() -> void:
|
||||
var samples: PackedFloat32Array = PackedFloat32Array([0.0, 0.5, -0.5, 1.0, -1.0])
|
||||
var bytes: PackedByteArray = Wav.encode(samples)
|
||||
assert_eq(bytes.size(), 44 + 10)
|
||||
assert_eq(Wav.rate_of(bytes), 22050)
|
||||
var back: PackedFloat32Array = Wav.decode(bytes)
|
||||
assert_eq(back.size(), 5)
|
||||
for i: int in 5:
|
||||
assert_near(back[i], samples[i], 0.0001)
|
||||
assert_eq(Wav.decode(PackedByteArray([1, 2, 3])).size(), 0, "not a WAV")
|
||||
Reference in New Issue
Block a user