Files
Triforce-Source/tests/test_audio_wave_buffer_release.py
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

91 lines
5.5 KiB
Python

"""Compile the actual wave-buffer calls, queued updates and the mixer's buffer consumption around an authored pass.
Ocarina's sound thread feeds six mono voices one after another: it reads each one's GetWaveBufferCount and appends
when one is short. The mixer finishing a buffer between two of those reads made one voice look short, the game
appended it an extra buffer, then one more each pass, until its queue was full and that speaker went silent. A
finished buffer must reach the game at the next RequestUpdateAudioRenderer, as on the console, never in between.
No game, SDK or output device is used. --source can select another nn_audio.c (the prior release fails the check).
"""
import argparse
import importlib.util
import os
from pathlib import Path
import re
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parents[1]
APPEND = "_ZN2nn5audio16AppendWaveBufferEPNS0_9VoiceTypeEPKNS0_10WaveBufferE"
RELEASED = "_ZN2nn5audio21GetReleasedWaveBufferEPNS0_9VoiceTypeE"
COUNT = "_ZN2nn5audio18GetWaveBufferCountEPKNS0_9VoiceTypeE"
STATE = "_ZN2nn5audio17SetVoicePlayStateEPNS0_9VoiceTypeENS1_9PlayStateE"
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cc", default="cc")
parser.add_argument("--source", type=Path, default=ROOT / "host/nn_audio.c")
args = parser.parse_args()
spec = importlib.util.spec_from_file_location("audio_block_helper", ROOT / "tests/test_audio_deadline.py")
helper = importlib.util.module_from_spec(spec)
spec.loader.exec_module(helper)
source = args.source.read_text(encoding="utf-8")
constants = []
for name in ("FRAME", "RATE", "AU_MAGIC", "MAX_VOICES", "MAX_MIXES", "MAX_SPLITTERS", "MAX_SPLIT_DESTS",
"MAX_CH", "MAX_BUF", "MAX_WB", "MAX_REL"):
matches = re.findall(r"^#define " + name + r"\s+[^\n]+", source, re.M)
assert len(matches) == 1, name
constants.extend(matches)
types = source[source.index("enum { K_VOICE"):source.index("static CRITICAL_SECTION lock;")]
queue = source[source.index("enum { OP_VOICE_RELEASE"):source.index("static int64_t last_update_ns;")]
actual = ["\n".join(constants), types, """
static Voice voices[MAX_VOICES];
static Mix mixes[MAX_MIXES];
static Splitter splitters[MAX_SPLITTERS];
static int sink_mix = -1;
/* (the samples are not looked at here: only which buffer the mixer is on) */
static void source_frame(Voice *v, const WB *w, int64_t s, float *out) { (void)v; (void)w; (void)s; out[0] = 0; }
static void adpcm_seek(Voice *v, const WB *w) { (void)v; (void)w; }
static int16_t adpcm_sample(Voice *v, const WB *w, int64_t s) { (void)v; (void)w; (void)s; return 0; }
"""]
actual.extend(helper.block(source, marker) for marker in (
"static void put_handle(", "static int get_handle(", "static int voice_index(", "static Voice *voice_of(",
"static WB read_wb(", "static int wb_in_guest(", "static void release_wb(", "static int next_source_frame("))
# (the update queue's apply also owns the Aux effects' state: their declarations and reset, as the file has them)
aux_start = source.index("typedef struct {", source.index("/* ---- Aux: the game supplies the processing"))
aux = [next(line for line in source.splitlines() if line.startswith("#define MAX_EFFECTS")),
source[aux_start:source.index("static int aux_on(void) {", aux_start)],
helper.block(source, "static void aux_ring_reset("), helper.block(source, "static void aux_reset(")]
actual.extend(aux)
actual.append("""/* ((Triforce) the controller speaker (host/pad_speaker.c, host/audio_source.h), off: nothing classed, nothing sent */
enum { AUDIO_SOURCE_NONE, AUDIO_SOURCE_NAVI_VOICE, AUDIO_SOURCE_NAVI_SOUND, AUDIO_SOURCE_TARGET, AUDIO_SOURCE_OCARINA };
enum { HOS_PAD_SPEAKER_OFF = 0, HOS_PAD_SPEAKER_ONLY = 1, HOS_PAD_SPEAKER_BOTH = 2 };
static int hos_pad_speaker_active(void) { return 0; }
static void hos_audio_source_load_async(void) {}
static int hos_audio_source_ready(void) { return 0; }
static int hos_audio_source_of(uint64_t data, uint32_t *crc) { (void)data, (void)crc; return -1; }
static int hos_audio_source_trace(void) { return 0; }
static const char *hos_audio_source_name(int cls) { (void)cls; return "?"; }""")
actual.extend([queue, helper.block(source, "static void apply("), helper.block(source, "static void submit("),
helper.block(source, "static void commit(")])
actual.extend(helper.block(source, "HLE(" + name + ")") for name in (APPEND, RELEASED, COUNT, STATE))
flags = subprocess.CREATE_NO_WINDOW | subprocess.BELOW_NORMAL_PRIORITY_CLASS if os.name == "nt" else 0
with tempfile.TemporaryDirectory(prefix="audio-wave-buffer-release-") as temporary:
folder = Path(temporary)
(folder / "actual_audio_wave_buffers.inc").write_text("\n\n".join(actual), encoding="utf-8")
executable = folder / "fixture.exe"
command = [args.cc, "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I" + str(folder),
str(ROOT / "tests/audio_wave_buffer_release_test.c"), "-lm", "-o", str(executable)]
for command in (command, [str(executable)]):
result = subprocess.run(command, creationflags=flags, capture_output=True, text=True,
encoding="utf-8", errors="replace", timeout=30)
print(result.stdout, end="")
print(result.stderr, end="", file=sys.stderr)
if result.returncode:
raise SystemExit(result.returncode)
if __name__ == "__main__":
main()