mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 09:19:58 -04:00
Run the sound manager's job at 60 Hz with whole steps above 60 fps.
The job (main+0x415300) hands the time manager's step to the sound system in its phase 0 and runs the sound objects' and the system's updates in phases 1 and 2. With the set ostep that step is a fraction of a frame above 60 fps, and fed fractions the game has been reported to keep sounds held after an area unloaded until no voice was free, new sounds and then the music going silent until a restart. The new set osound (sound_steps, on by default) calls the page's +0xf10 after the job's prologue: phase 0 adds the step to what the job is owed and runs once a whole step has built up, phases 1 and 2 follow that choice, and a job that does not run gets phase 3, which returns through its own epilogue. After phase 0's load of the step the page's +0xf00 makes a fraction one whole step. At 60 fps and below the job runs every frame with the game's step. Both sites were checked against the module; frame_step_check covers the gate at 60, 30, 144 and 240 fps. Needs the game code generated again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
|
||||
// Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
|
||||
static const char *const known[] = {
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_FPS", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "ONESHOT_BUDGET", "ONESHOT_WAIT_MS", "OCARINA_STEP", "PHYSICS_STEPS", "PICKUP_COUNT", "WATER_STEPS", "FLOOR_PROBE", "FLOOR_SCAN", "MOVIE_PTS", "STEP_STEADY", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_FPS", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "ONESHOT_BUDGET", "ONESHOT_WAIT_MS", "OCARINA_STEP", "PHYSICS_STEPS", "PICKUP_COUNT", "WATER_STEPS", "SOUND_STEPS", "FLOOR_PROBE", "FLOOR_SCAN", "MOVIE_PTS", "STEP_STEADY", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"AA", "AA_LOG", "AB", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CATCHUP", "AUDIO_CHANNELS", "AUDIO_DEVICE", "AUDIO_GAME_PRIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "AUDIO_RAMP", "AUDIO_STATS",
|
||||
"BARRIER_GAME", "MESH_AHEAD", "MESH_FALLBACK", "MESH_FALLBACK_MB", "MESH_FALLBACK_WORKERS", "PROBE_MESHFB_DIR",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
|
||||
@@ -103,6 +103,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"FPS_LIMIT", "frame rate"}, {"FPS60", "frame rate"}, {"RTSS", "frame rate"},
|
||||
{"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"},
|
||||
{"PHYSICS_STEPS", "frame rate"}, {"PICKUP_COUNT", "frame rate"}, {"WATER_STEPS", "frame rate"},
|
||||
{"SOUND_STEPS", "frame rate"},
|
||||
{"MOVIE_PTS", "frame rate"}, {"STEP_STEADY", "frame rate"},
|
||||
{"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"},
|
||||
{"GPU_INDEX", "display"}, {"MONITOR", "display"}, {"OUTPUT_RES", "display"}, {"GAME_ASPECT", "display"}, {"GAME_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"},
|
||||
@@ -243,6 +244,8 @@ static const CfgMeta metas[] = {
|
||||
{"HIGHFPS_FIX", "1", "0|1", RESTART},
|
||||
// the set owater of patches-v111.txt (frame_rate.c frame_rate_sim_host): water and floor surfaces' fixed steps
|
||||
{"WATER_STEPS", "1", "0|1", RESTART},
|
||||
// the set osound of patches-v111.txt (frame_rate.c frame_rate_sound_gate_host): the sound job at 60 Hz above 60 fps
|
||||
{"SOUND_STEPS", "1", "0|1", RESTART},
|
||||
// frame_rate.c floor_probe: lines about Link on a moving floor (0 off, 1 = 4000 lines, or a count)
|
||||
{"FLOOR_PROBE", "0", NULL, RESTART},
|
||||
// frame_rate.c floor_scan: finds the moving floor under Link in guest memory (0 off, 1 = 20000 lines, or a count)
|
||||
|
||||
@@ -615,6 +615,78 @@ void frame_rate_sim_host(Cpu *c) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- the sound manager's job at whole steps (patches-v111.txt osound)
|
||||
// The job (main+0x415300) runs in three phases a frame, the phase in w2: 0 loads the time manager's step, frames per
|
||||
// update at [[main+0x4c7e890]] +0x10, and hands it to the sound system ([[main+0x4c80c38]] +0xa8, and with its inverse
|
||||
// +0x18 of the object at +0x10 of [[main+0x4c806d0]]); 1 runs the sound objects' updates, 2 the system's own
|
||||
// (main+0x3798410). Any other phase returns at once (main+0x4155fc); the task wrappers main+0x4151f0 and main+0x4152d0
|
||||
// skip a 3 themselves. The sound system counts its fades, delays and parameter ramps in updates of at least one step.
|
||||
// With the set ostep the step is the display interval in 60 Hz frames, a fraction of one above 60 fps. Fed fractions,
|
||||
// this game has been reported to keep sounds held after an area unloaded until no voice was left free, so that new
|
||||
// sounds, then the music, went silent until a restart (not reproduced on this build: the fault takes a few area
|
||||
// changes above 60 fps). With the set osound the job runs at 60 Hz while the step is a fraction:
|
||||
// - frame_rate_sound_gate_host, after the job's prologue: phase 0 adds the step to what the job is owed and runs once
|
||||
// a whole step has built up, keeping the rest; phases 1 and 2 follow that frame's choice. A job that does not run
|
||||
// gets phase 3 in w2, so it returns through its own epilogue.
|
||||
// - frame_rate_sound_step_host, after phase 0's load of the step: a fraction becomes one whole step.
|
||||
// A step of one or more (60 fps and below) runs as the game has it and leaves what is owed for the next fractions; a
|
||||
// step that is not positive (or NaN) runs as the game has it and clears it. So the sound clock keeps the game's on
|
||||
// average at any frame rate, and at 60 fps the job runs every frame as before.
|
||||
typedef struct {
|
||||
float owed; // steps given since the job last ran, under one
|
||||
int run; // phase 0's choice, which the frame's other phases follow
|
||||
} SoundGate;
|
||||
static SoundGate sound_gate = {0.0f, 1}; // every phase runs until a phase 0 has chosen
|
||||
|
||||
static int sound_gate_take(SoundGate *g, uint32_t phase, float step) {
|
||||
if (phase != 0) return g->run;
|
||||
if (!(step > 0.0f)) {
|
||||
g->owed = 0.0f;
|
||||
return g->run = 1;
|
||||
}
|
||||
if (step >= 1.0f) return g->run = 1;
|
||||
g->owed += step;
|
||||
g->run = g->owed >= 1.0f;
|
||||
if (g->run) g->owed -= 1.0f;
|
||||
return g->run;
|
||||
}
|
||||
|
||||
// The step the job's phase 0 loads (1 when the time manager is not there: the gate then lets the phase run).
|
||||
static float sound_job_step(void) {
|
||||
uint64_t slot = read_ptr(MOD_MAIN_BASE + 0x4c7e890), mgr = slot ? read_ptr(slot) : 0;
|
||||
float step = 1.0f;
|
||||
if (mgr && !read_guest(mgr + 0x10, &step, 4)) step = 1.0f;
|
||||
return step;
|
||||
}
|
||||
|
||||
// NX2NAVI_TRACE=perf: every 10 s, how often phase 0 ran of the times it was asked.
|
||||
void frame_rate_sound_gate_host(Cpu *c) {
|
||||
uint32_t phase = (uint32_t)c->x[2];
|
||||
float step = phase == 0 ? sound_job_step() : 1.0f;
|
||||
uint64_t asked = 0, ran = 0, t = 0;
|
||||
plat_mutex_lock(&whole_lock); // the phases may come from different threads
|
||||
int run = sound_gate_take(&sound_gate, phase, step);
|
||||
if (phase == 0 && (rt_trace & RT_TRACE_PERF)) {
|
||||
static uint64_t t0, n, r;
|
||||
uint64_t now = plat_now_ns();
|
||||
n++, r += (uint64_t)run;
|
||||
if (!t0) t0 = now;
|
||||
if (now - t0 >= 10000000000ull) asked = n, ran = r, t = now - t0, t0 = now, n = r = 0;
|
||||
}
|
||||
plat_mutex_unlock(&whole_lock);
|
||||
if (!run) c->x[2] = 3;
|
||||
if (asked)
|
||||
rt_log("frame rate: the sound job ran %llu of %llu frames in %.1f s (step %.3f)", (unsigned long long)ran,
|
||||
(unsigned long long)asked, t / 1e9, step);
|
||||
}
|
||||
|
||||
void frame_rate_sound_step_host(Cpu *c) {
|
||||
uint32_t bits = (uint32_t)c->v[0];
|
||||
float step;
|
||||
memcpy(&step, &bits, 4);
|
||||
if (step > 0.0f && step < 1.0f) c->v[0] = 0x3f800000u; // 1.0f, the lanes above it zero as the load left them
|
||||
}
|
||||
|
||||
// The 60 Hz frames the game steps at each update where the set ostep gives them (Ocarina); 1 elsewhere, the game's own
|
||||
// nominal frame. The mouse camera divides by it (mouse_direct.c): the game multiplies camera input by this step.
|
||||
float frame_step_frames(void) {
|
||||
|
||||
@@ -410,6 +410,8 @@ double frame_step_game_hz(void); // the rate the game d
|
||||
void frame_rate_day_host(Cpu *c); // the time of day's seconds a frame (set ostep, page +0xf60)
|
||||
void frame_rate_water_host(Cpu *c); // the water's ripple steps a frame (set ostep, page +0xf50)
|
||||
void frame_rate_sim_host(Cpu *c); // water and floor surfaces' fixed steps (set owater, page +0xf20)
|
||||
void frame_rate_sound_gate_host(Cpu *c); // the sound job at whole steps (set osound, page +0xf10)
|
||||
void frame_rate_sound_step_host(Cpu *c); // the step the sound job hands on (set osound, page +0xf00)
|
||||
float frame_step_frames(void); // the 60 Hz frames the game steps per update (set ostep), else 1
|
||||
void frame_step_flight(float *page, float *game, uint64_t *presents); // flight.c: the step at a host present
|
||||
// rtss_limit.c: RivaTuner Statistics Server takes the frame limit where it runs
|
||||
|
||||
@@ -33,12 +33,15 @@ uint8_t rt_patch_on[RT_PATCH_COUNT > 0 ? RT_PATCH_COUNT : 1]; // read by the g
|
||||
#include "debug_tools.h"
|
||||
__attribute__((constructor)) static void freecam_register(void) { rt_register_host(RT_PATCH_PAGE + 0xf70, dbg_freecam_host); }
|
||||
// The time of day's site of the set ostep (patches-v111.txt) calls the page's +0xf60, the water renderer's site its
|
||||
// +0xf50, and the surfaces' fixed-step sites of the set owater its +0xf20 (frame_rate.c).
|
||||
// +0xf50, the surfaces' fixed-step sites of the set owater its +0xf20, and the sound job's two sites of the set osound
|
||||
// its +0xf10 and +0xf00 (frame_rate.c).
|
||||
__attribute__((constructor)) static void day_register(void) {
|
||||
if (!RT_V111) return;
|
||||
rt_register_host(RT_PATCH_PAGE + 0xf60, frame_rate_day_host);
|
||||
rt_register_host(RT_PATCH_PAGE + 0xf50, frame_rate_water_host);
|
||||
rt_register_host(RT_PATCH_PAGE + 0xf20, frame_rate_sim_host);
|
||||
rt_register_host(RT_PATCH_PAGE + 0xf10, frame_rate_sound_gate_host);
|
||||
rt_register_host(RT_PATCH_PAGE + 0xf00, frame_rate_sound_step_host);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user