Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SasAudio: Implement linear interpolation #8950

Merged
merged 8 commits into from
Dec 20, 2016
19 changes: 6 additions & 13 deletions Core/HW/SasAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

int samplesToRead = 0;
uint32_t t = sampleFrac + voice.pitch * (grainSize - delay);
while (t >= PSP_SAS_PITCH_BASE) {
samplesToRead++;
t -= PSP_SAS_PITCH_BASE;
}
temp[0] = voice.resampleHist[0];
temp[1] = voice.resampleHist[1];

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);
Expand Down
1 change: 1 addition & 0 deletions Core/HW/SasAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

@unknownbrackets unknownbrackets Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__sceSasInit allows grainSize of 2048 at most, any higher values fail with ERROR_SAS_INVALID_GRAIN. But 2048 is allowed.

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, that's a pretty compelling argument. I'll change it.


PSP_SAS_ADSR_CURVE_MODE_LINEAR_INCREASE = 0,
PSP_SAS_ADSR_CURVE_MODE_LINEAR_DECREASE = 1,
Expand Down