SPU: Clamp before applying main volume not after
Fixes popping in Monkey Magic.
This commit is contained in:
parent
81f297456c
commit
634880b5e3
|
@ -749,23 +749,24 @@ void SPU::Execute(TickCount ticks)
|
||||||
|
|
||||||
// Compute reverb.
|
// Compute reverb.
|
||||||
s32 reverb_out_left, reverb_out_right;
|
s32 reverb_out_left, reverb_out_right;
|
||||||
ProcessReverb(Clamp16(reverb_in_left), Clamp16(reverb_in_right), &reverb_out_left, &reverb_out_right);
|
ProcessReverb(static_cast<s16>(Clamp16(reverb_in_left)), static_cast<s16>(Clamp16(reverb_in_right)),
|
||||||
|
&reverb_out_left, &reverb_out_right);
|
||||||
|
|
||||||
// Mix in reverb.
|
// Mix in reverb.
|
||||||
left_sum += reverb_out_left;
|
left_sum += reverb_out_left;
|
||||||
right_sum += reverb_out_right;
|
right_sum += reverb_out_right;
|
||||||
|
|
||||||
// Apply main volume before clamping.
|
// Apply main volume after clamping. A maximum volume should not overflow here because both are 16-bit values.
|
||||||
*(output_frame++) = Clamp16(ApplyVolume(left_sum, m_main_volume_left.current_level));
|
*(output_frame++) = static_cast<s16>(ApplyVolume(Clamp16(left_sum), m_main_volume_left.current_level));
|
||||||
*(output_frame++) = Clamp16(ApplyVolume(right_sum, m_main_volume_right.current_level));
|
*(output_frame++) = static_cast<s16>(ApplyVolume(Clamp16(right_sum), m_main_volume_right.current_level));
|
||||||
m_main_volume_left.Tick();
|
m_main_volume_left.Tick();
|
||||||
m_main_volume_right.Tick();
|
m_main_volume_right.Tick();
|
||||||
|
|
||||||
// Write to capture buffers.
|
// Write to capture buffers.
|
||||||
WriteToCaptureBuffer(0, cd_audio_left);
|
WriteToCaptureBuffer(0, cd_audio_left);
|
||||||
WriteToCaptureBuffer(1, cd_audio_right);
|
WriteToCaptureBuffer(1, cd_audio_right);
|
||||||
WriteToCaptureBuffer(2, Clamp16(m_voices[1].last_volume));
|
WriteToCaptureBuffer(2, static_cast<s16>(Clamp16(m_voices[1].last_volume)));
|
||||||
WriteToCaptureBuffer(3, Clamp16(m_voices[3].last_volume));
|
WriteToCaptureBuffer(3, static_cast<s16>(Clamp16(m_voices[3].last_volume)));
|
||||||
IncrementCaptureBufferPosition();
|
IncrementCaptureBufferPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -331,9 +331,9 @@ private:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr s16 Clamp16(s32 value)
|
static constexpr s32 Clamp16(s32 value)
|
||||||
{
|
{
|
||||||
return (value < -0x8000) ? -0x8000 : (value > 0x7FFF) ? 0x7FFF : static_cast<s16>(value);
|
return (value < -0x8000) ? -0x8000 : (value > 0x7FFF) ? 0x7FFF : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr s32 ApplyVolume(s32 sample, s16 volume) { return (sample * s32(volume)) >> 15; }
|
static constexpr s32 ApplyVolume(s32 sample, s16 volume) { return (sample * s32(volume)) >> 15; }
|
||||||
|
|
Loading…
Reference in New Issue