Replace while loop with division (technically a right shift).

This commit is contained in:
Henrik Rydgard 2016-12-20 22:02:40 +01:00
parent ff4b99dd97
commit 1e095951dd
2 changed files with 7 additions and 13 deletions

View file

@ -495,23 +495,16 @@ void SasInstance::MixVoice(SasVoice &voice) {
// Resample to the correct pitch, writing exactly "grainSize" samples.
// TODO: Special case no-resample case (and 2x and 0.5x) for speed, it's not uncommon
int16_t temp[256 * 4];
int tempPos = 0;
int16_t temp[PSP_SAS_MAX_GRAIN + 2];
// Two passes: First read, then resample.
u32 sampleFrac = voice.sampleFrac;
temp[tempPos++] = voice.resampleHist[0];
temp[tempPos++] = voice.resampleHist[1];
temp[0] = voice.resampleHist[0];
temp[1] = voice.resampleHist[1];
int samplesToRead = 0;
uint32_t t = sampleFrac + voice.pitch * (grainSize - delay);
while (t >= PSP_SAS_PITCH_BASE) {
samplesToRead++;
t -= PSP_SAS_PITCH_BASE;
}
voice.ReadSamples(&temp[tempPos], samplesToRead);
tempPos += samplesToRead;
int samplesToRead = (sampleFrac + voice.pitch * (grainSize - delay)) >> PSP_SAS_PITCH_BASE_SHIFT;
voice.ReadSamples(&temp[2], samplesToRead);
int tempPos = 2 + samplesToRead;
for (int i = delay; i < grainSize; i++) {
const int16_t *s = temp + (sampleFrac >> PSP_SAS_PITCH_BASE_SHIFT);

View file

@ -38,6 +38,7 @@ enum {
PSP_SAS_PITCH_MAX = 0x4000,
PSP_SAS_VOL_MAX = 0x1000,
PSP_SAS_MAX_GRAIN = 1024, // VERY conservative! 256 is quite common but don't think I've ever seen bigger.
PSP_SAS_ADSR_CURVE_MODE_LINEAR_INCREASE = 0,
PSP_SAS_ADSR_CURVE_MODE_LINEAR_DECREASE = 1,