82 lines
3.3 KiB
GDScript
82 lines
3.3 KiB
GDScript
extends SceneTree
|
|
|
|
var failures := 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
func _check(ok: bool, detail: String) -> void:
|
|
if not ok:
|
|
failures += 1
|
|
printerr("FAIL: " + detail)
|
|
|
|
func _run() -> void:
|
|
_check(AssetRoot.pack_ready(), "40250 pack unavailable")
|
|
var driver: Node = preload("res://audio_driver.gd").new()
|
|
root.add_child(driver)
|
|
var sound := "sound/ambience/waterfall.wav"
|
|
var path: String = driver._find_sound(sound)
|
|
_check(path == "pack://" + sound, "sound must resolve through 40250 pack")
|
|
var stream: AudioStream = driver._load_stream(path)
|
|
_check(stream != null, "packed WAV must decode")
|
|
if stream != null:
|
|
driver.set_sound_volume(0.5)
|
|
driver.play_sound_2d(sound, 0.5)
|
|
var player: AudioStreamPlayer = driver._ui_pool[0]
|
|
_check(absf(player.volume_db - linear_to_db(0.5)) < 0.01,
|
|
"sound volume was applied more than once")
|
|
driver.play_sound_3d(sound, Vector3.ZERO, 0.5)
|
|
_check(driver._all_3d.size() == 1, "3D sound not tracked")
|
|
driver.play_sound_3d(sound, Vector3.ZERO, 0.5, 17, 0)
|
|
driver.set_sound_volume_3d(17, 0.25)
|
|
_check(absf(driver._active_3d[17].volume_db - linear_to_db(0.25)) < 0.01,
|
|
"indexed 3D sound volume did not update")
|
|
_check(driver._all_3d.size() == 2, "looping 3D sound not tracked")
|
|
driver._active_3d[17].finished.emit()
|
|
_check(driver._active_3d.has(17), "zero-loop-count ambience did not restart")
|
|
driver.play_sound_3d(sound, Vector3.ZERO, 0.5, 18, 2)
|
|
var twice: AudioStreamPlayer3D = driver._active_3d[18]
|
|
twice.finished.emit()
|
|
_check(driver._active_3d.has(18), "two-play ambience stopped after first play")
|
|
twice.finished.emit()
|
|
_check(not driver._active_3d.has(18), "two-play ambience did not finish")
|
|
driver.stop_sound_3d(17)
|
|
_check(not driver._active_3d.has(17), "StopSound3D left indexed sound running")
|
|
driver.stop_all_sound_3d()
|
|
_check(driver._all_3d.is_empty(), "StopAllSound3D left a player running")
|
|
driver.play_music("login_window.mp3", 0.8)
|
|
_check(driver._music_slot("login_window.mp3") == 0, "PlayMusic did not use slot 0")
|
|
driver.fade_limit_out_music("login_window.mp3", 0.2, 0.1)
|
|
for i in 8:
|
|
driver._update_music_fades()
|
|
_check(absf(driver._bgm_volumes[0] - 0.2) < 0.001,
|
|
"FadeLimitOutMusic did not retain the requested limit")
|
|
driver.fade_limit_out_music("login_window.mp3", 0.7, 0.1)
|
|
driver._update_music_fades()
|
|
_check(absf(driver._bgm_volumes[0] - 0.7) < 0.001,
|
|
"40250 limit fade must clamp immediately when already below the limit")
|
|
driver.fade_limit_out_music("login_window.mp3", 0.2, 0.5)
|
|
driver._update_music_fades()
|
|
driver.fade_out_music("another_track.mp3", 0.1)
|
|
_check(not driver._bgm_fades.has(1), "FadeOutMusic affected an unrelated track")
|
|
driver.fade_out_music("login_window.mp3", 0.1)
|
|
for i in 2:
|
|
driver._update_music_fades()
|
|
_check(not driver._bgm[0].playing, "FadeOutMusic did not stop named track")
|
|
driver.fade_in_music("characterselect.mp3", 0.3, 0.1)
|
|
for i in 3:
|
|
driver._update_music_fades()
|
|
_check(absf(driver._bgm_volumes[0] - 0.3) < 0.001,
|
|
"FadeInMusic did not advance by the requested frame step")
|
|
for player in driver._bgm:
|
|
player.stop()
|
|
player.stream = null
|
|
for player in driver._ui_pool:
|
|
player.stop()
|
|
player.stream = null
|
|
driver._cache.clear()
|
|
driver.free()
|
|
await process_frame
|
|
print("PASS: audio_driver_test" if failures == 0 else "FAIL: audio_driver_test")
|
|
quit(0 if failures == 0 else 1)
|