Adding some hysteresis on the folding threshold frequency
This adds some side-information that can be used to change the threshold freq arbitrarily.
This commit is contained in:
parent
85bbab0b4a
commit
dfd6e714f9
3 changed files with 49 additions and 9 deletions
|
@ -80,6 +80,7 @@ struct CELTEncoder {
|
|||
int fold_decision;
|
||||
int delayedIntra;
|
||||
int tonal_average;
|
||||
int lastCodedBands;
|
||||
|
||||
int prefilter_period;
|
||||
celt_word16 prefilter_gain;
|
||||
|
@ -740,6 +741,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
|||
int intensity=0;
|
||||
int dual_stereo=0;
|
||||
int effectiveBytes;
|
||||
int skip;
|
||||
SAVE_STACK;
|
||||
|
||||
if (nbCompressedBytes<0 || pcm==NULL)
|
||||
|
@ -1103,8 +1105,15 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
|||
ALLOC(pulses, st->mode->nbEBands, int);
|
||||
ALLOC(fine_priority, st->mode->nbEBands, int);
|
||||
|
||||
bits = nbCompressedBytes*8 - ec_enc_tell(enc, 0) - 1;
|
||||
codedBands = compute_allocation(st->mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM);
|
||||
/* bits = packet size - where we are - safety - skip signalling */
|
||||
bits = nbCompressedBytes*8 - ec_enc_tell(enc, 0) - 1 - (1<<BITRES);
|
||||
skip=-1;
|
||||
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
|
||||
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, &skip, st->lastCodedBands);
|
||||
st->lastCodedBands = codedBands;
|
||||
for (i=0;i<skip;i++)
|
||||
ec_enc_bit_prob(enc, 0, 32768);
|
||||
ec_enc_bit_prob(enc, 1, 32768);
|
||||
|
||||
quant_fine_energy(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, enc, C);
|
||||
|
||||
|
@ -1692,6 +1701,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
|||
celt_word16 postfilter_gain;
|
||||
int intensity=0;
|
||||
int dual_stereo=0;
|
||||
int skip;
|
||||
SAVE_STACK;
|
||||
|
||||
if (pcm==NULL)
|
||||
|
@ -1825,8 +1835,19 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
|||
intensity = ec_dec_uint(dec, 1+st->end-st->start);
|
||||
}
|
||||
|
||||
bits = len*8 - ec_dec_tell(dec, 0) - 1;
|
||||
codedBands = compute_allocation(st->mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM);
|
||||
bits = len*8 - ec_dec_tell(dec, 0) - 1 - (1<<BITRES);
|
||||
skip=0;
|
||||
while (ec_dec_bit_prob(dec, 32768)==0)
|
||||
{
|
||||
skip++;
|
||||
if (skip>21)
|
||||
{
|
||||
dec->error = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
|
||||
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, &skip, 0);
|
||||
|
||||
unquant_fine_energy(st->mode, st->start, st->end, bandE, oldBandE, fine_quant, dec, C);
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ void compute_pulse_cache(CELTMode *m, int LM)
|
|||
|
||||
static inline int interp_bits2pulses(const CELTMode *m, int start, int end,
|
||||
int *bits1, int *bits2, const int *thresh, int total, int *bits,
|
||||
int *ebits, int *fine_priority, int len, int _C, int LM)
|
||||
int *ebits, int *fine_priority, int len, int _C, int LM, int *skip, int prev)
|
||||
{
|
||||
int psum;
|
||||
int lo, hi;
|
||||
|
@ -192,6 +192,25 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end,
|
|||
psum += bits[j];
|
||||
}
|
||||
codedBands++;
|
||||
if (*skip==-1)
|
||||
{
|
||||
*skip=0;
|
||||
for (j=codedBands-1;j>=0;j--)
|
||||
{
|
||||
if ((bits[j] > (7*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>4 && j<prev)
|
||||
|| (bits[j] > (9*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>4))
|
||||
break;
|
||||
else
|
||||
(*skip)++;
|
||||
}
|
||||
*skip = IMIN(*skip, codedBands-start-1);
|
||||
}
|
||||
for (i=0;i<*skip;i++)
|
||||
{
|
||||
psum = psum - bits[codedBands-1] + ((C+1)<<BITRES);
|
||||
bits[codedBands-1] = C<<BITRES;
|
||||
codedBands--;
|
||||
}
|
||||
/* Allocate the remaining bits */
|
||||
if (codedBands) {
|
||||
int left, perband;
|
||||
|
@ -267,7 +286,7 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end,
|
|||
}
|
||||
|
||||
int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int alloc_trim,
|
||||
int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM)
|
||||
int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM, int *skip, int prev)
|
||||
{
|
||||
int lo, hi, len, j;
|
||||
const int C = CHANNELS(_C);
|
||||
|
@ -286,7 +305,7 @@ int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int
|
|||
|
||||
/* Below this threshold, we don't allocate any PVQ bits */
|
||||
for (j=start;j<end;j++)
|
||||
thresh[j] = (4*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>3;
|
||||
thresh[j] = ((C+1)<<BITRES) + (3*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>4;
|
||||
/* Tilt of the allocation curve */
|
||||
for (j=start;j<end;j++)
|
||||
trim_offset[j] = C*(m->eBands[j+1]-m->eBands[j])*(alloc_trim-5-LM)*(m->nbEBands-j-1)
|
||||
|
@ -334,7 +353,7 @@ int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int
|
|||
bits1[j] += offsets[j];
|
||||
}
|
||||
codedBands = interp_bits2pulses(m, start, end, bits1, bits2, thresh,
|
||||
total, pulses, ebits, fine_priority, len, C, LM);
|
||||
total, pulses, ebits, fine_priority, len, C, LM, skip, prev);
|
||||
RESTORE_STACK;
|
||||
return codedBands;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ celt_int16 **compute_alloc_cache(CELTMode *m, int M);
|
|||
@return Total number of bits allocated
|
||||
*/
|
||||
int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int alloc_trim,
|
||||
int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM);
|
||||
int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM, int *skip, int prev);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue