1. 03 Feb, 2011 1 commit
    • Timothy B. Terriberry's avatar
      Fix collapse mask tracking for recombine steps. · 57854e81
      Timothy B. Terriberry authored
      The recombine loop for cm was correct if one started at 1 block,
       but was wrong otherwise (for a test case, convert 2 recombined
       blocks back to 4 with an initial cm of 0x3; the result should be
       0xF, but instead you get 0x7).
      The recombine loop for fill was always wrong (for a test case,
       combine 8 blocks down to 1 with an initial fill=0xFE; the low bit
       remains unset).
      This now properly interleaves and deinterleaves bits for these
       steps, which avoids declaring collapses (and skipping folding)
       where none, in fact, occurred.
  2. 01 Feb, 2011 3 commits
    • Jean-Marc Valin's avatar
      Tuning the split threshold · 263e2719
      Jean-Marc Valin authored
    • Timothy B. Terriberry's avatar
      Add a seprate qtheta offset for two-phase stereo. · 411a84fa
      Timothy B. Terriberry authored
      9b34bd83 caused serious regressions for 240-sample frame stereo,
       because the previous qb limit was _always_ hit for two-phase
      Two-phase stereo really does operate with a different model (for
       example, the single bit allocated to the side should really
       probably be thought of as a sign bit for qtheta, but we don't
       count it as part of qtheta's allocation).
      The old code was equivalent to a separate two-phase offset of 12,
       however Greg Maxwell's testing demonstrates that 16 performs
    • Timothy B. Terriberry's avatar
      Adjust the splitting threshold. · 4499263b
      Timothy B. Terriberry authored
      Previously, we would only split a band if it was allocated more than
       32 bits.
      However, the N=4 codebook can only produce about 22.5 bits, and two
       N=2 bands combined can only produce 26 bits, including 8 bits for
       qtheta, so if we wait until we allocate 32, we're guaranteed to fall
      Several of the larger bands come pretty far from filling 32 bits as
       well, though their split versions will.
      Greg Maxwell also suggested adding an offset to the threshold to
       account for the inefficiency of using qtheta compared to another
       VQ dimension.
      This patch uses 1 bit as a placeholder, as it's a clear
       improvement, but we may adjust this later after collecting data on
       more possibilities over more files.
  3. 31 Jan, 2011 3 commits
    • Timothy B. Terriberry's avatar
      Don't destroy stereo history when switching to mono. · 682b6cf1
      Timothy B. Terriberry authored
      The first version of the mono decoder with stereo output collapsed
       the historic energy values stored for anti-collapse down to one
       channel (by taking the max).
      This means that a subsequent switch back would continue on using
       the the maximum of the two values instead of the original history,
       which would make anti-collapse produce louder noise (and
       potentially more pre-echo than otherwise).
      This patch moves the max into the anti_collapse function itself,
       and does not store the values back into the source array, so the
       full stereo history is maintained if subsequent frames switch
      It also fixes an encoder mismatch, which never took the max
       (assuming, apparently, that the output channel count would never
    • Timothy B. Terriberry's avatar
      Propagate balance from compute_allocation() to quant_all_bands(). · 948d27c9
      Timothy B. Terriberry authored
      Instead of just dumping excess bits into the first band after
       allocation, use them to initialize the rebalancing loop in
      This allows these bits to be redistributed over several bands, like
    • Jean-Marc Valin's avatar
  4. 29 Jan, 2011 1 commit
    • Timothy B. Terriberry's avatar
      Change qb cap to prevent side-fold collapses. · 9b34bd83
      Timothy B. Terriberry authored
      Previously, in a stereo split with itheta==16384, but without
       enough bits left over to actually code a pulse, the target band
       would completely collapse, because the mid gain would be zero and
       we don't fold the side.
      This changes the limit to ensure that we never set qn>1 unless we
       know we'll have enough bits for at least one pulse.
      This should eliminate the last possible whole-band collapse.
  5. 28 Jan, 2011 1 commit
  6. 27 Jan, 2011 6 commits
    • Jean-Marc Valin's avatar
      Making rebalance a celt_int32 · a9285720
      Jean-Marc Valin authored
    • Jean-Marc Valin's avatar
      Reducing waste at high bit-rate · 8ca16121
      Jean-Marc Valin authored
      We now encode the highest bitrate part of the split first and transfer
      any unused bits to the other part. We use a dead zone of three bits
      to prevent redistributing in cases of random fluctuation (or else
      we will statistically lower the allocation of higher frequencies at
      low-mid bitrates).
    • Jean-Marc Valin's avatar
      Fixes fixed-point overflow on really low energy · 79afa9c6
      Jean-Marc Valin authored
      Makes celt_exp2() use Q10 input to avoid problems on very low energy.
      Also makes the pitch downsampling more conservative on gain to avoid
      problems later.
    • Jean-Marc Valin's avatar
    • Timothy B. Terriberry's avatar
    • Timothy B. Terriberry's avatar
      More anti-collapse fixes, as well as a fold fix. · a396e153
      Timothy B. Terriberry authored
      This changes folding so that the LCG is never used on transients
       (either short blocks or long blocks with increased time
       resolution), except in the case that there's not enough decoded
       spectrum to fold yet.
      It also now only subtracts the anti-collapse bit from the total
       allocation in quant_all_bands() when space has actually been
       reserved for it.
      Finally, it cleans up some of the fill and collapse_mask tracking
       (this tracking was originally made intentionally sloppy to save
       work, but then converted to replace the existing fill flag at the
       last minute, which can have a number of logical implications).
      The changes, in particular:
      1) Splits of less than a block now correctly mark the second half
          as filled only if the whole block was filled (previously it
          would also mark it filled if the next block was filled).
      2) Splits of less than a block now correctly mark a block as
          un-collapsed if either half was un-collapsed, instead of marking
          the next block as un-collapsed when the high half was.
      3) The N=2 stereo special case now keeps its fill mask even when
          itheta==16384; previously this would have gotten cleared,
          despite the fact that we fold into the side in this case.
      4) The test against fill for folding now only considers the bits
          corresponding to the current set of blocks.
         Previously it would still fold if any later block was filled.
      5) The collapse mask used for the LCG fold data is now correctly
          initialized when B=16 on platforms with a 16-bit int.
      6) The high bits on a collapse mask are now cleared after the TF
          resolution changes and interleaving at level 0, instead of
          waiting until the very end.
         This prevents extraneous high flags set on mid from being mixed
          into the side flags for mid-side stereo.
  7. 26 Jan, 2011 1 commit
    • Jean-Marc Valin's avatar
      anti-collapse tuning · 9ce95e0b
      Jean-Marc Valin authored
      Using the min energy of the two last non-transient frames rather
      than the min of just the two last frames. Also slightly increasing
      the "thresh" upper bound coefficient to 0.5.
  8. 25 Jan, 2011 1 commit
  9. 24 Jan, 2011 1 commit
  10. 23 Jan, 2011 4 commits
  11. 21 Jan, 2011 4 commits
  12. 20 Jan, 2011 2 commits
    • Jean-Marc Valin's avatar
      Fixes an irrelevant uninitialized bug · e8a373fd
      Jean-Marc Valin authored
    • Timothy B. Terriberry's avatar
      Make collapse-detection bitexact. · 21af73eb
      Timothy B. Terriberry authored
      Jean-Marc's original anti-collapse patch used a threshold on the
       content of a decoded band to determine whether or not it should
       be filled with random noise.
      Since this is highly sensitive to the accuracy of the
       implementation, it could lead to significant decoder output
       differences even if decoding error up to that point was relatively
      This patch detects collapsed bands from the output of the vector
       quantizer, using exact integer arithmetic.
      It makes two simplifying assumptions:
       a) If either input to haar1() is non-zero during TF resolution
           adjustments, then the output will be non-zero.
       b) If the content of a block is non-zero in any of the bands that
           are used for folding, then the folded output will be non-zero.
      b) in particular is likely to be false when SPREAD_NONE is used.
      It also ignores the case where mid and side are orthogonal in
       stereo_merge, but this is relatively unlikely.
      This misses just over 3% of the cases that Jean-Marc's anti-collapse
       detection strategy would catch, but does not mis-classify any (all
       detected collapses are true collapses).
      This patch overloads the "fill" parameter to mark which blocks have
       non-zero content for folding.
      As a consequence, if a set of blocks on one side of a split has
       collapsed, _no_ folding is done: the result would be zero anyway,
       except for short blocks with SPREAD_AGGRESSIVE that are split down
       to a single block, but a) that means a lot of bits were available
       so a collapse is unlikely and b) anti-collapse can fill the block
       anyway, if it's used.
      This also means that if itheta==0 or itheta==16384, we no longer
       fold at all on that side (even with long blocks), since we'd be
       multiplying the result by zero anyway.
  13. 18 Jan, 2011 1 commit
    • Jean-Marc Valin's avatar
      Adds an anti-collapse mechanism for transients · 87efe1df
      Jean-Marc Valin authored
      This looks for bands in each short block that have no energy. For
      each of these "collapsed" bands, noise is injected to have an
      energy equal to the minimum of the two previous frames for that band.
      The mechanism can be used whenever there are 4 or more MDCTs (otherwise
      no complete collapse is possible) and is signalled with one bit just
      before the final fine energy bits.
  14. 17 Jan, 2011 1 commit
  15. 13 Jan, 2011 3 commits
    • Jean-Marc Valin's avatar
      Minor code cleanup, nothing to see here · f0d828fc
      Jean-Marc Valin authored
    • Jean-Marc Valin's avatar
      Proper scaling for the mid folding · a387ebfc
      Jean-Marc Valin authored
      Nor scaling the mid only after we've been able to store it
      for folding.
    • Timothy B. Terriberry's avatar
      Replace log2_frac in the delta offset calculation. · 173774bb
      Timothy B. Terriberry authored
      Adds a new bitexact_log2tan() function which is much simpler, and
       more accurate.
      The new approximation has an RMS error of 0.0038 bits from the
       correctly rounded result over the range of inputs we use, compared
       to an RMS error of 0.013 for the old log2_frac() method.
      The actual computation of delta is also changed to use FRAC_MUL16,
       since this allows us to keep the full accuracy of the new method
       while avoiding 16-bit overflow.
      The old delta computation actually could overflow 16 bits: it needed
       8 for the log2_frac() result, 1 for the sign of the difference, and
       8 more for N.
  16. 11 Jan, 2011 3 commits
  17. 10 Jan, 2011 4 commits