From 99f80413752824ed1b2aef0f31366caeb8f5c3dc Mon Sep 17 00:00:00 2001 From: oioitff Date: Fri, 24 May 2013 00:42:15 +0800 Subject: [PATCH] Implement pcm voice correctly. --- Core/HLE/sceSas.cpp | 1 + Core/HW/SasAudio.cpp | 16 ++++++++++++---- Core/HW/SasAudio.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index 0db0dda278..537e81df1a 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -164,6 +164,7 @@ u32 sceSasSetVoicePCM(u32 core, int voiceNum, u32 pcmAddr, int size, int loop) v.type = VOICETYPE_PCM; v.pcmAddr = pcmAddr; v.pcmSize = size; + v.pcmIndex = 0; v.loop = loop ? false : true; v.playing = true; v.ChangedParams(pcmAddr == prevPcmAddr); diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 84806d52db..6e005a1cb2 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -311,10 +311,17 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) { break; case VOICETYPE_PCM: { - u32 size = std::min(voice.pcmSize, (int)(numSamples * sizeof(s16))); - Memory::Memcpy(resampleBuffer + 2, voice.pcmAddr, size); - if (numSamples * sizeof(s16) > size) - memset(resampleBuffer + 2 + voice.pcmSize, 0, numSamples * sizeof(s16) - size); + u32 size = std::min(voice.pcmSize * 2 - voice.pcmIndex, (int)(numSamples * sizeof(s16))); + memset(resampleBuffer + 2, 0, numSamples * sizeof(s16)); + if (!voice.on) { + voice.pcmIndex = 0; + break; + } + Memory::Memcpy(resampleBuffer + 2, voice.pcmAddr + voice.pcmIndex, size); + voice.pcmIndex += size; + if (voice.pcmIndex >= voice.pcmSize * 2) { + voice.pcmIndex = 0; + } } break; default: @@ -357,6 +364,7 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) { // Let's hope grainSize is a power of 2. //voice.sampleFrac &= grainSize * PSP_SAS_PITCH_BASE - 1; voice.sampleFrac -= numSamples * PSP_SAS_PITCH_BASE; + if (voice.envelope.HasEnded()) { // NOTICE_LOG(SAS, "Hit end of envelope"); diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index ef0c704aad..e39b84fcf6 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -196,6 +196,7 @@ struct SasVoice int vagSize; u32 pcmAddr; int pcmSize; + int pcmIndex; int sampleRate; int sampleFrac;