88 static int quantize(
int value,
const int16_t *table,
unsigned int size)
90 unsigned int low = 0, high = size - 1;
93 int index = (low + high) >> 1;
94 int error = table[
index] - value;
97 return table[high] + error > value ? low : high;
116 float num = 0, den = 0;
142 const float *ortho1,
const float *ortho2,
143 const float *
data,
float *score,
float *gain)
155 g += work[i] * work[i];
156 c += data[i] * work[i];
183 vect[lag + i] = cb[i];
198 const float *coefs,
float *
data)
201 float score, gain, best_score, best_gain;
204 gain = best_score = 0;
208 if (score > best_score) {
224 data[i] -= best_gain * work[i];
225 return best_vect - BLOCKSIZE / 2 + 1;
246 const int8_t cb[][
BLOCKSIZE],
const float *ortho1,
247 const float *ortho2,
float *
data,
int *idx,
251 float g, score, best_score;
254 *idx = *gain = best_score = 0;
259 if (score > best_score) {
281 int cba_idx,
int *cb1_idx,
int *cb2_idx)
293 memcpy(cba_vect, work,
sizeof(cba_vect));
296 data, cb1_idx, &gain);
309 data[i] -= gain * work[i];
310 memcpy(cb1_vect, work,
sizeof(cb1_vect));
316 ortho_cb1 ? cb1_vect : NULL, data, cb2_idx, &gain);
330 const int16_t *sblock_data,
331 const int16_t *lpc_coefs,
unsigned int rms,
338 int cba_idx, cb1_idx, cb2_idx, gain;
341 float error, best_error;
345 coefs[i] = lpc_coefs[i] * (1/4096.0);
355 zero[i] = work[LPC_ORDER + i];
356 data[i] = sblock_data[i] - zero[i];
364 memset(work, 0, LPC_ORDER *
sizeof(*work));
373 memcpy(cba, work + LPC_ORDER,
sizeof(cba));
376 m[0] = (
ff_irms(cba_vect) * rms) >> 12;
378 fixed_cb_search(work + LPC_ORDER, coefs, data, cba_idx, &cb1_idx, &cb2_idx);
385 memcpy(cb1, work + LPC_ORDER,
sizeof(cb1));
389 memcpy(cb2, work + LPC_ORDER,
sizeof(cb2));
391 best_error = FLT_MAX;
393 for (n = 0; n < 256; n++) {
403 data[i] = zero[i] + g[0] * cba[i] + g[1] * cb1[i] +
405 error += (data[i] - sblock_data[i]) *
406 (data[i] - sblock_data[i]);
410 data[i] = zero[i] + g[1] * cb1[i] + g[2] * cb2[i];
411 error += (data[i] - sblock_data[i]) *
412 (data[i] - sblock_data[i]);
415 if (error < best_error) {
430 const AVFrame *frame,
int *got_packet_ptr)
441 unsigned int refl_rms[
NBLOCKS];
442 const int16_t *
samples = frame ? (
const int16_t *)frame->
data[0] :
NULL;
463 energy += (lpc_data[i] * lpc_data[i]) >> 4;
468 lpc_data[i] = samples[j] >> 2;
469 energy += (lpc_data[i] * lpc_data[i]) >> 4;
473 memset(&lpc_data[i], 0, (
NBLOCKS * BLOCKSIZE - i) *
sizeof(*lpc_data));
481 block_coefs[
NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
482 (12 - shift[LPC_ORDER - 1]));
496 memset(lpc_refl, 0,
sizeof(lpc_refl));
508 refl_rms[1] =
ff_interp(ractx, block_coefs[1], 2,
509 energy <= ractx->old_energy,
511 refl_rms[2] =
ff_interp(ractx, block_coefs[2], 3, 0, energy);
517 block_coefs[i], refl_rms[i], &pb);
534 (NBLOCKS * BLOCKSIZE - i) *
sizeof(*ractx->
curr_block));