Commit graph

53 commits

Author SHA1 Message Date
Jean-Marc Valin
a66b7574f6 Defines MAX_FINE_BITS to ensure that we're using the same value everywhere 2011-01-10 13:21:04 -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
1cb32aa057 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.
2011-01-08 14:57:01 -05:00
Jean-Marc Valin
5c80391b35 Comments, low bit-rate busting avoidance 2010-12-16 14:11:48 -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
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
7fff572a8c Making sure we can use up to 128 pulses.
Previous limit was effectively 120.
2010-10-18 16:20:00 -04:00
Jean-Marc Valin
6bf04627b0 Allowing to change the allocation dynamically.
Uses a scaling factor that gets applied to the allocation matrix.

Conflicts:

	libcelt/celt.c
	libcelt/rate.c
	libcelt/rate.h
2010-09-30 10:16:22 -04:00
Jean-Marc Valin
b801da5e83 Preventing bands from being coded at a rate below (for now) 3/8 bit/sample 2010-09-28 14:56:20 -04:00
Jean-Marc Valin
5c0c936d8f Fine energy allocation cleanup 2010-08-31 10:11:11 -04:00
Jean-Marc Valin
f1c8fb1067 qoffset tuning 2010-08-31 06:45:32 -04:00
Jean-Marc Valin
32a1e6b6a3 More fine energy tuning, compensation for N=2 2010-08-30 23:35:02 -04:00
Jean-Marc Valin
fffae794ea New fine energy allocation tuning.
Based on 1/2*log2(N)-19/8, but with the 2-bit and 3-bit thresholds
shifted by 2*log2(N)/8 bit and log2(N)/8 bit, respectively.
2010-08-30 21:34:11 -04:00
Jean-Marc Valin
732ea38810 Updated static modes for new pulse cache.
Fixed a few minor bugs in the process.
2010-08-25 13:52:27 -04:00
Jean-Marc Valin
3ad8db49c5 New pulse cache 2010-08-25 13:11:09 -04:00
Jean-Marc Valin
360342824f Adaptive fine offset value 2010-08-06 14:42:43 -04:00
Jean-Marc Valin
88c59a534b QTHETA_OFFSET* tuning 2010-08-05 16:15:46 -04:00
Jean-Marc Valin
30e2493efa Allowing fractional bits for splitting angle (theta) 2010-08-05 09:16:52 -04:00
Jean-Marc Valin
fd3139cccf Separate qtheta offset for stereo 2010-07-29 12:51:06 +02:00
Jean-Marc Valin
37546cc3f6 Bit allocation
Also convert the stereo split code to use log(N)/2 as the bit allocation
offset
2010-07-27 22:39:15 +02:00
Timothy B. Terriberry
a345decd97 Adjust fine bits allocation.
The old code allocated too many fine bits to large bands.
New allocations were derived from by numerical optimization using quantization
 MSE sampled from Laplacian distributed random data to within +/- 1 bit for
 N=2...160 and bits per band from 0 to 64.
Those allocations could be modeled with only minor errors using a simple offset
 of 19/8+log2(N), with no bits spent on fine energy when there would not be
 enough bits remaining to code a single pulse.
However, PEAQ testing suggested an offset of 14/8 was better, and that it was
 always worth spending at least one bit on fine energy.
2010-07-27 21:35:43 +02:00
Jean-Marc Valin
bdfb73bc26 Just removing old code that was commented out anyway 2010-07-23 17:46:53 -04:00
Jean-Marc Valin
525d7cfdc4 Support for adjusting the end band 2010-07-13 18:18:23 -04:00
Jean-Marc Valin
6c37fb150c Changing the allocator resolution to 1/8 bit
Should eventually allow using 8-bit values for the pulse->bits table.
2010-06-02 21:25:19 -04:00
Jean-Marc Valin
2fcb239736 Removing the rest of the >32-bit PVQ code 2010-05-24 09:05:36 -04:00
Jean-Marc Valin
cae30df09a Getting rid of PVQ-level split
Adding one more level of band splitting so that splitting at the
PVQ encoding level is no longer necessary.
2010-05-21 00:26:03 -04:00
Jean-Marc Valin
c803ee1959 Entropy-coding the new split parameter.
Uses a triangular PDF for coding the angle.
2010-05-14 00:17:31 -04:00
Jean-Marc Valin
65ee67ac55 Making the band definition the same at all frame sizes. 2010-04-26 07:08:44 -04:00
Jean-Marc Valin
3a0bc3d95c Allowing CELT to skip the low frequencies 2010-02-25 22:46:55 -05:00
Jean-Marc Valin
8b2ff0da5a Updated copyright notices 2009-10-17 21:40:10 -04:00
Jean-Marc Valin
30f7f813ea Changed all the celt*int*_t types to remove the _t suffix, which is reserved
by POSIX. The other _t types that are not part of the API are still there
for now. Also, got rid of all that was left of the 64-bit types.
2009-10-17 14:35:13 -04:00
Jean-Marc Valin
bf2398b049 first step for removing the number of channels from the mode 2009-10-15 07:28:19 -04:00
Jean-Marc Valin
91f07dc125 Changing some code to use BITRES directly instead of its value. 2009-07-25 20:42:24 -04:00
Jean-Marc Valin
164a229644 Reducing the size of the pulses->bits cache by restricting the number of pulses
possible
2009-07-23 07:24:03 -04:00
Jean-Marc Valin
52cb5fb3f6 Adding extra fine bits only when we have rounded down in the allocation 2009-06-10 08:08:55 -04:00
Jean-Marc Valin
9a44cde205 Removed support for band-per-band stereo_mode that was never really used 2009-06-02 20:21:53 -04:00
Jean-Marc Valin
dcd580d7ab Disabling K>128 until it can be shown to be useful. 2009-06-02 08:02:41 -04:00
Jean-Marc Valin
2b73a27ece 1024 pulses ought to be enough for everybody 2009-05-27 00:05:27 -04:00
Jean-Marc Valin
5aaf12333e Enabling more than 128 pulses for N=3 and N=4. 2009-05-26 21:50:38 -04:00
Jean-Marc Valin
6f18d11148 Adds support for up to 32767 pulses for the N=3 case (disabled for now) 2009-05-22 07:45:58 -04:00
Jean-Marc Valin
7b0cb4ba0d One-at-a-time allocator now uses direct feedback from ec_*_tell(). 2008-09-11 00:20:08 -04:00
Jean-Marc Valin
ebf72da760 At least attempting to use all the bits. 2008-09-09 23:21:36 -04:00
Jean-Marc Valin
6775de3eae Unified allocation of fine energy and pulses. 2008-08-02 08:14:42 -04:00
Jean-Marc Valin
679083f449 Implemented split-cwrs for very large codebooks (>64 bits), but still getting
a few decoding errors.
2008-06-10 17:23:03 +10:00
Jean-Marc Valin
7bd2b9e001 More stereo infrastructure 2008-05-23 14:23:22 +10:00
Jean-Marc Valin
fe0b8e8db4 infrastructure changes for upcoming stereo improvements 2008-05-23 13:35:35 +10:00
Jean-Marc Valin
fed97d58b5 optimisation: changed some for() loops to do-while() to give the compiler
a hint that there has to be at least one iteration.
2008-03-26 21:31:56 +11:00
Jean-Marc Valin
0de9d8abec Making bits2pulses() use a fixed number of iterations to allow further
optimisations.
2008-03-24 17:06:08 +11:00
Jean-Marc Valin
b76ee70606 Allocation cache can now be pre-computed as well. 2008-03-10 15:42:35 +11:00
Jean-Marc Valin
879fbfd528 Updated Doxygen comments, removed an incorrectly placed LGPL header (we own
copyright, so it's fine!)
2008-02-20 17:17:13 +11:00