Commit graph

477 commits

Author SHA1 Message Date
Jean-Marc Valin
c39bb8ab8c Removes unused function parameters 2011-01-26 10:50:55 -05:00
Jean-Marc Valin
de79c378bd Adding a special way to code digital silence in two or more bytes 2011-01-26 09:24:33 -05:00
Jean-Marc Valin
9ce95e0bd0 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.
2011-01-25 19:12:06 -05:00
Jean-Marc Valin
d121260f38 Minimum period is now 15 2011-01-25 13:11:36 -05:00
Jean-Marc Valin
495114b755 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.
2011-01-24 15:53:17 -05:00
Jean-Marc Valin
3a56c9e1c6 prefilter/postfilter now forced off in Opus hybrid mode 2011-01-23 11:34:55 -05:00
Jean-Marc Valin
eafd8a7f17 Simple DTX/CNG implementation 2011-01-23 00:24:45 -05:00
Gregory Maxwell
8f02c482ba 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. 2011-01-22 19:50:36 -05:00
Jean-Marc Valin
5c2ac2b75d Tracking the background noise level
Also a fix for the zero-ing of unused band energies.
2011-01-22 14:48:20 -05:00
Jean-Marc Valin
63fb61f176 Using previous range coder state for PRNG
This provides more entropy and allows some more flexibility on the
encoder side.
2011-01-20 23:29:05 -05:00
Timothy B. Terriberry
a363e3952c Remove useless ec_dec_tell() call. 2011-01-19 20:24:37 -05:00
Timothy B. Terriberry
21af73eb21 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.
2011-01-19 19:43:08 -05:00
Jean-Marc Valin
87efe1df00 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.
2011-01-18 14:44:04 -05:00
Jean-Marc Valin
2ce5c63d22 Moving the tapset signalling to the beginning of the stream 2011-01-17 20:50:18 -05:00
Jean-Marc Valin
8d367029a7 Adding tapset decision logic
Based on spreading_decision()'s logic. We choose tapsets
with less roll-off when we think the HF are tonal.
2011-01-17 16:37:51 -05:00
Jean-Marc Valin
dfa847a25d 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.
2011-01-17 11:37:08 -05:00
Gregory Maxwell
d85018cb54 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. 2011-01-13 16:31:50 -05:00
Jean-Marc Valin
5677e34fde 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.
2011-01-13 16:15:53 -05:00
Jean-Marc Valin
2b13401fe6 Allowing the tf recombining to go all the way to LM=3 2011-01-12 16:13:46 -05:00
Jean-Marc Valin
6b565268fb Fixes constrained VBR
Also removes the 8 byte/packet lower bound
2011-01-12 11:27:03 -05:00
Timothy B. Terriberry
76469c64b4 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().
2011-01-09 02:06:53 -05:00
Timothy B. Terriberry
051e044d14 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.
2011-01-09 01:40:05 -05:00
Timothy B. Terriberry
845dfa1986 Changes to ec_dec_cdf() to support 8-bit tables.
This renames ec_dec_cdf() to ec_dec_icdf(), and changes the
 functionality to use an "inverse" CDF table, where
 icdf[i]=ft-cdf[i+1].
The first entry is omitted entirely.
It also adds a corresonding ec_enc_icdf() to the encoder, which uses
 the same table.
One could use ec_encode_bin() by converting the values in the tables
 back to normal CDF values, but the icdf[] table already has them in
 the form ec_encode_bin() wants to use them, so there's no reason to
 translate them and then translate them back.

This is done primarily to allow SILK to use the range coder with
 8-bit probability tables containing cumulative frequencies that
 span the full range 0...256.
With an 8-bit table, the final 256 of a normal CDF becomes 0 in the
 "inverse" CDF.
It's the 0 at the start of a normal CDF which would become 256, but
 this is the value we omit, as it already has to be special-cased in
 the encoder, and is not used at all in the decoder.
2011-01-08 14:57:01 -05:00
Timothy B. Terriberry
79d76a2e3a Code intensity offset relative to start.
The band where intensity stereo begins was being coded as an
 absolute value, rather than relative to start, even though the
 range of values in the bitstream was limited as if it was being
 coded relative to start (meaning there would be desync if
 intensity was sufficiently large).
2010-12-30 12:47:28 -05:00
Timothy B. Terriberry
d6f6157192 Make the dynalloc boost run over [start,end).
Previously it was coded for all bands, even when not all of them
 were being used.
2010-12-30 12:47:28 -05:00
Timothy B. Terriberry
8893e530fc Fix the limits for CELT_SET_END_BAND_REQUEST.
The valid bands range from [start,end) everywhere, with start<end.
Therefore end should never be 0, and should be allowed to extend
 all the way to mode->nbEBands.
This patch does _not_ enforce that start<end, and it does _not_
 handle clearing oldBandE[] when the valid range changes, which
 are separate issues.
2010-12-30 12:47:28 -05:00
Timothy B. Terriberry
509ad2086d Move tf_select before the tf_res bits.
The tf_res bits are useless without tf_select, so move it up before
 them.
This allows the tf_res bits to be interpreted directly as they're
 decoded.
2010-12-27 21:27:04 -05:00
Jean-Marc Valin
41a15e6ca5 Fixes tf_select_table[][] (missing commas) 2010-12-27 16:34:53 -05:00
Jean-Marc Valin
20e4c6a611 Removing FIXMEs that were fixed 2010-12-27 16:34:40 -05:00
Timothy B. Terriberry
1aaa50d1c1 Update ec_dec_cdf() to use an unsigned cdf[].
For our current usage, this doesn't matter, but is more consistent
 with the rest of the API.
We may want to reduce this to an unsigned char[], but I'd rather
 coordinate that optimization with SILK's planned reduction to
 8-bit CDFs, as we may be able to use the same code.
2010-12-21 21:00:41 -05:00
Jean-Marc Valin
7365c7d1b6 Don't enable the post-filter in Opus hybrid mode 2010-12-21 16:30:01 -05:00
Timothy B. Terriberry
30df6cf3f8 Entropy coder clean-up.
This simplifies a good bit of the error handling, and should make it
 impossible to overrun the buffer in the encoder or decoder, while
 still allowing tell() to operate correctly after a bust.
The encoder now tries to keep the range coder data intact after a
 bust instead of corrupting it with extra bits data, though this is
 not a guarantee (too many extra bits may have already been flushed).
It also now correctly reports errors when the bust occurs merging the
 last byte of range coder and extra bits.

A number of abstraction barrier violations were cleaned up, as well.
This patch also includes a number of minor performance improvements:
 ec_{enc|dec}_bits() in particular should be much faster.

Finally, tf_select was changed to be coded with the range coder
 rather than extra bits, so that it is at the front of the packet
 (for unequal error protection robustness).
2010-12-21 14:23:45 -05:00
Jean-Marc Valin
034efa523a Tuning the dynamic allocation probability and increment
Dynalloc becomes 2x more likely every time we use it, until it
reaches a probability of 1/4. Allocation increments now have
a floor of 1/8 bit/sample and a ceiling of 1 bit/sample.
2010-12-21 00:20:39 -05:00
Jean-Marc Valin
6ba0b350fb Being a bit more careful about enabling the post-filter 2010-12-20 11:40:30 -05:00
Timothy B. Terriberry
e86fb268b0 Replace ec_{enc|dec}_bit_prob() with ec_{enc|dec}_bit_logp().
All of our usage of ec_{enc|dec}_bit_prob had the probability of a
 "one" being a power of two.
This adds a new ec_{enc|dec}_bit_logp() function that takes this
 explicitly into account.
It introduces less rounding error than the bit_prob version, does not
 require 17-bit integers to be emulated by ec_{encode|decode}_bin(),
 and does not require any multiplies or divisions at all.
It is exactly equivalent to
 ec_encode_bin(enc,_val?0:(1<<_logp)-1,(1<<_logp)-(_val?1:0),1<<_logp)

The old ec_{enc|dec}_bit_prob functions are left in place for now,
 because I am not sure if SILK is still using them or not when
 combined in Opus.
2010-12-18 09:06:06 -05:00
Timothy B. Terriberry
a0b664df3d Add a generic CDF decoding routine.
This decodes a value encoded with ec_encode_bin() without using any
 divisions.
It is only meant for small alphabets.
If a symbol can take on a large number of possible values, a binary
 search would be better.

This patch also converts spread_decision to use it, since it is
 faster and introduces less rounding error to encode a single
 decision for the entire value than to encode it a bit at a time.
2010-12-17 14:21:43 -05:00
Jean-Marc Valin
f33a7fb8e0 Fixed the spreading probabilities (1-x) 2010-12-17 13:38:20 -05:00
Timothy B. Terriberry
320cf2e2cd Re-organize spreading/folding constants.
These were stored internally in one order and in the bitstream in a
 different order.
Both used bare constants, making it unclear what either actually
 meant.
This changes them to use the same order, gives them named constants,
 and renames all the "fold" decision stuff to "spread" instead,
 since that is what it is really controlling.
2010-12-17 10:35:51 -05:00
Jean-Marc Valin
cd84e3d0f4 Re-enabling post-filter on 2.5 ms frames
Also, now forcing MS stereo for 2.5 frames because the current
analysis isn't reliable.
2010-12-16 22:29:35 -05:00
Timothy B. Terriberry
76ea41e17f Give the bit we reserved to end skipping back when we don't use it.
Commit 8e447678 increased the number of cases where we end skipping
 without explicit signaling.
Before, this would cause the bit we reserved for this purpose to
 either a) get grabbed by some N=1 band to code its sign bits or
 b) wind up as part of the fine energy at the end.
This patch gives it back to the band where we stopped skipping,
 which is either the first band, or a band that was boosted by
 dynalloc.
This allows the bit to be used for shape coding in that band, and
 allows the better computation of the fine offset, since the band
 knows it will get that bit in advance.

With this change, we now guarantee that the number of bits allocated
 by compute_allocation() is exactly equal to the input total, less
 the bits consumed by skip flags during allocation itself (assuming
 total was non-negative; for negative total, no bits are emitted,
 and no bits are allocated).
2010-12-16 20:20:04 -05:00
Jean-Marc Valin
5c80391b35 Comments, low bit-rate busting avoidance 2010-12-16 14:11:48 -05:00
Timothy B. Terriberry
4777f06910 Store the total budget of compute_allocation in BITRES units.
The margin of safety was supposed to be 1/8th bit, not 1 bit, and the
 bit we reserved to terminate skip signalling before was actually 8
 bits.
This patch updates the margin of safety to the correct value and
 accounts for the one bit (not 8) needed for skip signalling.
It also fixes the remainder calculation in the skip loop to work
 correctly when start>0.
2010-12-15 10:04:45 -05:00
Timothy B. Terriberry
b2f59009f6 Move skip coding into interp_bits2pulses().
This allows us to a) not pay a coding cost to avoid skipping bands that are
 stupid to skip (e.g., the first band, or bands that have so few bits that we
 wouldn't redistribute anything) and b) not reserve bits to pay that cost.
2010-12-15 08:35:22 -05:00
Jean-Marc Valin
6cbfbc383a Tuning for 2.5 ms frames 2010-12-14 11:53:39 -05:00
Jean-Marc Valin
70d30ffc09 Using overlap=shortMdctSize even for 2.5 ms frames.
And fixed a post-filter bug for that special case.
2010-12-13 13:52:06 -05:00
Jean-Marc Valin
546dfa1959 Adapting the allocation trim based on the spectral tilt 2010-12-10 17:18:17 -05:00
Jean-Marc Valin
dfd6e714f9 Adding some hysteresis on the folding threshold frequency
This adds some side-information that can be used to change the
threshold freq arbitrarily.
2010-12-09 23:23:34 -05:00
Jean-Marc Valin
fddc521a5c Completely new transient analysis algorithm
Should be more robust to closely-spaced transients
2010-12-09 14:48:02 -05:00
Jean-Marc Valin
79b34eb83e Add API support for unconstrained VBR
celtenc now defaults to unconstrained VBR.
2010-12-05 17:22:06 -05:00
Jean-Marc Valin
9faf740882 Keeping the allocation of the intensity-codec bands
Also some code to select between constrained and unconstrained VBR
2010-12-04 10:27:22 -05:00