Skip to content

Fix negative fine pitch across octave boundaries - #131

Closed
zishounekonanoda wants to merge 1 commit into
koca2000:masterfrom
zishounekonanoda:fix/negative-fine-pitch
Closed

Fix negative fine pitch across octave boundaries#131
zishounekonanoda wants to merge 1 commit into
koca2000:masterfrom
zishounekonanoda:fix/negative-fine-pitch

Conversation

@zishounekonanoda

@zishounekonanoda zishounekonanoda commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • normalize negative fine-pitch values with floor division and floor modulus
  • select the previous octave sample when a negative cent offset crosses an octave boundary
  • add regression tests for pitch calculation and resource-pack sound selection

Root cause

NoteUtils.getPitchInOctave split the fine-pitch value using Java integer division and remainder:

key += pitch / 100;
pitch %= 100;

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 an ArrayIndexOutOfBoundsException.

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.floorDiv and Math.floorMod represents 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 package
  • 2 regression tests, all passing
  • shaded plugin JAR generated successfully

Related 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.

@zishounekonanoda
zishounekonanoda deleted the fix/negative-fine-pitch branch August 11, 2026 17:48
@zishounekonanoda
zishounekonanoda restored the fix/negative-fine-pitch branch August 11, 2026 17:48
@sonarqubecloud

Copy link
Copy Markdown

@zishounekonanoda

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant