The encoder and decoder can now process audio encoded at a higher rate

than what they're running at.
This commit is contained in:
Jean-Marc Valin 2010-07-16 21:48:44 -04:00
parent 85f41b20df
commit 8952c45ea5
3 changed files with 17 additions and 18 deletions

View file

@ -902,7 +902,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, celt_nor
M = 1<<LM; M = 1<<LM;
B = shortBlocks ? M : 1; B = shortBlocks ? M : 1;
spread = fold ? B : 0; spread = fold ? B : 0;
ALLOC(_norm, M*eBands[m->nbEBands+1], celt_norm); ALLOC(_norm, M*eBands[m->nbEBands], celt_norm);
norm = _norm; norm = _norm;
balance = 0; balance = 0;
@ -949,6 +949,12 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, celt_nor
lowband = NULL; lowband = NULL;
tf_change = tf_res[i]; tf_change = tf_res[i];
if (i>=m->effEBands)
{
X=norm;
if (_Y!=NULL)
Y = norm;
}
quant_band(encode, m, i, X, Y, N, b, spread, tf_change, lowband, resynth, ec, &remaining_bits, LM, norm+M*eBands[i], bandE, 0); quant_band(encode, m, i, X, Y, N, b, spread, tf_change, lowband, resynth, ec, &remaining_bits, LM, norm+M*eBands[i], bandE, 0);
balance += pulses[i] + tell; balance += pulses[i] + tell;

View file

@ -158,9 +158,7 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error)
st->channels = channels; st->channels = channels;
st->start = 0; st->start = 0;
st->end = st->mode->nbEBands; st->end = st->mode->effEBands;
while (st->mode->eBands[st->end] > st->mode->shortMdctSize)
st->end--;
st->vbr_rate_norm = 0; st->vbr_rate_norm = 0;
st->pitch_enabled = 1; st->pitch_enabled = 1;
@ -1059,8 +1057,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c
quant_fine_energy(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, enc, C); quant_fine_energy(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, enc, C);
/* Residual quantisation */ /* Residual quantisation */
/* FIXME: we can't just stop at effEnd because we'll have an allocation mismatch */ quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, bandE, pulses, shortBlocks, has_fold, tf_res, resynth, nbCompressedBytes*8, enc, LM);
quant_all_bands(1, st->mode, st->start, effEnd, X, C==2 ? X+N : NULL, bandE, pulses, shortBlocks, has_fold, tf_res, resynth, nbCompressedBytes*8, enc, LM);
quant_energy_finalise(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C); quant_energy_finalise(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C);
@ -1435,9 +1432,7 @@ CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error)
st->channels = channels; st->channels = channels;
st->start = 0; st->start = 0;
st->end = st->mode->nbEBands; st->end = st->mode->effEBands;
while (st->mode->eBands[st->end] > st->mode->shortMdctSize)
st->end--;
st->decode_mem = (celt_sig*)celt_alloc((DECODE_BUFFER_SIZE+st->overlap)*C*sizeof(celt_sig)); st->decode_mem = (celt_sig*)celt_alloc((DECODE_BUFFER_SIZE+st->overlap)*C*sizeof(celt_sig));
st->out_mem = st->decode_mem+DECODE_BUFFER_SIZE-MAX_PERIOD; st->out_mem = st->decode_mem+DECODE_BUFFER_SIZE-MAX_PERIOD;
@ -1827,8 +1822,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
} }
/* Decode fixed codebook and merge with pitch */ /* Decode fixed codebook and merge with pitch */
/* FIXME: we can't just stop at effEnd because we'll have an allocation mismatch */ quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, NULL, pulses, shortBlocks, has_fold, tf_res, 1, len*8, dec, LM);
quant_all_bands(0, st->mode, st->start, effEnd, X, C==2 ? X+N : NULL, NULL, pulses, shortBlocks, has_fold, tf_res, 1, len*8, dec, LM);
unquant_energy_finalise(st->mode, st->start, st->end, bandE, st->oldBandE, fine_quant, fine_priority, len*8-ec_dec_tell(dec, 0), dec, C); unquant_energy_finalise(st->mode, st->start, st->end, bandE, st->oldBandE, fine_quant, fine_priority, len*8-ec_dec_tell(dec, 0), dec, C);

View file

@ -123,10 +123,9 @@ static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int res, int *n
if (Fs == 400*(celt_int32)frame_size) if (Fs == 400*(celt_int32)frame_size)
{ {
*nbEBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1; *nbEBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1;
eBands = celt_alloc(sizeof(celt_int16)*(*nbEBands+2)); eBands = celt_alloc(sizeof(celt_int16)*(*nbEBands+1));
for (i=0;i<*nbEBands+2;i++) for (i=0;i<*nbEBands+1;i++)
eBands[i] = eband5ms[i]; eBands[i] = eband5ms[i];
eBands[*nbEBands+1] = frame_size;
return eBands; return eBands;
} }
/* Find the number of critical bands supported by our sampling rate */ /* Find the number of critical bands supported by our sampling rate */
@ -164,9 +163,8 @@ static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int res, int *n
if (eBands[i] < i) if (eBands[i] < i)
eBands[i] = i; eBands[i] = i;
eBands[*nbEBands] = (bark_freq[nBark]+res/2)/res; eBands[*nbEBands] = (bark_freq[nBark]+res/2)/res;
eBands[*nbEBands+1] = frame_size; if (eBands[*nbEBands] > frame_size)
if (eBands[*nbEBands] > eBands[*nbEBands+1]) eBands[*nbEBands] = frame_size;
eBands[*nbEBands] = eBands[*nbEBands+1];
for (i=1;i<*nbEBands-1;i++) for (i=1;i<*nbEBands-1;i++)
{ {
if (eBands[i+1]-eBands[i] < eBands[i]-eBands[i-1]) if (eBands[i+1]-eBands[i] < eBands[i]-eBands[i-1])
@ -235,6 +233,7 @@ static void compute_allocation_table(CELTMode *mode, int res)
/* Move to next eband */ /* Move to next eband */
current = 0; current = 0;
eband++; eband++;
if (eband < mode->nbEBands)
edge = mode->eBands[eband+1]*res; edge = mode->eBands[eband+1]*res;
} }
current += alloc; current += alloc;