mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Correct envelope scaling in sas mixing.
Sound effects seem a bit loud, but this matches what JPCSP does and I've added comments based on my understanding of it. It makes sense. This makes all the sounds that never get muted when the envelope hits 0 go away. Hurray. Thanks to help from @i1x.
This commit is contained in:
parent
dd41d4a85c
commit
b7152c2f27
1 changed files with 5 additions and 3 deletions
|
@ -414,12 +414,14 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) {
|
|||
int sample = resampleBuffer[sampleFrac / PSP_SAS_PITCH_BASE + 2];
|
||||
sampleFrac += voice.pitch;
|
||||
|
||||
// Reduce envelope to 15 bits, rounding down.
|
||||
// The maximum envelope height (PSP_SAS_ENVELOPE_HEIGHT_MAX) is (1 << 30) - 1.
|
||||
// Reduce it to 14 bits, by shifting off 15. Round up by adding (1 << 14) first.
|
||||
int envelopeValue = voice.envelope.GetHeight();
|
||||
envelopeValue = ((envelopeValue >> 15) + 1) >> 1;
|
||||
envelopeValue = (envelopeValue + (1 << 14)) >> 15;
|
||||
|
||||
// We just scale by the envelope before we scale by volumes.
|
||||
sample = sample * (envelopeValue + 0x4000) >> 15;
|
||||
// Again, we round up by adding (1 << 14) first (*after* multiplying.)
|
||||
sample = ((sample * envelopeValue) + (1 << 14)) >> 15;
|
||||
|
||||
// We mix into this 32-bit temp buffer and clip in a second loop
|
||||
// Ideally, the shift right should be there too but for now I'm concerned about
|
||||
|
|
Loading…
Add table
Reference in a new issue