mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibAudio: Fix overflow on 24-bit FLAC LPC data
When computing sample values from a linear predictor, the repeated multiplication and addition can lead to very large values that may overflow a 32-bit integer. This was never discovered with 16-bit FLAC test files used to create and validate the first version of the FLAC loader. However, 24-bit audio, especially with large LPC shifts, will regularly exceed and overflow i32. Therefore, we now use 64 bits temporarily. If the resulting value is too large for 32 bits, something else has gone wrong :^) This fixes playback noise on 24-bit FLACs.
This commit is contained in:
parent
c974be91ab
commit
ba622cffe4
Notes:
sideshowbarker
2024-07-18 05:37:25 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/ba622cffe4f Pull-request: https://github.com/SerenityOS/serenity/pull/9461
1 changed files with 2 additions and 2 deletions
|
@ -675,9 +675,9 @@ Vector<i32> FlacLoaderPlugin::decode_custom_lpc(FlacSubframeHeader& subframe, In
|
|||
|
||||
// approximate the waveform with the predictor
|
||||
for (size_t i = subframe.order; i < m_current_frame->sample_count; ++i) {
|
||||
i32 sample = 0;
|
||||
i64 sample = 0;
|
||||
for (size_t t = 0; t < subframe.order; ++t) {
|
||||
sample += coefficients[t] * decoded[i - t - 1];
|
||||
sample += static_cast<i64>(coefficients[t]) * static_cast<i64>(decoded[i - t - 1]);
|
||||
}
|
||||
decoded[i] += sample >> lpc_shift;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue