mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Revert "More minor SasAudio optimizations"
Will reapply later in pieces.
This reverts commit cd251af345
.
This commit is contained in:
parent
9f5402ce54
commit
5f51432de7
2 changed files with 21 additions and 31 deletions
|
@ -396,7 +396,7 @@ void SasInstance::MixVoice(SasVoice &voice) {
|
||||||
// Actually this is not entirely correct - we need to get one extra sample, and store it
|
// Actually this is not entirely correct - we need to get one extra sample, and store it
|
||||||
// for the next time around. A little complicated...
|
// for the next time around. A little complicated...
|
||||||
// But for now, see Smoothness HACKERY below :P
|
// But for now, see Smoothness HACKERY below :P
|
||||||
u32 numSamples = (voice.sampleFrac + grainSize * voice.pitch) >> PSP_SAS_PITCH_SHIFT;
|
u32 numSamples = (voice.sampleFrac + grainSize * voice.pitch) / PSP_SAS_PITCH_BASE;
|
||||||
if ((int)numSamples > grainSize * 4) {
|
if ((int)numSamples > grainSize * 4) {
|
||||||
ERROR_LOG(SASMIX, "numSamples too large, clamping: %i vs %i", numSamples, grainSize * 4);
|
ERROR_LOG(SASMIX, "numSamples too large, clamping: %i vs %i", numSamples, grainSize * 4);
|
||||||
numSamples = grainSize * 4;
|
numSamples = grainSize * 4;
|
||||||
|
@ -421,7 +421,7 @@ void SasInstance::MixVoice(SasVoice &voice) {
|
||||||
if (volumeShift < 0) volumeShift = 0;
|
if (volumeShift < 0) volumeShift = 0;
|
||||||
for (int i = 0; i < grainSize; i++) {
|
for (int i = 0; i < grainSize; i++) {
|
||||||
// For now: nearest neighbour, not even using the resample history at all.
|
// For now: nearest neighbour, not even using the resample history at all.
|
||||||
int sample = resampleBuffer[(sampleFrac >> PSP_SAS_PITCH_SHIFT) + 2];
|
int sample = resampleBuffer[sampleFrac / PSP_SAS_PITCH_BASE + 2];
|
||||||
sampleFrac += voice.pitch;
|
sampleFrac += voice.pitch;
|
||||||
|
|
||||||
// The maximum envelope height (PSP_SAS_ENVELOPE_HEIGHT_MAX) is (1 << 30) - 1.
|
// The maximum envelope height (PSP_SAS_ENVELOPE_HEIGHT_MAX) is (1 << 30) - 1.
|
||||||
|
@ -446,7 +446,7 @@ void SasInstance::MixVoice(SasVoice &voice) {
|
||||||
voice.sampleFrac = sampleFrac;
|
voice.sampleFrac = sampleFrac;
|
||||||
// Let's hope grainSize is a power of 2.
|
// Let's hope grainSize is a power of 2.
|
||||||
//voice.sampleFrac &= grainSize * PSP_SAS_PITCH_BASE - 1;
|
//voice.sampleFrac &= grainSize * PSP_SAS_PITCH_BASE - 1;
|
||||||
voice.sampleFrac -= numSamples << PSP_SAS_PITCH_SHIFT;
|
voice.sampleFrac -= numSamples * PSP_SAS_PITCH_BASE;
|
||||||
|
|
||||||
if (voice.envelope.HasEnded())
|
if (voice.envelope.HasEnded())
|
||||||
{
|
{
|
||||||
|
@ -685,16 +685,16 @@ static int durationFromRate(int rate) {
|
||||||
|
|
||||||
const short expCurveReference = 0x7000;
|
const short expCurveReference = 0x7000;
|
||||||
|
|
||||||
const float expCurveToEnvelopeHeight = (float)PSP_SAS_ENVELOPE_HEIGHT_MAX / (float)expCurveReference;
|
|
||||||
|
|
||||||
// This needs a rewrite / rethink. Doing all this per sample is insane.
|
// This needs a rewrite / rethink. Doing all this per sample is insane.
|
||||||
static float computeExpCurveAt(int index, float invDuration) {
|
static int getExpCurveAt(int index, int duration) {
|
||||||
const int curveLength = ARRAY_SIZE(expCurve);
|
const short curveLength = sizeof(expCurve) / sizeof(short);
|
||||||
|
|
||||||
if (invDuration == 0.0f)
|
if (duration == 0) {
|
||||||
return 0.0f;
|
// Avoid division by zero, and thus undefined behaviour in conversion to int.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
float curveIndex = (index * curveLength) * invDuration;
|
float curveIndex = (index * curveLength) / (float) duration;
|
||||||
int curveIndex1 = (int) curveIndex;
|
int curveIndex1 = (int) curveIndex;
|
||||||
int curveIndex2 = curveIndex1 + 1;
|
int curveIndex2 = curveIndex1 + 1;
|
||||||
float curveIndexFraction = curveIndex - curveIndex1;
|
float curveIndexFraction = curveIndex - curveIndex1;
|
||||||
|
@ -705,7 +705,8 @@ static float computeExpCurveAt(int index, float invDuration) {
|
||||||
return expCurve[curveLength - 1];
|
return expCurve[curveLength - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return expCurve[curveIndex1] * (1.f - curveIndexFraction) + expCurve[curveIndex2] * curveIndexFraction;
|
float sample = expCurve[curveIndex1] * (1.f - curveIndexFraction) + expCurve[curveIndex2] * curveIndexFraction;
|
||||||
|
return (short)(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADSREnvelope::ADSREnvelope()
|
ADSREnvelope::ADSREnvelope()
|
||||||
|
@ -720,14 +721,11 @@ ADSREnvelope::ADSREnvelope()
|
||||||
releaseType(PSP_SAS_ADSR_CURVE_MODE_LINEAR_DECREASE),
|
releaseType(PSP_SAS_ADSR_CURVE_MODE_LINEAR_DECREASE),
|
||||||
state_(STATE_OFF),
|
state_(STATE_OFF),
|
||||||
steps_(0),
|
steps_(0),
|
||||||
height_(0),
|
height_(0) {
|
||||||
type_(0),
|
|
||||||
rate_(0),
|
|
||||||
invDuration_(0) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADSREnvelope::WalkCurve(int type) {
|
void ADSREnvelope::WalkCurve(int type) {
|
||||||
float expFactor;
|
short expFactor;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_LINEAR_INCREASE:
|
case PSP_SAS_ADSR_CURVE_MODE_LINEAR_INCREASE:
|
||||||
height_ += rate_;
|
height_ += rate_;
|
||||||
|
@ -746,14 +744,14 @@ void ADSREnvelope::WalkCurve(int type) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_DECREASE:
|
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_DECREASE:
|
||||||
expFactor = computeExpCurveAt(steps_, invDuration_);
|
expFactor = getExpCurveAt(steps_, duration_);
|
||||||
height_ = (s64)(expFactor * expCurveToEnvelopeHeight);
|
height_ = (s64)expFactor * PSP_SAS_ENVELOPE_HEIGHT_MAX / expCurveReference;
|
||||||
height_ = PSP_SAS_ENVELOPE_HEIGHT_MAX - height_;
|
height_ = PSP_SAS_ENVELOPE_HEIGHT_MAX - height_;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_INCREASE:
|
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_INCREASE:
|
||||||
expFactor = computeExpCurveAt(steps_, invDuration_);
|
expFactor = getExpCurveAt(steps_, duration_);
|
||||||
height_ = (s64)(expFactor * expCurveToEnvelopeHeight);
|
height_ = (s64)expFactor * PSP_SAS_ENVELOPE_HEIGHT_MAX / expCurveReference;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_DIRECT:
|
case PSP_SAS_ADSR_CURVE_MODE_DIRECT:
|
||||||
|
@ -789,14 +787,7 @@ void ADSREnvelope::SetState(ADSRState state) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_DECREASE:
|
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_DECREASE:
|
||||||
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_INCREASE:
|
case PSP_SAS_ADSR_CURVE_MODE_EXPONENT_INCREASE:
|
||||||
{
|
duration_ = durationFromRate(rate_);
|
||||||
int duration = durationFromRate(rate_);
|
|
||||||
if (duration == 0) {
|
|
||||||
invDuration_ = 0.0f;
|
|
||||||
} else {
|
|
||||||
invDuration_ = 1.0f / (float)duration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -33,7 +33,6 @@ enum {
|
||||||
PSP_SAS_PITCH_MIN = 1,
|
PSP_SAS_PITCH_MIN = 1,
|
||||||
PSP_SAS_PITCH_BASE = 0x1000,
|
PSP_SAS_PITCH_BASE = 0x1000,
|
||||||
PSP_SAS_PITCH_MAX = 0x4000,
|
PSP_SAS_PITCH_MAX = 0x4000,
|
||||||
PSP_SAS_PITCH_SHIFT = 12,
|
|
||||||
|
|
||||||
PSP_SAS_VOL_MAX = 0x1000,
|
PSP_SAS_VOL_MAX = 0x1000,
|
||||||
|
|
||||||
|
@ -173,7 +172,7 @@ private:
|
||||||
// No need to save in state
|
// No need to save in state
|
||||||
int rate_;
|
int rate_;
|
||||||
int type_;
|
int type_;
|
||||||
float invDuration_;
|
int duration_;
|
||||||
|
|
||||||
enum ADSRState {
|
enum ADSRState {
|
||||||
STATE_ATTACK,
|
STATE_ATTACK,
|
||||||
|
|
Loading…
Add table
Reference in a new issue