103 512 , 12,
tab.
lsp08, 1, 5, 3, 3,
tab.
shape08 , 8, 28, 20, 6, 40
112 512 , 16,
tab.
lsp11, 1, 6, 4, 3,
tab.
shape11 , 9, 36, 30, 7, 90
121 512 , 16,
tab.
lsp11, 1, 6, 4, 3,
tab.
shape11 , 9, 36, 30, 7, 90
130 1024, 16,
tab.
lsp16, 1, 6, 4, 3,
tab.
shape16 , 9, 56, 60, 7, 180
139 1024, 16,
tab.
lsp22_1, 1, 6, 4, 3,
tab.
shape22_1, 9, 56, 36, 7, 144
148 1024, 16,
tab.
lsp22_1, 1, 6, 4, 3,
tab.
shape22_1, 9, 56, 36, 7, 144
157 512 , 16,
tab.
lsp22_2, 1, 6, 4, 4,
tab.
shape22_2, 9, 56, 36, 7, 72
166 2048, 20,
tab.
lsp44, 1, 6, 4, 4,
tab.
shape44 , 9, 84, 54, 7, 432
175 2048, 20,
tab.
lsp44, 1, 6, 4, 4,
tab.
shape44 , 9, 84, 54, 7, 432
210 #define PPC_SHAPE_CB_SIZE 64
211 #define PPC_SHAPE_LEN_MAX 60
212 #define SUB_AMP_MAX 4500.0
213 #define MULAW_MU 100.0
215 #define AMP_MAX 13000.0
216 #define SUB_GAIN_BITS 5
217 #define WINDOW_TYPE_BITS 4
219 #define LSP_COEFS_MAX 20
220 #define LSP_SPLIT_MAX 4
221 #define CHANNELS_MAX 2
222 #define SUBBLOCKS_MAX 16
223 #define BARK_N_COEF_MAX 4
249 float two_cos_w = 2.0f*cos_val;
251 for (j = 0; j + 1 < order; j += 2*2) {
253 q *= lsp[j ] - two_cos_w;
254 p *= lsp[j+1] - two_cos_w;
256 q *= lsp[j+2] - two_cos_w;
257 p *= lsp[j+3] - two_cos_w;
260 p *= p * (2.0f - two_cos_w);
261 q *= q * (2.0f + two_cos_w);
263 return 0.5 / (p + q);
275 for (i = 0; i < size_s/2; i++) {
285 float step = (v1 - v2)/(size + 1);
287 for (i = 0; i <
size; i++) {
295 return part ? -cos_tab[size - idx - 1] :
315 float *out,
const float *in,
326 get_cos(i, part, cos_tab, size),
330 for (i = step; i <= size - 2*
step; i +=
step) {
331 if (out[i + step] + out[i - step] > 1.95*out[i] ||
332 out[i + step] >= out[i - step]) {
333 interpolate(out + i - step + 1, out[i], out[i-step], step - 1);
337 get_cos(i-step/2, part, cos_tab, size),
339 interpolate(out + i - step + 1, out[i-step/2], out[i-step ], step/2 - 1);
340 interpolate(out + i - step/2 + 1, out[i ], out[i-step/2], step/2 - 1);
344 interpolate(out + size - 2*step + 1, out[size-step], out[size - 2*step], step - 1);
348 const float *buf,
float *lpc,
354 interpolate(lpc+size/2-step+1, lpc[size/2], lpc[size/2-step], step);
356 memset_float(lpc + size - 2*step + 1, lpc[size - 2*step], 2*step - 1);
366 const int16_t *cb0,
const int16_t *cb1,
int cb_len)
371 for (i = 0; i < tctx->
n_div[ftype]; i++) {
375 const int16_t *tab0, *
tab1;
397 tab0 = cb0 + tmp0*cb_len;
398 tab1 = cb1 + tmp1*cb_len;
400 for (j = 0; j < length; j++)
401 out[tctx->
permut[ftype][pos+j]] = sign0*tab0[j] + sign1*tab1[j];
410 y = av_clipf(y/clip, -1, 1);
411 return clip *
FFSIGN(y) * (exp(log(1+mu) * fabs(y)) - 1) / mu;
445 size =
tabs[b/5].size;
446 rtab =
tabs[b/5].tab;
447 return x - rtab[size*
av_log2(2*(x - 1)/size)+(x - 1)%size];
456 float ppc_gain,
float *speech,
int len)
460 const float *shape_end = shape +
len;
464 for (i = 0; i < width/2; i++)
465 speech[i] += ppc_gain * *shape++;
469 for (j = -width/2; j < (width+1)/2; j++)
470 speech[j+center] += ppc_gain * *shape++;
475 for (j = -width/2; j < (width + 1)/2 && shape < shape_end; j++)
476 speech[j+center] += ppc_gain * *shape++;
480 float ppc_gain,
float *speech)
487 int period_range = max_period - min_period;
491 int period = min_period +
495 if (isampf == 22 && ibps == 32) {
515 out[i] = (1./(1<<13)) *
520 float val = (1./(1<<23)) *
524 for (j = 0; j < sub; j++) {
543 float min_dist2 = min_dist * 0.5;
544 for (i = 1; i < order; i++)
545 if (lsp[i] - lsp[i-1] < min_dist) {
546 float avg = (lsp[i] + lsp[i-1]) * 0.5;
548 lsp[i-1] = avg - min_dist2;
549 lsp[i ] = avg + min_dist2;
554 int lpc_hist_idx,
float *lsp,
float *hist)
563 const int8_t funny_rounding[4] = {
572 int chunk_end = ((i + 1)*mtab->
n_lsp + funny_rounding[i])/mtab->
lsp_split;
573 for (; j < chunk_end; j++)
574 lsp[j] = cb [lpc_idx1 * mtab->
n_lsp + j] +
575 cb2[lpc_idx2[i] * mtab->
n_lsp + j];
580 for (i = 0; i < mtab->
n_lsp; i++) {
581 float tmp1 = 1. - cb3[lpc_hist_idx*mtab->
n_lsp + i];
582 float tmp2 = hist[i] * cb3[lpc_hist_idx*mtab->
n_lsp + i];
584 lsp[i] = lsp[i] * tmp1 + tmp2;
599 lsp[i] = 2*cos(lsp[i]);
615 float *in,
float *prev,
int ch)
629 static const uint8_t wtype_to_wsize[] = {0, 0, 2, 2, 2, 1, 0, 1, 1};
630 int types_sizes[] = {
636 wsize = types_sizes[wtype_to_wsize[wtype]];
638 prev_buf = prev + (size - bsize)/2;
640 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
641 int sub_wtype = ftype ==
FT_MEDIUM ? 8 : wtype;
643 if (!j && wtype == 4)
645 else if (j == mtab->
fmode[ftype].
sub-1 && wtype == 7)
648 wsize = types_sizes[wtype_to_wsize[sub_wtype]];
650 mdct->
imdct_half(mdct, buf1 + bsize*j, in + bsize*j);
658 memcpy(out2, buf1 + bsize*j + wsize/2, (bsize - wsize/2)*
sizeof(
float));
660 out2 += ftype ==
FT_MEDIUM ? (bsize-wsize)/2 : bsize - wsize;
662 prev_buf = buf1 + bsize*j + bsize/2;
679 prev_buf + 2*i*mtab->
size,
687 size1 = mtab->
size - size2;
689 memcpy(&out[0][0 ], prev_buf, size1 *
sizeof(out[0][0]));
690 memcpy(&out[0][size1], tctx->
curr_frame, size2 *
sizeof(out[0][0]));
693 memcpy(&out[1][0], &prev_buf[2*mtab->
size], size1 *
sizeof(out[1][0]));
694 memcpy(&out[1][size1], &tctx->
curr_frame[2*mtab->
size], size2 *
sizeof(out[1][0]));
700 int ch,
float *out,
float gain,
enum FrameType ftype)
704 float *hist = tctx->
bark_hist[ftype][ch];
705 float val = ((
const float []) {0.4, 0.35, 0.28})[ftype];
710 for (i = 0; i < fw_cb_len; i++)
711 for (j = 0; j < bark_n_coef; j++, idx++) {
713 mtab->
fmode[ftype].
bark_cb[fw_cb_len*in[j] + i] * (1./4096);
714 float st = use_hist ?
715 (1. - val) * tmp2 + val*hist[idx] + 1. : tmp2 + 1.;
718 if (st < -1.) st = 1.;
732 int block_size = mtab->
size / sub;
748 for (i = 0; i < channels; i++)
749 for (j = 0; j < sub; j++)
754 for (i = 0; i < channels; i++)
755 for (j = 0; j < sub; j++)
760 for (i = 0; i < channels; i++) {
775 for (i = 0; i < channels; i++) {
776 float *chunk = out + mtab->
size * i;
779 for (j = 0; j < sub; j++) {
781 tctx->
tmp_buf, gain[sub*i+j], ftype);
789 float pgain_step = 25000. / ((1 << mtab->
pgain_bit) - 1);
799 decode_lsp(tctx, lpc_idx1[i], lpc_idx2[i], lpc_hist_idx[i], lsp,
804 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
812 int *got_frame_ptr,
AVPacket *avpkt)
815 int buf_size = avpkt->
size;
821 int window_type, ret;
822 static const enum FrameType wtype_to_ftype_table[] = {
829 "Frame too small (%d bytes). Truncated file?\n", buf_size);
847 if (window_type > 8) {
852 ftype = wtype_to_ftype_table[window_type];
882 float norm = channels == 1 ? 2. : 1.;
884 for (i = 0; i < 3; i++) {
887 -sqrt(norm/bsize) / (1<<15))))
904 for (i = 0; i < 3; i++) {
906 double freq = 2*M_PI/m;
908 (m / 4) *
sizeof(*tctx->
cos_tabs[i]), alloc_fail);
910 for (j = 0; j <= m/8; j++)
911 tctx->
cos_tabs[i][j] = cos((2*j + 1)*freq);
912 for (j = 1; j < m/8; j++)
934 const uint8_t line_len[2],
int length_div,
940 for (i = 0; i < line_len[0]; i++) {
943 if (num_blocks == 1 ||
944 (ftype ==
FT_LONG && num_vect % num_blocks) ||
945 (ftype !=
FT_LONG && num_vect & 1 ) ||
953 for (j = 0; j < num_vect && (j+num_vect*i < block_size*num_blocks); j++)
954 tab[i*num_vect+j] = i*num_vect + (j + shift) % num_vect;
974 const uint8_t line_len[2],
int length_div)
978 for (i = 0; i < num_vect; i++)
979 for (j = 0; j < line_len[i >= length_div]; j++)
980 out[cont++] = in[j*num_vect + i];
983 static void linear_perm(int16_t *out, int16_t *in,
int n_blocks,
int size)
985 int block_size = size/n_blocks;
988 for (i = 0; i <
size; i++)
989 out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks;
997 int16_t *tmp_perm = (int16_t *) tctx->
tmp_buf;
1008 block_size, tctx->
length[ftype],
1031 int bsize_no_main_cb[3];
1036 for (i = 0; i < 3; i++)
1038 bse_bits[i] = n_ch *
1041 bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits +
1044 for (i = 0; i < 2; i++)
1045 bsize_no_main_cb[i] =
1050 for (i = 0; i < 4; i++) {
1053 int rounded_up, rounded_down, num_rounded_down, num_rounded_up;
1058 bit_size = total_fr_bits - bsize_no_main_cb[i];
1059 vect_size = n_ch * mtab->
size;
1062 tctx->
n_div[i] = (bit_size + 13) / 14;
1064 rounded_up = (bit_size + tctx->
n_div[i] - 1)/tctx->
n_div[i];
1065 rounded_down = (bit_size )/tctx->
n_div[i];
1066 num_rounded_down = rounded_up * tctx->
n_div[i] - bit_size;
1067 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
1074 rounded_up = (vect_size + tctx->
n_div[i] - 1)/tctx->
n_div[i];
1075 rounded_down = (vect_size )/tctx->
n_div[i];
1076 num_rounded_down = rounded_up * tctx->
n_div[i] - vect_size;
1077 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
1078 tctx->
length[i][0] = rounded_up;
1079 tctx->
length[i][1] = rounded_down;
1092 for (i = 0; i < 3; i++) {
1112 tctx->
avctx = avctx;
1123 if (isampf < 8 || isampf > 44) {
1131 default: avctx->
sample_rate = isampf * 1000;
break;
1143 if (ibps < 8 || ibps > 48) {
1148 switch ((isampf << 8) + ibps) {
1159 av_log(avctx,
AV_LOG_ERROR,
"This version does not support %d kHz - %d kbit/s/ch mode.\n", isampf, isampf);