From 1aac569e73584e2a302fc8aefc36cc88e6cc382f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 1 Nov 2015 20:56:34 -0800 Subject: [PATCH] Sas: Add in zeroes like the PSP seems to. --- Core/HW/SasAudio.cpp | 22 +++++++++++++--------- Core/HW/SasReverb.cpp | 14 +++++++++++--- Core/HW/SasReverb.h | 1 + 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 19854e9924..7376c26d3b 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -391,11 +391,11 @@ void SasInstance::SetGrainSize(int newGrainSize) { mixBuffer = new s32[grainSize * 2]; sendBuffer = new s32[grainSize * 2]; sendBufferDownsampled = new s16[grainSize]; - sendBufferProcessed = new s16[grainSize]; + sendBufferProcessed = new s16[grainSize * 2]; memset(mixBuffer, 0, sizeof(int) * grainSize * 2); memset(sendBuffer, 0, sizeof(int) * grainSize * 2); memset(sendBufferDownsampled, 0, sizeof(s16) * grainSize); - memset(sendBufferProcessed, 0, sizeof(s16) * grainSize); + memset(sendBufferProcessed, 0, sizeof(s16) * grainSize * 2); // 2 samples padding at the start, that's where we copy the two last samples from the channel // so that we can do bicubic resampling if necessary. Plus 1 for smoothness hackery. @@ -618,8 +618,8 @@ void SasInstance::WriteMixedOutput(s16 *outp, const s16 *inp, int leftVol, int r sampleR += mixBuffer[i + 1]; } if (wet) { - sampleL += sendBufferProcessed[((i >> 1) & ~1) + 0]; - sampleR += sendBufferProcessed[((i >> 1) & ~1) + 1]; + sampleL += sendBufferProcessed[i + 0]; + sampleR += sendBufferProcessed[i + 1]; } *outp++ = clamp_s16(sampleL); *outp++ = clamp_s16(sampleR); @@ -628,8 +628,8 @@ void SasInstance::WriteMixedOutput(s16 *outp, const s16 *inp, int leftVol, int r // These are the optimal cases. if (dry && wet) { for (int i = 0; i < grainSize * 2; i += 2) { - *outp++ = clamp_s16(mixBuffer[i + 0] + sendBufferProcessed[((i >> 1) & ~1) + 0]); - *outp++ = clamp_s16(mixBuffer[i + 1] + sendBufferProcessed[((i >> 1) & ~1) + 1]); + *outp++ = clamp_s16(mixBuffer[i + 0] + sendBufferProcessed[i + 0]); + *outp++ = clamp_s16(mixBuffer[i + 1] + sendBufferProcessed[i + 1]); } } else if (dry) { for (int i = 0; i < grainSize * 2; i += 2) { @@ -637,13 +637,17 @@ void SasInstance::WriteMixedOutput(s16 *outp, const s16 *inp, int leftVol, int r *outp++ = clamp_s16(mixBuffer[i + 1]); } } else { - // This is another uncommon case, dry must be off. + // This is another uncommon case, dry must be off but let's keep it for clarity. for (int i = 0; i < grainSize * 2; i += 2) { int sampleL = 0; int sampleR = 0; + if (dry) { + sampleL += mixBuffer[i + 0]; + sampleR += mixBuffer[i + 1]; + } if (wet) { - sampleL += sendBufferProcessed[((i >> 1) & ~1) + 0]; - sampleR += sendBufferProcessed[((i >> 1) & ~1) + 1]; + sampleL += sendBufferProcessed[i + 0]; + sampleR += sendBufferProcessed[i + 1]; } *outp++ = clamp_s16(sampleL); *outp++ = clamp_s16(sampleR); diff --git a/Core/HW/SasReverb.cpp b/Core/HW/SasReverb.cpp index aa7fef242b..7b98dcfc2e 100644 --- a/Core/HW/SasReverb.cpp +++ b/Core/HW/SasReverb.cpp @@ -210,7 +210,13 @@ void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inpu // This means replicate the input signal in the processed buffer. // Can also be used to verify that the error is in here... if (preset_ == -1) { - memcpy(output, input, inputSize * 2 * sizeof(int16_t)); + // Strangely, OFF is not filled with zeroes every other. Seems special cased. + for (size_t i = 0; i < inputSize; ++i) { + output[i * 4 + 0] = clamp_s16(input[i * 2 + 0] * volLeft >> 15); + output[i * 4 + 1] = clamp_s16(input[i * 2 + 1] * volRight >> 15); + output[i * 4 + 2] = clamp_s16(input[i * 2 + 0] * volLeft >> 15); + output[i * 4 + 3] = clamp_s16(input[i * 2 + 1] * volRight >> 15); + } return; } @@ -250,8 +256,10 @@ void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inpu b[d.mRAPF2] = clamp_s16(Rout - (d.vAPF2*b[(d.mRAPF2 - d.dAPF2)] >> 15)); Rout = b[(d.mRAPF2 - d.dAPF2)] + (b[d.mRAPF2] * d.vAPF2 >> 15); // ___Output to Mixer(Output volume multiplied with input from APF2)___________ - output[i*2] = clamp_s16(Lout*volLeft >> 15); - output[i*2+1] = clamp_s16(Rout*volRight >> 15); + output[i * 4 + 0] = clamp_s16(Lout * volLeft >> 15); + output[i * 4 + 1] = clamp_s16(Rout * volRight >> 15); + output[i * 4 + 2] = 0; + output[i * 4 + 3] = 0; b.Next(); } diff --git a/Core/HW/SasReverb.h b/Core/HW/SasReverb.h index a22fc26d3a..10fcc3d674 100644 --- a/Core/HW/SasReverb.h +++ b/Core/HW/SasReverb.h @@ -30,6 +30,7 @@ public: static const char *GetPresetName(int preset); // Input should be a mixdown of all the channels that have reverb enabled, at 22khz. + // Output is written back at 44khz. void ProcessReverb(int16_t *output, const int16_t *input, size_t inputSize, int16_t volLeft, int16_t volRight); private: