Selaa lähdekoodia

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.)
:^)
kleines Filmröllchen 3 vuotta sitten
vanhempi
commit
d50b1465c3
1 muutettua tiedostoa jossa 5 lisäystä ja 1 poistoa
  1. 5 1
      Userland/Libraries/LibAudio/FlacLoader.cpp

+ 5 - 1
Userland/Libraries/LibAudio/FlacLoader.cpp

@@ -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;