mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +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
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…
Add table
Add a link
Reference in a new issue