Timothy B. Terriberry [Mon, 31 Jan 2011 18:44:03 +0000 (10:44 -0800)]
Adjust the splitting threshold.
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
short.
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.
Jean-Marc Valin [Mon, 31 Jan 2011 22:34:46 +0000 (17:34 -0500)]
Including static_mode* files in the distribution
Jean-Marc Valin [Mon, 31 Jan 2011 22:30:15 +0000 (17:30 -0500)]
Stop collapsing the background noise channels when switching to mono
Timothy B. Terriberry [Mon, 31 Jan 2011 21:34:54 +0000 (13:34 -0800)]
Don't destroy stereo history when switching to mono.
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
back.
It also fixes an encoder mismatch, which never took the max
(assuming, apparently, that the output channel count would never
change).
Timothy B. Terriberry [Mon, 31 Jan 2011 20:28:12 +0000 (12:28 -0800)]
Propagate balance from compute_allocation() to quant_all_bands().
Instead of just dumping excess bits into the first band after
allocation, use them to initialize the rebalancing loop in
quant_all_bands().
This allows these bits to be redistributed over several bands, like
normal.
Jean-Marc Valin [Mon, 31 Jan 2011 18:41:01 +0000 (13:41 -0500)]
Fix sample type conversion when resampling
Jean-Marc Valin [Mon, 31 Jan 2011 18:27:21 +0000 (13:27 -0500)]
No longer extracting the frame size from the mode to build the header
Jean-Marc Valin [Mon, 31 Jan 2011 16:19:03 +0000 (11:19 -0500)]
Making the stereo encoder capable of encoding in mono
Jean-Marc Valin [Mon, 31 Jan 2011 15:51:30 +0000 (10:51 -0500)]
Making it possible for the stereo decoder to decode a mono stream
Timothy B. Terriberry [Mon, 31 Jan 2011 06:27:13 +0000 (22:27 -0800)]
Apply band caps to the band allocation table.
The average caps over all values of LM and C are well below the
target allocations of the last two modelines.
Lower them to the caps, to prevent hitting them quite so early.
This helps quality at medium-high rates, in the 180-192 kbps range.
Timothy B. Terriberry [Mon, 31 Jan 2011 06:18:12 +0000 (22:18 -0800)]
More band caps updates.
Use measured cross-entropy to estimate the real cost of coding
qtheta given the allocated qb parameter, instead of the entropy of
the PDF.
This is generally much lower, and reduces waste at high rates.
This patch also removes some intermediate rounding from this
computation.
Timothy B. Terriberry [Sun, 30 Jan 2011 08:12:31 +0000 (00:12 -0800)]
Add generic fine-energy rebalancing.
This extends the previous rebalancing for fine energy in N=1 bands
to also allocate extra fine bits for bands that go over their cap.
Jean-Marc Valin [Mon, 31 Jan 2011 04:38:28 +0000 (23:38 -0500)]
Custom and non-custom versions of the get_size() functions
Jean-Marc Valin [Mon, 31 Jan 2011 02:19:06 +0000 (21:19 -0500)]
Making sure that itheta=0 or 16384 really cuts allocation to one band
Jean-Marc Valin [Sun, 30 Jan 2011 17:15:12 +0000 (12:15 -0500)]
Merge branch 'exp_api_change'
Timothy B. Terriberry [Sat, 29 Jan 2011 20:57:18 +0000 (12:57 -0800)]
Use a smarter per-band bitrate cap.
The previous "dumb cap" of (64<<LM)*(C<<BITRES) was not actually
achievable by many (most) bands, and did not take the cost of
coding theta for splits into account, and so was too small for some
bands.
This patch adds code to compute a fairly accurate estimate of the
real maximum per-band rate (an estimate only because of rounding
effects and the fact that the bit usage for theta is variable),
which is then truncated and stored in an 8-bit table in the mode.
This gives improved quality at all rates over 160 kbps/channel,
prevents bits from being wasted all the way up to 255 kbps/channel
(the maximum rate allowed, and approximately the maximum number of
bits that can usefully be used regardless of the allocation), and
prevents dynalloc and trim from producing enormous waste
(eliminating the need for encoder logic to prevent this).
Jean-Marc Valin [Sun, 30 Jan 2011 15:23:40 +0000 (10:23 -0500)]
Error handling in _create() functions
Jean-Marc Valin [Sat, 29 Jan 2011 15:00:20 +0000 (10:00 -0500)]
Adding resampling support
We use the MDCT as low-pass filter.
Timothy B. Terriberry [Sat, 29 Jan 2011 06:20:59 +0000 (22:20 -0800)]
Change qb cap to prevent side-fold collapses.
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.
Jean-Marc Valin [Sat, 29 Jan 2011 04:07:32 +0000 (23:07 -0500)]
celt_encoder_create() now defaults to Opus standard mode
The old constructor is renamed celt_encoder_create_custom(). Same
for the decoder.
Jean-Marc Valin [Sat, 29 Jan 2011 03:42:09 +0000 (22:42 -0500)]
Enabling the standard static mode by default
Jean-Marc Valin [Sat, 29 Jan 2011 03:24:40 +0000 (22:24 -0500)]
Adding the auto-generated static modes for float and fixed
Jean-Marc Valin [Sat, 29 Jan 2011 01:56:56 +0000 (20:56 -0500)]
Using the actual degrees of freedom rather than N*C for fine offset
Gregory Maxwell [Fri, 28 Jan 2011 03:35:50 +0000 (22:35 -0500)]
Prevent VBR from shooting up to the maximum rate if set to very low target rates, and prevent the encoder VBR from producing 1 byte frames (which are no longer allowed).
Jean-Marc Valin [Fri, 28 Jan 2011 02:43:24 +0000 (21:43 -0500)]
Don't rebalance bits for itheta=0 or 16384
Jean-Marc Valin [Thu, 27 Jan 2011 23:44:26 +0000 (18:44 -0500)]
Making rebalance a celt_int32
Jean-Marc Valin [Thu, 27 Jan 2011 23:05:47 +0000 (18:05 -0500)]
Making anti-collapse a bit more conservative again
The energy memory can be lowered (not increased) during a transient
Jean-Marc Valin [Thu, 27 Jan 2011 22:19:49 +0000 (17:19 -0500)]
Changing some double constants to float
Jean-Marc Valin [Thu, 27 Jan 2011 22:14:33 +0000 (17:14 -0500)]
Adjusting post-filter coefficients to be exact in 13 bit precision.
That way they can be exact in 16 bits once multiplied by the gain
Jean-Marc Valin [Thu, 27 Jan 2011 22:01:59 +0000 (17:01 -0500)]
Adjusting pre-emphasis coefs to be exact in 16-bit precision
Jean-Marc Valin [Thu, 27 Jan 2011 21:51:20 +0000 (16:51 -0500)]
Using a real 16-bit value for the coarse beta on intra frames
Jean-Marc Valin [Thu, 27 Jan 2011 21:28:16 +0000 (16:28 -0500)]
Reducing waste at high bit-rate
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 [Thu, 27 Jan 2011 20:50:27 +0000 (15:50 -0500)]
Minor opus_compare fix
Jean-Marc Valin [Thu, 27 Jan 2011 20:47:15 +0000 (15:47 -0500)]
Comparison tool for decoder compliance
Jean-Marc Valin [Thu, 27 Jan 2011 15:46:01 +0000 (10:46 -0500)]
Fixes fixed-point overflow on really low energy
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 [Thu, 27 Jan 2011 14:53:09 +0000 (09:53 -0500)]
Fixes a fixed-point overflow in anti-collapse
Timothy B. Terriberry [Thu, 27 Jan 2011 04:32:53 +0000 (20:32 -0800)]
Improve accuracy of update_lowband test.
Jean-Marc Valin [Thu, 27 Jan 2011 03:04:59 +0000 (22:04 -0500)]
Only allowing silence in non-hybrid mode.
Also defining a 1-byte packet as triggering the PLC/CNG
Timothy B. Terriberry [Wed, 26 Jan 2011 07:05:04 +0000 (23:05 -0800)]
More anti-collapse fixes, as well as a fold fix.
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.
Jean-Marc Valin [Thu, 27 Jan 2011 01:30:21 +0000 (20:30 -0500)]
Setting bandE[] to zero after log2Amp when silence=1
Gregory Maxwell [Thu, 27 Jan 2011 01:19:01 +0000 (20:19 -0500)]
Fixes for silence handling in VBR mode, plus an encoder/decoder desync triggered by silent frames.
Jean-Marc Valin [Wed, 26 Jan 2011 18:09:53 +0000 (13:09 -0500)]
Removing more unused function params
Jean-Marc Valin [Wed, 26 Jan 2011 15:58:33 +0000 (10:58 -0500)]
Removes explicit filling of remaining bits with zeros
The initialiser already takes care of this
Jean-Marc Valin [Wed, 26 Jan 2011 15:50:55 +0000 (10:50 -0500)]
Removes unused function parameters
Jean-Marc Valin [Wed, 26 Jan 2011 15:00:28 +0000 (10:00 -0500)]
Should avoid running log2Amp on uninitialized data
Jean-Marc Valin [Wed, 26 Jan 2011 14:24:33 +0000 (09:24 -0500)]
Adding a special way to code digital silence in two or more bytes
Jean-Marc Valin [Wed, 26 Jan 2011 02:43:23 +0000 (21:43 -0500)]
Remove // comment
Jean-Marc Valin [Wed, 26 Jan 2011 00:12:06 +0000 (19:12 -0500)]
anti-collapse tuning
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.
Jean-Marc Valin [Tue, 25 Jan 2011 20:58:58 +0000 (15:58 -0500)]
Oops, fixed the sqrt(2) constant for anti_collapse()
Jean-Marc Valin [Tue, 25 Jan 2011 18:11:36 +0000 (13:11 -0500)]
Minimum period is now 15
Jean-Marc Valin [Mon, 24 Jan 2011 22:21:12 +0000 (17:21 -0500)]
Taking LM into account for anti-collapse
Timothy B. Terriberry [Mon, 24 Jan 2011 20:50:30 +0000 (12:50 -0800)]
Fix off-by-one error in ec_laplace_encode.
di_max was counting the _number_ of code-points remaining, not the
largest one that could be used.
Jean-Marc Valin [Mon, 24 Jan 2011 20:53:17 +0000 (15:53 -0500)]
Moving energy floor to coarse quantization
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.
Jean-Marc Valin [Sun, 23 Jan 2011 23:22:14 +0000 (18:22 -0500)]
Clipping the encoder input to +/-2 to prevent scaling errors
If someone messed up scaling, they'll know because it'll sound bad
Jean-Marc Valin [Sun, 23 Jan 2011 16:34:55 +0000 (11:34 -0500)]
prefilter/postfilter now forced off in Opus hybrid mode
Jean-Marc Valin [Sun, 23 Jan 2011 05:24:45 +0000 (00:24 -0500)]
Simple DTX/CNG implementation
Jean-Marc Valin [Sun, 23 Jan 2011 03:29:25 +0000 (22:29 -0500)]
Considering "badness" in two-pass quant_coarse_energy().
The most important thing is to not screw up the energy. Then we
compare the bit-rates.
Jean-Marc Valin [Sun, 23 Jan 2011 02:22:03 +0000 (21:22 -0500)]
Stop uselessly calling haar1() when resynth=0
This was computing on uninitialized data (though the result was never
used)
Gregory Maxwell [Sun, 23 Jan 2011 01:16:43 +0000 (20:16 -0500)]
Prevent out of bounds access to collapse_masks.
Gregory Maxwell [Sat, 22 Jan 2011 19:57:51 +0000 (14:57 -0500)]
Correct an encoder/decoder mismatch at low volume levels. Relax some low level clamps so that the dynamic range can extend further below the 16bit floor.
Jean-Marc Valin [Sat, 22 Jan 2011 19:48:20 +0000 (14:48 -0500)]
Tracking the background noise level
Also a fix for the zero-ing of unused band energies.
Jean-Marc Valin [Fri, 21 Jan 2011 23:41:48 +0000 (18:41 -0500)]
Defining merge_stereo() when S==-M or S==M
Timothy B. Terriberry [Fri, 21 Jan 2011 07:08:31 +0000 (23:08 -0800)]
Fix collapse_masks overflow for mono.
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.
Jean-Marc Valin [Fri, 21 Jan 2011 05:07:03 +0000 (00:07 -0500)]
Reorders some operations in anti-collapse to reuse values
Jean-Marc Valin [Fri, 21 Jan 2011 05:02:10 +0000 (00:02 -0500)]
Prevents taking the log of zero in fixed-point
Jean-Marc Valin [Fri, 21 Jan 2011 03:52:55 +0000 (22:52 -0500)]
Using previous range coder state for PRNG
This provides more entropy and allows some more flexibility on the
encoder side.
Jean-Marc Valin [Thu, 20 Jan 2011 01:47:01 +0000 (20:47 -0500)]
Fixes an irrelevant uninitialized bug
Timothy B. Terriberry [Tue, 18 Jan 2011 18:44:35 +0000 (10:44 -0800)]
Remove useless ec_dec_tell() call.
Timothy B. Terriberry [Thu, 20 Jan 2011 00:30:03 +0000 (16:30 -0800)]
Make collapse-detection bitexact.
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
small.
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.
Jean-Marc Valin [Tue, 18 Jan 2011 19:44:04 +0000 (14:44 -0500)]
Adds an anti-collapse mechanism for transients
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.
Jean-Marc Valin [Tue, 18 Jan 2011 01:50:18 +0000 (20:50 -0500)]
Moving the tapset signalling to the beginning of the stream
Jean-Marc Valin [Mon, 17 Jan 2011 21:37:51 +0000 (16:37 -0500)]
Adding tapset decision logic
Based on spreading_decision()'s logic. We choose tapsets
with less roll-off when we think the HF are tonal.
Jean-Marc Valin [Mon, 17 Jan 2011 16:37:08 +0000 (11:37 -0500)]
Support for multiple postfilter tapsets
Supporting three different tapsets with different roll-offs. The default
is now a 5-tap post-filter with a 13 kHz cutoff frequency.
Gregory Maxwell [Thu, 13 Jan 2011 19:38:24 +0000 (14:38 -0500)]
In CVBR mode the rate selection was failing to add bytes which were about to fall off the end of the bitres and never be reusable, causing undershoot.
Jean-Marc Valin [Thu, 13 Jan 2011 21:15:53 +0000 (16:15 -0500)]
Setting oldBandE to zero outside of [start,end[
In case start or end changes, we want the encoder and decoder
to be in sync and not do anything stupid.
Jean-Marc Valin [Thu, 13 Jan 2011 20:01:54 +0000 (15:01 -0500)]
Minor code cleanup, nothing to see here
Jean-Marc Valin [Thu, 13 Jan 2011 18:22:02 +0000 (13:22 -0500)]
Proper scaling for the mid folding
Nor scaling the mid only after we've been able to store it
for folding.
Timothy B. Terriberry [Thu, 13 Jan 2011 00:34:34 +0000 (16:34 -0800)]
Replace log2_frac in the delta offset calculation.
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.
Jean-Marc Valin [Wed, 12 Jan 2011 21:13:46 +0000 (16:13 -0500)]
Allowing the tf recombining to go all the way to LM=3
Jean-Marc Valin [Wed, 12 Jan 2011 16:27:03 +0000 (11:27 -0500)]
Fixes constrained VBR
Also removes the 8 byte/packet lower bound
Jean-Marc Valin [Wed, 12 Jan 2011 14:22:29 +0000 (09:22 -0500)]
Enforces bands of even size even for custom modes
Jean-Marc Valin [Tue, 11 Jan 2011 22:05:07 +0000 (17:05 -0500)]
Using a step pdf for the stereo itheta encoding
Jean-Marc Valin [Tue, 11 Jan 2011 14:42:28 +0000 (09:42 -0500)]
Minor fixes to testcases
David Schleef [Sun, 2 Jan 2011 04:03:10 +0000 (20:03 -0800)]
Add --export-symbols-regex
David Schleef [Sun, 2 Jan 2011 03:52:20 +0000 (19:52 -0800)]
MSVC build fixes
David Schleef [Sun, 2 Jan 2011 03:47:50 +0000 (19:47 -0800)]
Use more standard test for lrintf/lrint
Jean-Marc Valin [Tue, 11 Jan 2011 14:20:39 +0000 (09:20 -0500)]
Fixes the recombining stride and the deinterleaving stride
Previously, recombining only worked when going all the way back to
frequency domain.
Jean-Marc Valin [Tue, 11 Jan 2011 11:39:44 +0000 (06:39 -0500)]
Using intensity_stereo() when itheta==0
Jean-Marc Valin [Mon, 10 Jan 2011 18:21:04 +0000 (13:21 -0500)]
Defines MAX_FINE_BITS to ensure that we're using the same value everywhere
Jean-Marc Valin [Mon, 10 Jan 2011 17:45:01 +0000 (12:45 -0500)]
Using tell() rather than log2_frac() to compute qalloc
Jean-Marc Valin [Mon, 10 Jan 2011 15:52:51 +0000 (10:52 -0500)]
Changes the N=2 stereo case to use the same sign convention as N=1
Jean-Marc Valin [Mon, 10 Jan 2011 15:35:31 +0000 (10:35 -0500)]
Max delta: +/- 16384
Jean-Marc Valin [Mon, 10 Jan 2011 15:34:20 +0000 (10:34 -0500)]
32-bit fixes
Jean-Marc Valin [Mon, 10 Jan 2011 15:02:58 +0000 (10:02 -0500)]
Make LCG 16-bit clean
Timothy B. Terriberry [Mon, 10 Jan 2011 04:04:12 +0000 (20:04 -0800)]
Properly skip padding in testcelt for stereo.
The right amount of data was being written for the first frame, but
from the wrong offset in the buffer.
Timothy B. Terriberry [Fri, 7 Jan 2011 17:18:34 +0000 (09:18 -0800)]
Prevent busts at low bitrates.
This patch makes all symbols conditional on whether or not there's
enough space left in the buffer to code them, and eliminates much
of the redundancy in the side information.
A summary of the major changes:
* The isTransient flag is moved up to before the the coarse energy.
If there are not enough bits to code the coarse energy, the flag
would get forced to 0, meaning what energy values were coded
would get interpreted incorrectly.
This might not be the end of the world, and I'd be willing to
move it back given a compelling argument.
* Coarse energy switches coding schemes when there are less than 15
bits left in the packet:
- With at least 2 bits remaining, the change in energy is forced
to the range [-1...1] and coded with 1 bit (for 0) or 2 bits
(for +/-1).
- With only 1 bit remaining, the change in energy is forced to
the range [-1...0] and coded with one bit.
- If there is less than 1 bit remaining, the change in energy is
forced to -1.
This effectively low-passes bands whose energy is consistently
starved; this might be undesirable, but letting the default be
zero is unstable, which is worse.
* The tf_select flag gets moved back after the per-band tf_res
flags again, and is now skipped entirely when none of the
tf_res flags are set, and the default value is the same for
either alternative.
* dynalloc boosting is now limited so that it stops once it's given
a band all the remaining bits in the frame, or when it hits the
"stupid cap" of (64<<LM)*(C<<BITRES) used during allocation.
* If dynalloc boosing has allocated all the remaining bits in the
frame, the alloc trim parameter does not get encoded (it would
have no effect).
* The intensity stereo offset is now limited to the range
[start...codedBands], and thus doesn't get coded until after
all of the skip decisions.
Some space is reserved for it up front, and gradually given back
as each band is skipped.
* The dual stereo flag is coded only if intensity>start, since
otherwise it has no effect.
It is now coded after the intensity flag.
* The space reserved for the final skip flag, the intensity stereo
offset, and the dual stereo flag is now redistributed to all
bands equally if it is unused.
Before, the skip flag's bit was given to the band that stopped
skipping without it (usually a dynalloc boosted band).
In order to enable simple interaction between VBR and these
packet-size enforced limits, many of which are encountered before
VBR is run, the maximum packet size VBR will allow is computed at
the beginning of the encoding function, and the buffer reduced to
that size immediately.
Later, when it is time to make the VBR decision, the minimum packet
size is set high enough to ensure that no decision made thus far
will have been affected by the packet size.
As long as this is smaller than the up-front maximum, all of the
encoder's decisions will remain in-sync with the decoder.
If it is larger than the up-front maximum, the packet size is kept
at that maximum, also ensuring sync.
The minimum used now is slightly larger than it used to be, because
it also includes the bits added for dynalloc boosting.
Such boosting is shut off by the encoder at low rates, and so
should not cause any serious issues at the rates where we would
actually run out of room before compute_allocation().
Timothy B. Terriberry [Sun, 9 Jan 2011 06:11:46 +0000 (22:11 -0800)]
Fix Jean-Marc's sqrt(0.5) constants.
There were two different ones in use, one with less precision than
a float, and the other missing a digit in the middle.
Jean-Marc Valin [Sun, 9 Jan 2011 06:27:07 +0000 (01:27 -0500)]
Tuning the split allocation for temporal masking
Timothy B. Terriberry [Tue, 4 Jan 2011 18:26:15 +0000 (10:26 -0800)]
Use B0 instead of B for decisions in quant_band().
B contains the number of blocks _after_ splitting.
We were using it to decide a) when to use a uniform PDF instead of a
triangular one for theta and b) whether to bias the bit allocation
towards the lower bins.
Using B0 (the number of blocks before the split) instead for a)
gives a PEAQ gain of 0.003 ODG (as high as 0.1 ODG on s02a samples
006, 083, and 097) for 240-sample frames at 96kbps mono.
Using B0 instead for b) gives a gain of only 0.00002.
Timothy B. Terriberry [Tue, 4 Jan 2011 17:07:40 +0000 (09:07 -0800)]
Fix rounding in bits2pulses search.
The mid = (lo+hi)>>1 line in the binary search would allow hi to drop
down to the same value as lo, meaning the rounding after the search
would be choosing between the same two values.
This patch changes it to (lo+hi+1)>>1.
This will allow lo to increase up to the value hi, but only in the
case that we can't possibly allocate enough pulses to meet the
target number of bits (in which case the rounding doesn't matter).
To pay for the extra add, this moves the +1 in the comparison to bits
to the other side, which can then be taken outside the loop.
The compiler can't normally do this because it might cause overflow
which would change the results.
This rarely mattered, but gives a 0.01 PEAQ improvement on 12-byte
120 sample frames.
It also makes the search process describable with a simple
algorithm, rather than relying on this particular optimized
implementation.
I.e., the binary search loop can now be replaced with
for(lo=0;lo+1<cache[0]&&cache[lo+1]<bits;lo++);
hi=lo+1;
and it will give equivalent results.
This was not true before.