mcpx: Mitigate ADPCM audio crackling #1616
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a workaround for audio crackling that frequently occurs when non-streaming ADPCM voices are requested to be deactivated before finishing using
NV1BA0_PIO_VOICE_OFF.
Fixes the issue #339 most likely similar issues with other games too.I noticed the
NV1BA0_PIO_VOICE_OFF
arrives to thevp_write
callback after something has already written garbage data to the voice processor memory region. At that point it would not be possible to retroactively clear the output buffers, since the voices have already been mixed together. So I created a workaround which detects this garbage data before it is decoded and written to sample buffers.This will have a very minimal performance impact (could not notice at all when profiling). It is however a hack around a root issue I do not have the expertise to debug. In ideal scenario the
NV1BA0_PIO_VOICE_OFF
would arrive in time before the memory contains this garbage data.I tested the fix with USA version of standalone Jet Set Radio Future, where both mono and stereo ADPCM voices exhibited this issue. Now both are fixed and there are no other downsides that I could find. I can't come up with a scenario where a valid ADPCM header would contain all identical non-zero values and still represent audio someone wants to hear 馃檪
I tested the code on Ubuntu 22.04 (x86), Windows 11 (x86) and M1 Mac (arm64), identical behavior on those platforms.