Fix negative fine pitch across octave boundaries - #131
Closed
zishounekonanoda wants to merge 1 commit into
Closed
Conversation
|
Author
|
Superseded by #130, which now includes both the playback scheduling changes and this negative fine-pitch fix, together with the environment-specific reproduction details and regression tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Root cause
NoteUtils.getPitchInOctavesplit the fine-pitch value using Java integer division and remainder:Java truncates integer division toward zero and keeps a negative remainder. For example, a note at key 33 with a -30 cent offset remained at key 33 with a remainder of -30. At the lower edge of that octave sample, this produced
pitches[-30]and threw anArrayIndexOutOfBoundsException.The exception propagated out of note playback and aborted the rest of that song tick, causing audible missing notes whenever 10-octave playback was enabled.
Fix
Using
Math.floorDivandMath.floorModrepresents the same note as key 32 with a +70 cent offset. This selects the previous octave sample and preserves the intended absolute pitch without accessing outside the pitch table.Positive pitch offsets retain their existing behavior.
Validation
./mvnw.cmd clean packageRelated reports
Spliterash/MusicBox#27 reports choppy playback and sounds randomly cutting out with NoteBlockAPI 1.x, especially when using the extended octave range and its resource pack. This pull request fixes one concrete cause of that symptom: a negative fine-pitch value crossing an octave boundary could throw during 10-octave playback and abort the remaining notes in the current song tick.
The report also discusses broader playback timing and NoteBlockAPI 2.0 migration concerns. Those parts are separate from this pitch fix and are addressed independently by #130 or remain outside this pull request.