EmuNewz Network

Full Version: Fix for distorted synthesizer sound (maybe)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Starting with r1979, I noticed that sound effects in Persona 3 Portable became a bit distorted and noisy. I think I have found a way to restore the sound quality back to the way it was previously. In class jpcsp.sound.SampleSourceWithPitch starting on line 75, I changed the getSampleIndex() method to:
Code:
    @Override
    public int getSampleIndex() {
            return sampleIndex;
    }

The original one calculates the sampleIndex from the sampleSourceIndex but I'm not sure that's necessary since there's already a sampleIndex field available. The calculation probably introduces rounding errors which cause the distortion/noise? Changing the above seems to have restored sound effects quality in P3P (and probably other games too) back to the way it was before r1979.

Also, I noticed that SampleSourceWithPitch isn't needed if pitch is already at base pitch, and some sound effects in P3P (and I assume in other games too) are at base pitch. So, perhaps the following optimization in class jpcsp.sound.SoftwareSynthesizer in method getSampleSource() replacing lines 35-36 can help a bit:
Code:
ISampleSource sampleSourceTemp = new SampleSourceVAG(voice.getVAGAddress(), voice.getVAGSize(), voice.getLoopMode() != sceSasCore.PSP_SAS_LOOP_MODE_OFF);
int pitch = voice.getPitch();
if (pitch == sceSasCore.PSP_SAS_PITCH_BASE)
        sampleSource = sampleSourceTemp;
else
        sampleSource = new SampleSourceWithPitch(sampleSourceTemp, pitch);

I haven't done any benchmarks at all, and the above optimization may even be useless or even slow things down a bit if very few sounds are at base pitch in most games. Oh well, it's just a suggestion. Smile
Very well spotted!
In fact, the PSP itself skips the pitch conversion if the sound is already sampled at the base pitch, so you're fix is completely accurate. Even though there aren't many games using only the base pitch, it's necessary to enable this check.
Thanks, Itaru! Big Grin
Hi Itaru!

thank you for your code review! Is the problem fixed by r1995? The fix was a little bit more complicated to handle looping sounds.
I've also posted your improvement in r1996.
You're very welcome, Hykem and gid15. And thank you very much for the proper fix, gid15! I kinda figured the fix wouldn't be that simple so that's why the "(maybe)" in the title, hehe. It's working perfectly now with your fix. Smile