Skip to content

Fix notes ending too soon in GUS path - #280

Merged
psi29a merged 7 commits into
masterfrom
bugfix/gus_notes_end_too_soon
Jul 12, 2026
Merged

Fix notes ending too soon in GUS path#280
psi29a merged 7 commits into
masterfrom
bugfix/gus_notes_end_too_soon

Conversation

@psi29a

@psi29a psi29a commented Jul 11, 2026

Copy link
Copy Markdown
Member

Closes #229
Closes #230

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved MIDI note-off and “All Notes Off” release handling, including more accurate envelope tail timing.
    • Fixed release computations for non-envelope samples and preserved release tails when looping reaches end-of-track.
    • Improved GUS envelope amplitude calculations and corrected reverb listener position validation.
    • Clamped playback progress display to never exceed 100%.
  • Build Improvements
    • Static builds now automatically link required math libraries when configured.
  • Documentation
    • Updated man pages for current options and configuration behavior.

@psi29a
psi29a requested a review from sezero July 11, 2026 17:19
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change revises MIDI envelope release and tail timing, adds exponential envelope amplitude mapping, preserves release allowance during looping, links static builds with the configured math library, corrects reverb validation, updates playback progress display, and refreshes documentation.

Changes

MIDI release and rendering

Layer / File(s) Summary
Release envelope and allowance semantics
src/internal_midi.c
Note-off, All Notes Off, envelope stage transitions, and release-duration calculations now use revised stage-3 release behavior.
Envelope amplitude mapping
src/wildmidi_lib.c, src/CMakeLists.txt
Linear and Gauss premix paths use an initialized exponential amplitude table, and static consumers link ${M_LIBRARY} when configured.
Looped render release preservation
src/wildmidi_lib.c
Linear, Gauss, and SF2 rendering accumulate loop event samples instead of replacing existing release allowance.

Runtime configuration and display

Layer / File(s) Summary
Configuration validation and playback display
src/wildmidi_lib.c, src/player/wildmidi.c
Reverb listener Y validation uses room length, while paused and normal progress displays limit percentages to 100.

Documentation updates

Layer / File(s) Summary
Command-line and library reference updates
docs/man/man1/wildmidi.1, docs/man/man3/WildMidi_Init.3
Man pages document current options, content-based configuration detection, OPL3 selection, playback controls, and updated metadata.
Configuration reference updates
docs/man/man5/wildmidi.cfg.5
The configuration man page documents SoundFont selection, envelope compatibility behavior, reverb listener positions, and updated metadata.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: sezero

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also includes unrelated docs, progress-display, and reverb-bound fixes that go beyond the GUS note-decay issues. Split the manpage updates, playback percentage clamp, and reverb-bound fix into separate PRs unless they are required for the GUS fix.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main GUS note-release fix in this changeset.
Linked Issues check ✅ Passed The code changes adjust envelope release and tail mixing to address premature note cutoffs and excessive sustain in GUS playback.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/gus_notes_end_too_soon

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@psi29a psi29a mentioned this pull request Jul 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/internal_midi.c`:
- Around line 1043-1046: Update _WM_do_control_channel_notes_off() to preserve
the env == 0 fallback before calling _WM_do_note_off_extra(note_data), matching
the guard used by _WM_do_note_off(). Ensure notes with a zero envelope wait for
the initial envelope step instead of entering release stage 3 directly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f759bde4-d104-4bea-bc45-4c4cd2d3277d

📥 Commits

Reviewing files that changed from the base of the PR and between ec4ad76 and d4b348e.

📒 Files selected for processing (2)
  • src/internal_midi.c
  • src/wildmidi_lib.c

Comment thread src/internal_midi.c Outdated
@psi29a psi29a mentioned this pull request Jul 11, 2026
@sezero

sezero commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

I'm not proficient enough in midi/gus/etc to comment on code changes, but this midi, for e.g., now sounds weirder than it's used to: hex1.mid.zip (excessively sustained notes???)

@psi29a

psi29a commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

I'm not proficient enough in midi/gus/etc to comment on code changes, but this midi, for e.g., now sounds weirder than it's used to: hex1.mid.zip (excessively sustained notes???)

How does it sound like on timidiy (normal?).

I would like also @afritz1 time chime in about his XMI to check if it's excessive or not as well with his xmi files.

@sezero

sezero commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

How does it sound like on timidiy (normal?).

timi.zip
wm-before.zip
wm-pr280.zip

@psi29a

psi29a commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

@sezero try again with latest commit? I tried to follow timidity's code a bit here

@afritz1

afritz1 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

I'm not a MIDI connoisseur but I agree some notes are excessively sustained now.

Before this PR the rhythm in OVERSNOW.XMI was like staccato. Now it's the opposite, very drawn out. The strings at 53s are also more sustained. Could we get a middle ground maybe?

I exported these two .WAVs with Saphyr 2000: oversnow.zip

@psi29a

psi29a commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

I'm not a MIDI connoisseur but I agree some notes are excessively sustained now.

Before this PR the rhythm in OVERSNOW.XMI was like staccato. Now it's the opposite, very drawn out. The strings at 53s are also more sustained. Could we get a middle ground maybe?

I exported these two .WAVs with Saphyr 2000: oversnow.zip

Thanks! Please try with latest commit applied as well?

@afritz1

afritz1 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Yeah your latest commit feels like how the song should be IMO, it's not excessive anymore.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/wildmidi_lib.c`:
- Around line 1807-1813: Update the build definition for libwildmidi-static to
publicly propagate the math library dependency introduced by pow(), so consumers
linking only this target automatically receive M_LIBRARY. Preserve the existing
static target linkage and apply the dependency through the target’s
exported/public link interface.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12328c44-1c32-46ba-90ca-d54b62e812ff

📥 Commits

Reviewing files that changed from the base of the PR and between df586c5 and 43c3627.

📒 Files selected for processing (2)
  • src/internal_midi.c
  • src/wildmidi_lib.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/internal_midi.c

Comment thread src/wildmidi_lib.c
@afritz1

afritz1 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

I noticed the song duration on the command prompt is not exact now. in ARABCITY.XMI it thinks 100% is when the last note starts but then it goes back to ~55% and then is fading out the last note until 100% again.

@sezero

sezero commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@sezero try again with latest commit? I tried to follow timidity's code a bit here

Definitely better.

@sezero

sezero commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

How does this affect #230 ?

@psi29a

psi29a commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

How does this affect #230 ?

I'm not sure, I'd need to read the thread but I'll leave that for tomorrow. I'm a bit dead right now. 💀

Is this PR good for merge? want 0.5.0 to be a great big bang release :)

@sezero

sezero commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

How does this affect #230 ?

I'm not sure, I'd need to read the thread but I'll leave that for tomorrow.

OK

I'm a bit dead right now. 💀

Heh :)

Is this PR good for merge?

Sounds fair to me, but @afritz1 reported duration issues above?

want 0.5.0 to be a great big bang release :)

Will be that way, as i seems ;)

…00; cmake: propagate libm on libwildmidi-static INTERFACE
@psi29a

psi29a commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

Sounds fair to me, but @afritz1 reported duration issues above?

have another go @afritz1 ?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/internal_midi.c (1)

1211-1214: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Match the release estimate to the envelope direction.

_WM_Release_Allowance forces env_inc negative here, but the mixer and _WM_do_note_off_extra choose the sign by comparing env_level to env_target[note->env]. If stage 3 needs to rise before falling, longest_release will be too small and the tail can be cut off early. Mirror the same sign check here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/internal_midi.c` around lines 1211 - 1214, Update the release estimate
near _WM_Release_Allowance so note->env_inc uses the same direction as the mixer
and _WM_do_note_off_extra: choose its sign by comparing note->env_level with
note->sample->env_target[note->env], rather than always negating env_rate. Keep
the release calculation based on note->env_level / -note->env_inc after
selecting the correct direction.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/internal_midi.c`:
- Around line 1211-1214: Update the release estimate near _WM_Release_Allowance
so note->env_inc uses the same direction as the mixer and _WM_do_note_off_extra:
choose its sign by comparing note->env_level with
note->sample->env_target[note->env], rather than always negating env_rate. Keep
the release calculation based on note->env_level / -note->env_inc after
selecting the correct direction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33fddeac-efbe-459c-80f7-d62f70dbb282

📥 Commits

Reviewing files that changed from the base of the PR and between 43c3627 and 14c7149.

📒 Files selected for processing (3)
  • src/CMakeLists.txt
  • src/internal_midi.c
  • src/player/wildmidi.c

… reverb_listener_posy by room length, not width

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/man/man1/wildmidi.1`:
- Line 12: Update the wildmidi SYNOPSIS option cluster to include the
no-argument x option alongside the existing flags, matching the Convert to MIDI
option documented in the OPTIONS section.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7175e8fd-4303-47d3-9cb3-647b5d7ce3d8

📥 Commits

Reviewing files that changed from the base of the PR and between 14c7149 and 6133983.

📒 Files selected for processing (4)
  • docs/man/man1/wildmidi.1
  • docs/man/man3/WildMidi_Init.3
  • docs/man/man5/wildmidi.cfg.5
  • src/wildmidi_lib.c

Comment thread docs/man/man1/wildmidi.1 Outdated
@afritz1

afritz1 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

have another go @afritz1 ?

It's better, now it stays at 100% from the beginning of the last note until it's faded out completely. I think this only matters for really short songs like these city entrance jingles.

Playing ARABCITY.XMI
[Approx  0m  3s Total]
                              [    ] [100] [ 0m  6s Processed] [100%] \

@psi29a

psi29a commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

Indeed, that's the case.

@psi29a
psi29a merged commit 6e0b5ae into master Jul 12, 2026
18 checks passed
@psi29a psi29a added this to the 0.5.0 milestone Jul 12, 2026
@sezero
sezero deleted the bugfix/gus_notes_end_too_soon branch July 12, 2026 15:41
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.

Excessive echo/reverb/sustain Notes end too soon

3 participants