Smooth SAS resampling when pitch != 0x1000.

This commit is contained in:
Unknown W. Brackets 2014-02-17 14:09:35 -08:00
parent 8ded863231
commit 1efcebb121

View file

@ -474,7 +474,7 @@ void SasInstance::MixVoice(SasVoice &voice) {
voice.resampleHist[1] = resampleBuffer[2 + numSamples - 1];
// Resample to the correct pitch, writing exactly "grainSize" samples.
// This is a HORRIBLE resampler by the way.
// This is a poor resampler by the way.
// TODO: Special case no-resample case (and 2x and 0.5x) for speed, it's not uncommon
u32 sampleFrac = voice.sampleFrac;
@ -483,7 +483,11 @@ void SasInstance::MixVoice(SasVoice &voice) {
if (volumeShift < 0) volumeShift = 0;
for (int i = 0; i < grainSize; i++) {
// For now: nearest neighbour, not even using the resample history at all.
int sample = resampleBuffer[sampleFrac / PSP_SAS_PITCH_BASE + 2];
const int readIndex = sampleFrac / PSP_SAS_PITCH_BASE;
const int readFrac = sampleFrac % PSP_SAS_PITCH_BASE;
int sample1 = resampleBuffer[readIndex + 2];
int sample2 = resampleBuffer[readIndex + 1 + 2];
int sample = (sample1 * (PSP_SAS_PITCH_BASE - readFrac) + sample2 * readFrac) / PSP_SAS_PITCH_BASE;
sampleFrac += voice.pitch;
// The maximum envelope height (PSP_SAS_ENVELOPE_HEIGHT_MAX) is (1 << 30) - 1.
@ -505,10 +509,7 @@ void SasInstance::MixVoice(SasVoice &voice) {
voice.envelope.Step();
}
voice.sampleFrac = sampleFrac;
// Let's hope grainSize is a power of 2.
//voice.sampleFrac &= grainSize * PSP_SAS_PITCH_BASE - 1;
voice.sampleFrac -= numSamples * PSP_SAS_PITCH_BASE;
voice.sampleFrac = sampleFrac & (PSP_SAS_PITCH_BASE - 1);
if (voice.HaveSamplesEnded())
voice.envelope.End();