mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:28:11 +00:00
LibAudio: Prevent overflow in QOA LMS prediction
This commit is contained in:
parent
ede8582def
commit
24f5914d18
1 changed files with 4 additions and 3 deletions
|
@ -38,10 +38,11 @@ LMSState::LMSState(u64 history_packed, u64 weights_packed)
|
||||||
|
|
||||||
i32 LMSState::predict() const
|
i32 LMSState::predict() const
|
||||||
{
|
{
|
||||||
i32 prediction = 0;
|
// The spec specifies that overflows are not allowed, but we do a safe thing anyways.
|
||||||
|
Checked<i32> prediction = 0;
|
||||||
for (size_t i = 0; i < lms_history; ++i)
|
for (size_t i = 0; i < lms_history; ++i)
|
||||||
prediction += history[i] * weights[i];
|
prediction.saturating_add(Checked<i32>::saturating_mul(history[i], weights[i]));
|
||||||
return prediction >> 13;
|
return prediction.value() >> 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LMSState::update(i32 sample, i32 residual)
|
void LMSState::update(i32 sample, i32 residual)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue