Commit graph

1246 commits

Author SHA1 Message Date
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
f0d828fc14 Minor code cleanup, nothing to see here 2011-01-13 15:12:20 -05:00
Jean-Marc Valin
a387ebfc13 Proper scaling for the mid folding
Nor scaling the mid only after we've been able to store it
for folding.
2011-01-13 13:22:02 -05:00
Timothy B. Terriberry
173774bbf9 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.
2011-01-12 21:21:35 -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
Jean-Marc Valin
4420390799 Enforces bands of even size even for custom modes 2011-01-12 09:22:29 -05:00
Jean-Marc Valin
235c64b94d Using a step pdf for the stereo itheta encoding 2011-01-11 17:05:41 -05:00
David Schleef
da290c8899 Add --export-symbols-regex 2011-01-11 09:33:20 -05:00
Jean-Marc Valin
ecefde3d4a Fixes the recombining stride and the deinterleaving stride
Previously, recombining only worked when going all the way back to
frequency domain.
2011-01-11 09:20:39 -05:00
Jean-Marc Valin
8cfda4a301 Using intensity_stereo() when itheta==0 2011-01-11 06:56:18 -05:00
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
Jean-Marc Valin
9d2d0510a1 Using tell() rather than log2_frac() to compute qalloc 2011-01-10 12:45:01 -05:00
Jean-Marc Valin
d9f6ec3f04 Changes the N=2 stereo case to use the same sign convention as N=1 2011-01-10 10:52:51 -05:00
Jean-Marc Valin
c2095a2930 Max delta: +/- 16384 2011-01-10 10:35:31 -05:00
Jean-Marc Valin
d9127edb1f 32-bit fixes 2011-01-10 10:34:20 -05:00
Jean-Marc Valin
75f99bc51a Make LCG 16-bit clean 2011-01-10 10:02:58 -05:00
Timothy B. Terriberry
08ef1f4c6c 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.
2011-01-09 23:08:15 -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
Jean-Marc Valin
d0aa9f8616 Tuning the split allocation for temporal masking 2011-01-09 01:27:07 -05:00
Timothy B. Terriberry
a714994bf8 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.
2011-01-09 01:09:58 -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
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
fe40ddd999 Update the maximum fine bits everywhere.
cf874373 raised the limit from 7 to 8 for N>1 bands in
 interp_bits2pulses(), but did not raise the corresponding limits
 for N=1 bands, or for [un]quant_energy_finalise().
This commit raises all of the limits to the same value, 8.
2010-12-30 12:47:28 -05:00
Timothy B. Terriberry
949f18010f Move fine_priority calculation after the bust cap.
This way if a band doesn't get the fine bits we want because it
 wasn't allocated enough bits to start with, then we will still
 give it priority for any spare bits after PVQ.
2010-12-30 12:47:28 -05:00
Jean-Marc Valin
fa7215fdb9 Fixing stereo renormalisation
Compensate for the fact that the side "energy" is not preserved
when the split ends up starving one segment.
2010-12-29 15:19:58 -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
cf874373c0 Minor tweaks to the max allocation 2010-12-27 16:34:49 -05:00
Jean-Marc Valin
20e4c6a611 Removing FIXMEs that were fixed 2010-12-27 16:34:40 -05:00
Timothy B. Terriberry
8fcde379ec Clean up some type usage.
ec_byte_read() ec_byte_read_from_end() had different return types.
ec_dec_bits() was storing its return value as int instead of
 ec_uint32, which will break if int is only 16 bits.
2010-12-23 14:33:32 -05:00
Timothy B. Terriberry
df2c71ea5a Use _BitScanReverse for EC_ILOG with MSVC.
Also updates the TI dsplib macros to use the same EC_CLZ mechanism
 as everything else.
2010-12-23 11:23:50 -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
Timothy B. Terriberry
4e955ed379 Fix a typo in ec_byte_write_done().
Introduced by 30df6cf3.
This should have only affected the output in the case where the last
 few extra bits caused us to bust, and wouldn't have prevented us
 from detecting the error.
2010-12-21 20:16:24 -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
59858633fb Added highest allocation line possible 2010-12-21 11:28:23 -05:00
Jean-Marc Valin
dc6d69e64b Ordering Hadamard frequencies when increasing the time-resolution.
This means we're "time-ordered" in all cases except when increasing
the time resolution on frames that already use short blocks.
There's no reordering when increasing the frequency resolution
on short blocks.
2010-12-21 01:04:11 -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
88bab52abc Bump bit-stream version 2010-12-20 16:58:29 -05:00
Jean-Marc Valin
6ba0b350fb Being a bit more careful about enabling the post-filter 2010-12-20 11:40:30 -05:00
Jean-Marc Valin
6e4b9dc034 Turning noise filling back on for cases where we have no data to fold with 2010-12-19 21:58:31 -05:00
Gregory Maxwell
9b98aaa741 Eliminate some divisions from rate.c. 2010-12-19 07:53:04 -05:00