80 static int quantize(
int value,
const int16_t *table,
unsigned int size)
82 unsigned int low = 0, high = size - 1;
85 int index = (low + high) >> 1;
86 int error = table[
index] - value;
89 return table[high] + error > value ? low : high;
108 float num = 0, den = 0;
134 const float *ortho1,
const float *ortho2,
135 const float *
data,
float *score,
float *gain)
147 g += work[i] * work[i];
148 c += data[i] * work[i];
175 vect[lag + i] = cb[i];
190 const float *coefs,
float *
data)
193 float score, gain, best_score, best_gain;
196 gain = best_score = 0;
200 if (score > best_score) {
216 data[i] -= best_gain * work[i];
217 return best_vect - BLOCKSIZE / 2 + 1;
238 const int8_t cb[][
BLOCKSIZE],
const float *ortho1,
239 const float *ortho2,
float *
data,
int *idx,
243 float g, score, best_score;
246 *idx = *gain = best_score = 0;
251 if (score > best_score) {
273 int cba_idx,
int *cb1_idx,
int *cb2_idx)
285 memcpy(cba_vect, work,
sizeof(cba_vect));
288 data, cb1_idx, &gain);
301 data[i] -= gain * work[i];
302 memcpy(cb1_vect, work,
sizeof(cb1_vect));
308 ortho_cb1 ? cb1_vect : NULL, data, cb2_idx, &gain);
322 const int16_t *sblock_data,
323 const int16_t *lpc_coefs,
unsigned int rms,
330 int cba_idx, cb1_idx, cb2_idx, gain;
333 float error, best_error;
337 coefs[i] = lpc_coefs[i] * (1/4096.0);
344 memset(data, 0,
sizeof(data));
348 zero[i] = work[LPC_ORDER + i];
349 data[i] = sblock_data[i] - zero[i];
357 memset(work, 0, LPC_ORDER *
sizeof(*work));
366 memcpy(cba, work + LPC_ORDER,
sizeof(cba));
369 m[0] = (
ff_irms(cba_vect) * rms) >> 12;
371 fixed_cb_search(work + LPC_ORDER, coefs, data, cba_idx, &cb1_idx, &cb2_idx);
378 memcpy(cb1, work + LPC_ORDER,
sizeof(cb1));
382 memcpy(cb2, work + LPC_ORDER,
sizeof(cb2));
384 best_error = FLT_MAX;
386 for (n = 0; n < 256; n++) {
396 data[i] = zero[i] + g[0] * cba[i] + g[1] * cb1[i] +
398 error += (data[i] - sblock_data[i]) *
399 (data[i] - sblock_data[i]);
403 data[i] = zero[i] + g[1] * cb1[i] + g[2] * cb2[i];
404 error += (data[i] - sblock_data[i]) *
405 (data[i] - sblock_data[i]);
408 if (error < best_error) {
423 int buf_size,
void *
data)
425 static const uint8_t
sizes[
LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};
426 static const uint8_t bit_sizes[
LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
434 unsigned int refl_rms[
NBLOCKS];
453 energy += (lpc_data[i] * lpc_data[i]) >> 4;
456 lpc_data[i] = *((int16_t *)data + i - 2 * BLOCKSIZE - BLOCKSIZE / 2) >>
458 energy += (lpc_data[i] * lpc_data[i]) >> 4;
467 block_coefs[
NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
468 (12 - shift[LPC_ORDER - 1]));
482 memset(lpc_refl, 0,
sizeof(lpc_refl));
494 refl_rms[1] =
ff_interp(ractx, block_coefs[1], 2,
495 energy <= ractx->old_energy,
497 refl_rms[2] =
ff_interp(ractx, block_coefs[2], 3, 0, energy);
503 block_coefs[i], refl_rms[i], &pb);
508 for (i = 0; i < NBLOCKS *
BLOCKSIZE; i++)
509 ractx->
curr_block[i] = *((int16_t *)data + i) >> 2;