Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken native midiout playback after playing a song that alters pitch bend #3090

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

Ghabry
Copy link
Member

@Ghabry Ghabry commented Sep 22, 2023

  1. Clearing the tempo data should fix that the next song is faster than usual at the beginning (prior speed became normal after the first tempo event).
  2. The fade code change solves the "sometimes Toilet in Wonderland music is mute" bug for me
  3. I hooked the Windows Midi API to compare the events. Harmony never generated "all sound off", I removed this event. But what Harmony does is resetting the pitch bend. When you look at the code it looks awful. The reason is that Pbend is > 127, so it uses some weird "calling convention" of preregistering a number so a larger value like 256 can be set. Midi...

The pitch bend reset fixes the broken music after playing some Toilet in Wonderland tracks because these songs indeed alter the pitch bend.

There are some further inaccuracies: The timing when we send volume changes for fade (and pan is completely missing) but system command wise we should be doing exactly the same now.

Frida hook for reference:

var midiOutLongMsg = Module.getExportByName(null, "midiOutLongMsg");
var midiOutShortMsg = Module.getExportByName(null, "midiOutShortMsg");

Interceptor.attach(midiOutLongMsg, {
    onEnter: function(args)
    {
		let size = args[1].add(4).readInt();
        console.log("LongMsg:" + hexdump(args[1].readPointer().readByteArray(size)));
	}
	
});

Interceptor.attach(midiOutShortMsg, {
    onEnter: function(args)
    {
        console.log("ShrtMsg:" + args[1]);
	}
	
});

@Mimigris please check if this fixes the tracks for you.

This sometimes appears to break the volume of Midi on Windows as it is timing sensitive.
All sound off is never sent.
After the GM reset harmony sends Pitch Bend Range 256 to all channels.

Resetting the pitch bend fixes the corrupted audio after playing the tracks zerotwo and timetolearn in "Toilet in Wonderland".
These songs indeed alter the pitch bend.

Fix EasyRPG#2910
@Ghabry Ghabry added this to the 0.8.1 milestone Sep 22, 2023
@Ghabry Ghabry changed the title Audio/midi accuracy Fix broken native midiout playback after playing a song that alters pitch bend Sep 22, 2023
@fdelapena fdelapena merged commit 6d2f042 into EasyRPG:master Sep 26, 2023
4 checks passed
@tyrone-sudeium tyrone-sudeium mentioned this pull request Nov 16, 2023
@Ghabry Ghabry deleted the audio/midi-accuracy branch September 2, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants