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.
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).
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.
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.
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.
By moving the energy floor to the encoder, we can use a different
floor for prediction than for the decay level. Also, the fixed-point
dynamic range has been increased to avoid overflows when a fixed-point
decoder is used on a stream encoded in floating-point.
We were always storing collapse_masks[i*C+1], which could have
overflowed the buffer on the last band in mono.
This also moves the stores outside the conditional, which allows
common code to be used for masking the high bits, address
generation, etc.