pcm/Normalizer: split the normalization loop

Performance improvement because the ramp code is now moved out of the
hot code path, allowing the compiler to vectorize.
This commit is contained in:
Max Kellermann 2023-03-13 13:31:46 +01:00
parent d7f2d90fd3
commit c0d38d941a

View File

@ -71,15 +71,19 @@ PcmNormalizer::ProcessS16(int16_t *gcc_restrict dest,
curGain = 1 << 10; curGain = 1 << 10;
const int delta = (newGain - curGain) / (int)ramp; const int delta = (newGain - curGain) / (int)ramp;
for (std::size_t i = 0; i < src.size(); i++) { for (const auto sample : src.first(ramp)) {
//! Amplify the sample //! Amplify the sample
*dest++ = PcmClamp<format>(src[i] * curGain >> 10); *dest++ = PcmClamp<format>(sample * curGain >> 10);
//! Adjust the gain //! Adjust the gain
if (i < ramp) curGain += delta;
curGain += delta; }
else
curGain = newGain; curGain = newGain;
for (const auto sample : src.subspan(ramp)) {
//! Amplify the sample
*dest++ = PcmClamp<format>(sample * curGain >> 10);
} }
pos = slot; pos = slot;