Thealexbarney / VGAudio

A library for encoding, decoding, and manipulating audio files from video games.
MIT License
219 stars 37 forks source link

Slight Issue with HPS Encoding #99

Closed gheskett closed 6 years ago

gheskett commented 6 years ago

I've noticed that the HPS streams seem to have an issue where some instances of static are formed during playback. Although this effect is mostly subtle and cannot be heard with vgmstream at all, it is present when used on Dolphin and the Wii/GameCube (especially with softer pieces of music). I don't know this for certain, but I think the issue lies within the block sizes. I have found that most (if not all) HPS streams used in the games have block sizes of 0x00010000, whereas VGAudio tends to create block sizes of 0x0000FFC0, a difference of 64 bytes. While I don't fully understand the format or why a block size would negatively affect the playback of the audio, it remains put that vgmstream doesn't exhibit this problem, so I honestly do think that is the cause of the issue.

image

Thealexbarney commented 6 years ago

Which games specifically? HPS loop points have to fall at the edge of a block, so adjustments need to be made for that. The sizes of the blocks leading up to the loop point will slowly decrease so the loop point will end up in the right spot.

When implementing this I used the HPS files from Smash Bros Melee and Kirby Airride for testing by unpacking and rebuilding the HPS container. IIRC, the current HPS builder matches the originals ~80% of the time. The other differences come from VGAudio choosing slightly different block sizes than the official encoder did.

The audio code in the games may make some assumptions about the stream for optimization or other reasons that could be causing the static issue.

gheskett commented 6 years ago

I can confirm the playback issues seem to appear in the exact same manner across both Kirby Air Ride and Super Smash Bros. Melee. Artifacts can definitely be found in both games, each spaced out by a couple of seconds. I can also confirm that all the native HPS files from both games that I've tried have block sizes of 0x00010000.

I just tried comparing an HPS file created by VGAudio between the interpretations of vgmstream and Dolphin. Here is something I discovered:

image

I've noticed each time these artifacts appear, the audio seems to have an amplitudinal "zero" effect where the waveform essentially reverts very close back to the center. I feel like the issue may just be a problem with the game's way of dealing with and interpreting history samples or something along those lines.

Thealexbarney commented 6 years ago

How's the audio with the fix in a24f7fe8?

I tested it by rebuilding 984 official HPS files, and the number of files that were byte perfect jumped from 40 to 868.

gheskett commented 6 years ago

I haven't had the opportunity to test this in-depth yet, but the issue appears to be resolved based on what I've seen so far. I'll let you know if anything else pops up.