fix(fps): a song's notes show one at a time with its melody above a 60 fps cap #1471
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1471
Loading…
Reference in a new issue
No description provided.
Delete branch "CraftyCorvid/Longshot:fix/ocarina-song-notes-above-60"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: Linux, RTX 5090 · Needs: none
TL;DR
With the frame rate cap above 60, after you played a song on the ocarina its notes showed two or three at a time, ahead
of the music. Now they show one at a time as the music reaches each, as at a cap of 60. A new test fails on main and
passes here, and Zelda's Lullaby played uncapped (about 150 fps) on Linux showed its notes in time with the music.
Breakdown
times before the sound engine, which runs 60 times a second, moved on.
cold review by a second agent, and the game uncapped on Linux, RTX 5090.
which uses the same code but which I haven't seen run.
Why
With the Game frame rate cap past 60, after you play a song on the ocarina the game plays the song back and shows its
notes, but they come two or three at a time and run ahead of the music: at about 150 fps Zelda's Lullaby showed all six
notes within 1.3 s of a melody that lasts about 4 s. At a cap of 60 each note shows as the music reaches it. No issue
covers it (the tracker searched for ocarina, song, playback, notes, melody); #78 fixed a different counter, the
Scarecrow's Song's, and #414 is the ocarina's input.
How to reproduce
Seen on: CachyOS Linux (kernel 7.3), RTX 5090, NVIDIA 620.70.06
Settings and switches: Game frame rate cap Uncapped (about 140-160 fps on this PC), everything else default
Steps: take out the ocarina anywhere and play a song you know (Zelda's Lullaby here), then watch the playback
Expected: one note shows at each note of the melody, as at a cap of 60
Actual: the notes show in bursts of two or three, ahead of the music, and the playback ends early
What changed
After a song is played, its playback (
f_832b2af0) goes on to the next note on each update it finds the note flag set:a word the sound engine sets when the melody reaches a note and clears on its next run. The sound engine runs in the
sound job, which runs at 60 Hz above 60 fps (its gate,
hos_oot_sound_gate, from8fcc8c22), so at 150 fps the playback found the flag set on two orthree updates in a row and went on that many notes. The flag's read now goes through the host: above a cap of 60, a set
flag read again before the sound job has run again is the same note and reads clear. At a cap of 60 the game's value is
unchanged. The ocarina's other melody playback (
f_832b2dc0, the ocarina state machine's state 6) has the same codeand gets the same treatment (its melodies are the game's example melodies, by their names; I haven't seen it run).
nx2/oot_patches.pypatch_song_cue: after each of the two calls tof_832b7b50(the flag's read, by itsreturn address
0x832b2c84and0x832b2ed4), its result goes throughhos_oot_song_cue;reportwarns when eitheris not found once.
host/oot_high_fps.hoot_song_cue(the rule, and why at the top of the file), andhost/oot_high_fps.chos_oot_song_cue(each playback's last read, under the sound job's lock) with the sound job's runs counted at itsgate (
hos_oot_sound_gate).HOS_FPS_LOGcounts the reads it held back.tests/test_song_note_cue.py.How it was found: a diagnostic build (not in this PR) counted the calls of the ocarina's functions at 60 and uncapped,
which pointed at the playback's update, then logged its state each update and put a hardware write watchpoint on the
flag. The only writer is the sound job (
f_80435300, throughf_806aa3b0): it writes 0 on every run and sets theflag on the run where the melody reaches a note.
Measurements
Verdict: fixed. Uncapped, the notes now show one at a time with the music (by eye, and the host held back the
flag's repeated reads); the game-free test fails on
mainfor this bug and passes here.Hardware: CachyOS Linux (kernel 7.3), RTX 5090, NVIDIA 620.70.06
Scene: the ocarina in a field, Zelda's Lullaby; Game frame rate cap Uncapped (about 140-160 fps) and 60
Method:
tests/test_song_note_cue.py(gcc and clang); in the game, a diagnostic build onmain's code logging theplayback's note and the flag each update, then this branch played by hand with
HOS_FPS_LOG=1How to reproduce:
python -I -B tests/test_song_note_cue.py; in the game, the steps aboveBaseline: the in-game before is a diagnostic build (logging only) of an earlier
main,71b1edd8, the dev base on thisPC. Since then
maingained, in the same files, the battle music's flags and the music manager's step (#1224), Gohma'sturn rate (#1098) and a horse's jump (#1434); the sound job's gate and the ocarina's code are unchanged, and the
game-free test shows the same bursts on
mainc7db6c02. The after is this branch (at 22c8ce7e, the same fix code),built as a dev pack over the same base.
c7db6c02(with the test, b1832551)test_song_note_cue.pyFlags and settings
None (
HOS_FPS_LOG, the existing diagnostic switch, gets one more line).Testing
Tested:
71b1edd8(thelift reports "the song playbacks' note flag once a note above 60 fps in code_045.c", and no warning). Since then the
branch changed only its test and comments (the cold review) and was rebased onto
mainc7db6c02, whose #1434 addsa horse's jump patch beside this one in the same files; the fix's code is the same. Uncapped (about
140-160 fps), Zelda's Lullaby's notes showed one at a time with the music; at a cap of 60 as before.
tests/test_song_note_cue.pywith gcc and clang (and compiled by MinGW gcc): fails at b1832551 (the test alone, onmain), passes at 70835372. Broken on purpose, it fails: no repeat held back (120 fps), the sound job's runs notcounted (two notes on consecutive runs of the sound engine), the rule applied at a cap of 60 too (a cap of 60 with two
reads a frame), the host handing back the game's value, and a rule by time instead of by the job's runs (a set flag
counted once per 60 fps frame of time: it loses one of two notes on consecutive runs at 75 fps and around 60).
this version: the test gained two notes on consecutive runs at 75, 90, 144 and 165 fps, uncapped with varying frame
times and around 60 (steps of 0.98 to 1.02), which the time-based rule above passed before; the header now states the
thread order the rule relies on, with the log that shows the game keeps it; three comments corrected. It also caught
these mutations in the test: one state for both playbacks, the result stored instead of the game's, the hook before
the call.
python -I -B tests/run_all.py(Linux): 633 passed, 38 failed, 91 skipped (Vulkan and SPIR-V headers missing here).The 38 also fail on
main(run there), for reasons in files this PR doesn't touch (test_dev_packs, which reads thepatch file, fails the same way on
mainc7db6c02: "a game patch shows in the objects"): test_bug_report_defaults,test_compute_warm_apart, test_cpu_report, test_crt_options, test_damage_debug_menu, test_discover,
test_dev_packs, test_display_startup_failure, test_dlss_feature_size, test_failed_compile_keeps_objects, test_framegen_preset,
test_guest_imported, test_hud_layout_row, test_invalidate_quick, test_invalidate_vcore, test_lift_lookups, test_linux_preflight,
test_linux_pressure, test_linux_update, test_log_open_failure, test_mirror_budget, test_missing_nup,
test_mods_size_table, test_pending_guest_import, test_pipeline_play_cache, test_present_thread, test_profiling_mode,
test_readback_timeout_source, test_rumble_menu, test_run_all_changed, test_slow_frames, test_switch_table, test_target_image_pool,
test_upscaler_round_trip, test_upscaler_rows, test_vcore_escape, test_walk, test_walk_key.
host/oot_high_fps.ccompiled alone (-fsyntax-only -Wall -Wextra, the build's include folders) with gcc and clangfor Linux and with llvm-mingw clang (tools.lock's, 20261104) and MinGW gcc for Windows: no warnings, as on
main.Not tested:
f_832b2dc0, state 6) in the game: it didn't run in these rides and I haven'tidentified when the game uses it. It is the same code and the same rule, and the game-free test runs it.
frames slower than 60).
Must be tested: None.
Risks
What could break: the note display of an ocarina song's playback above a 60 fps cap. Above 60, a set flag read on
two updates with no run of the sound job between is counted once; were the flag ever meant to count twice within one
run, a note would be lost (the game's own timer then moves the playback on when its melody ends). The job's runs are
counted at the head of its phase 0 and the flag is written later in that phase, so a playback read inside phase 0 would
count one note twice: the game's own threads never did that in the diagnostic's log (the run count less the flag's
clears stayed the same through each playback, 432 reads on five worker threads and the main thread), and the test
cannot model threads. At a cap of 60 nothing changes: the host hands back the game's value.
Turning it off: revert the commit, or a cap of 60.
Compatibility: Nothing changes for saves, options or caches; an update translates the game's code again, as for any
change to the lift's patches.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened. (None needed: the checks thatread
host/oot_high_fps.*ornx2/oot_patches.py,test_high_fps_fixes.py,test_patch_hooks_defined.py,test_ocarina_wait.pyandtest_scarecrow_timing.pyamong them, pass unchanged.)🤖 Generated with Claude Code
Tested in game: RTX 5090, NVIDIA 620.70.06, Linux (CachyOS): the ocarina in a field, Zelda's Lullaby, Game frame rate cap Uncapped (about 140-160 fps): after the song, its notes showed one at a time with the music (on main they came two or three at a time, ahead of it); at a cap of 60 as before. Built as a dev pack over a base of
71b1edd8.22c8ce7e25bd8e6c4e83Rewritten after a cold review by a second agent (the diff and the test, not my conclusions): the branch still reads test, then fix, now aed6e69d and bd8e6c4e (were dae46b12 and 22c8ce7e). No blocking problem was found; what changed:
main257c5491.host/oot_high_fps.h: the comment states the thread order the rule relies on: the job's runs are counted at the head of its phase 0 and the flag is written later in that phase, so the playback must not read it inside phase 0. The diagnostic's log shows the game keeps that order (the run count less the flag's clears stayed the same through each playback, 432 reads on five worker threads and the main thread). Also in Risks.No code change:
tests/run_all.pygives the same 607 passed and the same 34 failures that also fail onmain;host/oot_high_fps.ccompiles without warnings with gcc, clang, llvm-mingw clang and MinGW gcc.bd8e6c4e8370835372dcRebased onto
mainc7db6c02: now b1832551 (test) and 70835372 (fix), were aed6e69d and bd8e6c4e. #1434 (a horse's jump above 60) had merged into the same places:host/oot_high_fps.hand.c,nx2/oot_patches.py'spatch_fileandreport, and the README's frame rate cap row. Both are kept, the horse's first, and the host file's head comment names both. The fix's code is unchanged.After the rebase:
tests/test_song_note_cue.pyfails at b1832551 and passes at 70835372 (76 checks, gcc and clang).test_horse_jump_step,test_high_fps_fixes,test_patch_hooks_defined,test_ocarina_waitandtest_scarecrow_timingpass.host/oot_high_fps.ccompiles without warnings with gcc, clang, llvm-mingw clang and MinGW gcc.tests/run_all.py: 633 passed, 38 failed, 91 skipped. The 38 also fail onmainc7db6c02. Four of them are new since257c5491and fail onmaintoo: test_compute_warm_apart, test_dev_packs (the same "a game patch shows in the objects" on both), test_invalidate_quick, test_switch_table.WIP: fix(fps): a song's notes show one at a time with its melody above a 60 fps capto fix(fps): a song's notes show one at a time with its melody above a 60 fps cap70835372dc97d8b51b20Quick code review: the note-flag rule (a set flag read again before the sound job's next phase-0 run is the same note) is small and matches the description; the patch is idempotent and warns when either call site is missing. Rebased onto main (af. #1628/#1559): the header comments in host/oot_high_fps.{c,h}, the README line and nx2/oot_patches.py's patch_file/report were union-merged with main's floor-carry and cloth entries; no code changed.