## Checks the generated audio: every sound the source defines has a file and a manifest ## entry, every file's hash matches its entry, and every file passes the loudness rules ## in loudness.gd, measured from the file itself. Exits 1 on any problem. ## ## tools/godot.sh --script res://tools/audio/check.gd extends SceneTree const Bake = preload("res://tools/audio/bake.gd") const Wav = preload("res://tools/audio/wav.gd") const Loudness = preload("res://tools/audio/loudness.gd") static func problems() -> Array[String]: var found: Array[String] = [] var manifest: Dictionary = Bake.read_manifest() var measured: Dictionary = {} for sound: String in Bake.names(): if not manifest.has(sound): found.append("%s has no manifest entry" % sound) continue var bytes: PackedByteArray = FileAccess.get_file_as_bytes(Bake.path(sound)) if bytes.is_empty(): found.append("%s has no file at %s" % [sound, Bake.path(sound)]) continue if Bake.sha256(bytes) != String(manifest[sound]["sha256"]): found.append("%s's file doesn't match its manifest hash" % sound) var samples: PackedFloat32Array = Wav.decode(bytes) var peak: float = Loudness.peak_db(samples) var loudness: float = Loudness.loudness_db(samples, Bake.loops(sound)) found.append_array(Loudness.problems(sound, peak, loudness, Bake.target(sound))) measured[sound] = {"category": Bake.category(sound), "loudness": loudness} for sound: String in manifest: if not Bake.names().has(sound): found.append("%s is in the manifest but no recipe makes it" % sound) found.append_array(Loudness.mix_problems(measured)) return found func _init() -> void: var found: Array[String] = problems() for line: String in found: printerr(line) print("audio check: %d sounds, %d problems" % [Bake.names().size(), found.size()]) quit(1 if not found.is_empty() else 0)