From 4b86fd75676d16f572d1670abc7ef25563054344 Mon Sep 17 00:00:00 2001 From: raven02 Date: Tue, 12 Mar 2013 09:14:31 +0800 Subject: [PATCH 1/2] Fake VOICETYPE_PCM code --- Core/HW/SasAudio.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index ce79551865dd..72bed102c73a 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -330,7 +330,34 @@ void SasInstance::Mix(u32 outAddr) { } } else if (voice.type == VOICETYPE_PCM && voice.pcmAddr != 0) { - // PCM mixing should be easy, can share code with VAG + resampleBuffer[0] = voice.resampleHist[0]; + resampleBuffer[1] = voice.resampleHist[1]; + u32 numSamples = voice.sampleFrac + grainSize ; + if ((int)numSamples > grainSize * 4) { + ERROR_LOG(SAS, "numSamples too large, clamping: %i vs %i", numSamples, grainSize * 4); + numSamples = grainSize * 4; + } + resampleBuffer[2 + numSamples] = resampleBuffer[2 + numSamples - 1]; + voice.resampleHist[0] = resampleBuffer[2 + numSamples - 2]; + voice.resampleHist[1] = resampleBuffer[2 + numSamples - 1]; + u32 sampleFrac = voice.sampleFrac; + for (int i = 0; i < grainSize; i++) { + int sample = resampleBuffer[sampleFrac + 2]; + int envelopeValue = voice.envelope.GetHeight(); + envelopeValue = ((envelopeValue >> 15) + 1) >> 1; + sample = sample * envelopeValue >> 15; + mixBuffer[i * 2] += sample * voice.volumeLeft >> 15; + mixBuffer[i * 2 + 1] += sample * voice.volumeRight >> 15; + sendBuffer[i * 2] += sample * voice.volumeLeftSend >> 15; + sendBuffer[i * 2 + 1] += sample * voice.volumeRightSend >> 15; + voice.envelope.Step(); + } + voice.sampleFrac = sampleFrac; + voice.sampleFrac -= numSamples ; + if (voice.envelope.HasEnded()) { + NOTICE_LOG(SAS, "Hit end of envelope"); + voice.playing = false; + } } else if (voice.type == VOICETYPE_NOISE && voice.noiseFreq != 0) { // Generate noise? From b07fe9da46da6be4c8ac09700ce193f5dc9b50a3 Mon Sep 17 00:00:00 2001 From: raven02 Date: Tue, 12 Mar 2013 12:17:19 +0800 Subject: [PATCH 2/2] Should be good enough to remove now as we already identifed games use sceSasSetVoicePCM() --- Core/HLE/sceSas.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index f92b9cbe81ee..17b0eb1155a0 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -143,7 +143,7 @@ u32 sceSasSetVoice(u32 core, int voiceNum, u32 vagAddr, int size, int loop) { u32 sceSasSetVoicePCM(u32 core, int voiceNum, u32 pcmAddr, int size, int loop) { - INFO_LOG(HLE,"PLEASE REPORT issue #505 sceSasSetVoicePCM(%08x, %i, %08x, %i, %i)", core, voiceNum, pcmAddr, size, loop); + INFO_LOG(HLE,"sceSasSetVoicePCM(%08x, %i, %08x, %i, %i)", core, voiceNum, pcmAddr, size, loop); Reporting::ReportMessage("sceSasSetVoicePCM(%x, %i)", core, voiceNum); if (voiceNum >= PSP_SAS_VOICES_MAX || voiceNum < 0) { @@ -162,12 +162,13 @@ u32 sceSasSetVoicePCM(u32 core, int voiceNum, u32 pcmAddr, int size, int loop) } SasVoice &v = sas->voices[voiceNum]; + u32 prevPcmAddr = v.pcmAddr; v.type = VOICETYPE_PCM; v.pcmAddr = pcmAddr; v.pcmSize = size; v.loop = loop ? false : true; v.playing = true; - v.ChangedParams(true); + v.ChangedParams(pcmAddr == prevPcmAddr); return 0; }