1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:58:11 +00:00

LibAudio: Add explanatory comments to the FlacLoader

Some nuances in the FLAC loading code can do well with an explanation,
as these non-obvious insights are often the result of long and painful
debugging and nobody should touch the affected code without careful
deliberation.

(Of course, secretly I just want people to maintain my loader code.)
:^)
This commit is contained in:
kleines Filmröllchen 2021-11-15 23:00:09 +01:00 committed by Linus Groh
parent 8af97d0ce7
commit d50b1465c3

View file

@ -682,13 +682,17 @@ Vector<i32> FlacLoaderPlugin::decode_custom_lpc(FlacSubframeHeader& subframe, In
dbgln_if(AFLACLOADER_DEBUG, "{}-bit {} shift coefficients: {}", lpc_precision, lpc_shift, coefficients);
// decode residual
// FIXME: This order may be incorrect, the LPC is applied to the residual, probably leading to incorrect results.
decoded = decode_residual(decoded, subframe, bit_input);
// approximate the waveform with the predictor
for (size_t i = subframe.order; i < m_current_frame->sample_count; ++i) {
// (see below)
i64 sample = 0;
for (size_t t = 0; t < subframe.order; ++t) {
// It's really important that we compute in 64-bit land here.
// Even though FLAC operates at a maximum bit depth of 32 bits, modern encoders use super-large coefficients for maximum compression.
// These will easily overflow 32 bits and cause strange white noise that apruptly stops intermittently (at the end of a frame).
// The simple fix of course is to do intermediate computations in 64 bits.
sample += static_cast<i64>(coefficients[t]) * static_cast<i64>(decoded[i - t - 1]);
}
decoded[i] += sample >> lpc_shift;