Skip to content

Keep streamed music alive across the enemy bgm crossfade - #7126

Open
bassdr wants to merge 1 commit into
HarbourMasters:developfrom
bassdr:fix/streamed-bgm-enemy-crossfade
Open

Keep streamed music alive across the enemy bgm crossfade#7126
bassdr wants to merge 1 commit into
HarbourMasters:developfrom
bassdr:fix/streamed-bgm-enemy-crossfade

Conversation

@bassdr

@bassdr bassdr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #5706.

Audio_SplitBgmChannels() stops the channels of the quieter bgm player so it hands its notes back to the pool. A sequence loses nothing by that - its script issues fresh notes every tick. Streamed music is a single note lasting the whole song, so stopping its channel ends the track for good; neither the mask clearing nor the volume returning brings it back.

Two ways in, which is why it looked intermittent: both players are stopped together while volSplit is between 40 and 87 (roughly 260 to 390 units from the enemy), and the sub player is stopped the instant enemy mode engages, before the queued sequence has reached it. The second depends on the distance at that exact moment, so the same route reproduces or not.

Testing

Instrumented build, Dodongo's Cavern with a streamed music pack, same route each run, counting log lines where a player's volume says it should be audible while all of its channels are stopped:

before after
player silenced while audible 26 0
channel stop masks applied 36 0

Also entered encounters at the two distances that previously killed the battle track before it could start, with no stop applied. A streamed track ran 1.6 million samples uninterrupted across an encounter, against roughly 580 thousand before.

Build Artifacts

@bassdr

bassdr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

I found a somewhat similar bug that happens in the vanilla game too, but kept it in a separate branch as this is unrelated to what's fixed here. I reproed also in the royal family tomb, when you approach enemies, the battle music will sometimes not start. I remember this behavior also on console.

The channel stop silences both players together for part of every crossfade in vanilla
too. With sequences it is far subtler, because the notes come straight back, but the
music does thin out for a moment.

Branch for anyone who wants to read the code, gated behind a checkbox under
Enhancements -> Fixes and defaulting to vanilla:
bassdr:Shipwright:enhancement/fix-battle-music-dropout

@lankv2 worth pursuing, or too subtle to bother? Your call is better than mine here. It
is a new feature during a feature freeze, so it should not ride along with a bug fix
either way, and nothing about it needs deciding before this PR lands. If you think
it is worth doing, please open an issue (or say so and I will open one) so it is queued
rather than blocking.

One tradeoff a programmer should weigh first: the stop is how the quieter player
releases notes back to a fixed pool of 22 to 28, so removing it means both players hold
their voices through a crossfade. I have not measured whether that ever costs a dropped
note, but I assume this was the reason vanilla did it that way.

@lankv2

lankv2 commented Aug 28, 2026

Copy link
Copy Markdown

@bassdr not sure what you're asking is too subtle but after testing the build linked, i think it's pretty much perfect! The battle music resumes properly.

Fixes HarbourMasters#5706.

Audio_SplitBgmChannels stops the channels of the quieter bgm player so it gives
its notes back to the pool. A sequence loses nothing, since its script issues
fresh notes every tick, but streamed music is a single note that lasts the whole
song and then waits on a long delay: stopping its channel ends the track for
good, and neither the mask clearing nor the volume returning brings it back.

Both players are stopped together while volSplit is between 40 and 87, and the
sub player is also stopped at the instant enemy mode engages, before the queued
sequence has reached it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Ex3z29fQzPEZgwH4EA641
@bassdr

bassdr commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@bassdr not sure what you're asking is too subtle but after testing the build linked, i think it's pretty much perfect! The battle music resumes properly.

Thanks @lankv2 for confirming the fix works!

On my other question: nobody has raised this in all the audio-mod work you've done, which is answer enough — it's not annoying in practice. I won't PR the enhancement for now.

@bassdr
bassdr force-pushed the fix/streamed-bgm-enemy-crossfade branch from 75697ce to 1a2d8f2 Compare August 28, 2026 12:51
@lankv2

lankv2 commented Aug 28, 2026

Copy link
Copy Markdown

@bassdr yah so i tested the build with the enhancement on and off and i don't notice much of a difference tbh, so i think it's fine without the enhancement. Also btw, have you tried out my music mod?

@bassdr

bassdr commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@lankv2, yes I tried it, nice work :) I'll try it again during my next playthrough. If there are other bugs preventing it to sound like you want, I might look into it, as audio was the part I felt un-"enhanced", and also why I created my fluidsynth integration, but it also has limitations (Malon and some songs are not Midi-friendly at all, as they have custom instruments).

@lankv2

lankv2 commented Aug 29, 2026

Copy link
Copy Markdown

@bassdr i have opened some other issues that may be worth looking into, for me the big things right now are the fluidsynth integration for hyrule fields music, and the following issues. #5684 #5780

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.

Custom Audio: Battle music playback issues

2 participants