100 512 , 12,
tab.lsp08, 1, 5, 3, 3,
tab.shape08 , 8, 28, 20, 6, 40
109 512 , 16,
tab.lsp11, 1, 6, 4, 3,
tab.shape11 , 9, 36, 30, 7, 90
118 512 , 16,
tab.lsp11, 1, 6, 4, 3,
tab.shape11 , 9, 36, 30, 7, 90
127 1024, 16,
tab.lsp16, 1, 6, 4, 3,
tab.shape16 , 9, 56, 60, 7, 180
136 1024, 16,
tab.lsp22_1, 1, 6, 4, 3,
tab.shape22_1, 9, 56, 36, 7, 144
145 1024, 16,
tab.lsp22_1, 1, 6, 4, 3,
tab.shape22_1, 9, 56, 36, 7, 144
154 512 , 16,
tab.lsp22_2, 1, 6, 4, 4,
tab.shape22_2, 9, 56, 36, 7, 72
163 2048, 20,
tab.lsp44, 1, 6, 4, 4,
tab.shape44 , 9, 84, 54, 7, 432
172 2048, 20,
tab.lsp44, 1, 6, 4, 4,
tab.shape44 , 9, 84, 54, 7, 432
207 #define PPC_SHAPE_CB_SIZE 64
208 #define PPC_SHAPE_LEN_MAX 60
209 #define SUB_AMP_MAX 4500.0
210 #define MULAW_MU 100.0
212 #define AMP_MAX 13000.0
213 #define SUB_GAIN_BITS 5
214 #define WINDOW_TYPE_BITS 4
216 #define LSP_COEFS_MAX 20
217 #define LSP_SPLIT_MAX 4
218 #define CHANNELS_MAX 2
219 #define SUBBLOCKS_MAX 16
220 #define BARK_N_COEF_MAX 4
246 float two_cos_w = 2.0f*cos_val;
248 for (j = 0; j + 1 < order; j += 2*2) {
250 q *= lsp[j ] - two_cos_w;
251 p *= lsp[j+1] - two_cos_w;
253 q *= lsp[j+2] - two_cos_w;
254 p *= lsp[j+3] - two_cos_w;
257 p *= p * (2.0f - two_cos_w);
258 q *= q * (2.0f + two_cos_w);
260 return 0.5 / (p + q);
272 for (i = 0; i < size_s/2; i++) {
282 float step = (v1 - v2)/(size + 1);
284 for (i = 0; i <
size; i++) {
290 static inline float get_cos(
int idx,
int part,
const float *cos_tab,
int size)
292 return part ? -cos_tab[size - idx - 1] :
312 float *out,
const float *in,
317 const float *cos_tab = tctx->
cos_tabs[ftype];
323 get_cos(i, part, cos_tab, size),
327 for (i = step; i <= size - 2*
step; i +=
step) {
328 if (out[i + step] + out[i - step] > 1.95*out[i] ||
329 out[i + step] >= out[i - step]) {
330 interpolate(out + i - step + 1, out[i], out[i-step], step - 1);
334 get_cos(i-step/2, part, cos_tab, size),
336 interpolate(out + i - step + 1, out[i-step/2], out[i-step ], step/2 - 1);
337 interpolate(out + i - step/2 + 1, out[i ], out[i-step/2], step/2 - 1);
341 interpolate(out + size - 2*step + 1, out[size-step], out[size - 2*step], step - 1);
345 const float *buf,
float *lpc,
351 interpolate(lpc+size/2-step+1, lpc[size/2], lpc[size/2-step], step);
353 memset_float(lpc + size - 2*step + 1, lpc[size - 2*step], 2*step - 1);
363 const int16_t *cb0,
const int16_t *cb1,
int cb_len)
368 for (i = 0; i < tctx->
n_div[ftype]; i++) {
372 const int16_t *tab0, *
tab1;
394 tab0 = cb0 + tmp0*cb_len;
395 tab1 = cb1 + tmp1*cb_len;
397 for (j = 0; j < length; j++)
398 out[tctx->
permut[ftype][pos+j]] = sign0*tab0[j] + sign1*tab1[j];
407 y = av_clipf(y/clip, -1, 1);
408 return clip *
FFSIGN(y) * (exp(log(1+mu) * fabs(y)) - 1) / mu;
442 size =
tabs[b/5].size;
443 rtab =
tabs[b/5].tab;
444 return x - rtab[size*av_log2(2*(x - 1)/size)+(x - 1)%size];
453 float ppc_gain,
float *speech,
int len)
457 const float *shape_end = shape +
len;
461 for (i = 0; i < width/2; i++)
462 speech[i] += ppc_gain * *shape++;
466 for (j = -width/2; j < (width+1)/2; j++)
467 speech[j+center] += ppc_gain * *shape++;
472 for (j = -width/2; j < (width + 1)/2 && shape < shape_end; j++)
473 speech[j+center] += ppc_gain * *shape++;
477 float ppc_gain,
float *speech)
484 int period_range = max_period - min_period;
488 int period = min_period +
492 if (isampf == 22 && ibps == 32) {
512 out[i] = (1./(1<<13)) *
517 float val = (1./(1<<23)) *
521 for (j = 0; j < sub; j++) {
540 float min_dist2 = min_dist * 0.5;
541 for (i = 1; i < order; i++)
542 if (lsp[i] - lsp[i-1] < min_dist) {
543 float avg = (lsp[i] + lsp[i-1]) * 0.5;
545 lsp[i-1] = avg - min_dist2;
546 lsp[i ] = avg + min_dist2;
551 int lpc_hist_idx,
float *lsp,
float *hist)
560 const int8_t funny_rounding[4] = {
569 int chunk_end = ((i + 1)*mtab->
n_lsp + funny_rounding[i])/mtab->
lsp_split;
570 for (; j < chunk_end; j++)
571 lsp[j] = cb [lpc_idx1 * mtab->
n_lsp + j] +
572 cb2[lpc_idx2[i] * mtab->
n_lsp + j];
577 for (i = 0; i < mtab->
n_lsp; i++) {
578 float tmp1 = 1. - cb3[lpc_hist_idx*mtab->
n_lsp + i];
579 float tmp2 = hist[i] * cb3[lpc_hist_idx*mtab->
n_lsp + i];
581 lsp[i] = lsp[i] * tmp1 + tmp2;
596 lsp[i] = 2*cos(lsp[i]);
612 float *in,
float *prev,
int ch)
626 static const uint8_t wtype_to_wsize[] = {0, 0, 2, 2, 2, 1, 0, 1, 1};
627 int types_sizes[] = {
633 wsize = types_sizes[wtype_to_wsize[wtype]];
635 prev_buf = prev + (size - bsize)/2;
637 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
638 int sub_wtype = ftype ==
FT_MEDIUM ? 8 : wtype;
640 if (!j && wtype == 4)
642 else if (j == mtab->
fmode[ftype].
sub-1 && wtype == 7)
645 wsize = types_sizes[wtype_to_wsize[sub_wtype]];
647 mdct->
imdct_half(mdct, buf1 + bsize*j, in + bsize*j);
650 prev_buf + (bsize-wsize)/2,
656 memcpy(out2, buf1 + bsize*j + wsize/2, (bsize - wsize/2)*
sizeof(
float));
658 out2 += ftype ==
FT_MEDIUM ? (bsize-wsize)/2 : bsize - wsize;
660 prev_buf = buf1 + bsize*j + bsize/2;
677 prev_buf + 2*i*mtab->
size,
685 size1 = mtab->
size - size2;
688 &prev_buf[2*mtab->
size],
697 memcpy(out, prev_buf, size1 *
sizeof(*out));
701 memcpy(out, tctx->
curr_frame, size2 *
sizeof(*out));
707 int ch,
float *out,
float gain,
enum FrameType ftype)
711 float *hist = tctx->
bark_hist[ftype][ch];
712 float val = ((
const float []) {0.4, 0.35, 0.28})[ftype];
717 for (i = 0; i < fw_cb_len; i++)
718 for (j = 0; j < bark_n_coef; j++, idx++) {
720 mtab->
fmode[ftype].
bark_cb[fw_cb_len*in[j] + i] * (1./4096);
721 float st = use_hist ?
722 (1. - val) * tmp2 + val*hist[idx] + 1. : tmp2 + 1.;
725 if (st < -1.) st = 1.;
739 int block_size = mtab->
size / sub;
755 for (i = 0; i < channels; i++)
756 for (j = 0; j < sub; j++)
761 for (i = 0; i < channels; i++)
762 for (j = 0; j < sub; j++)
767 for (i = 0; i < channels; i++) {
782 for (i = 0; i < channels; i++) {
783 float *chunk = out + mtab->
size * i;
786 for (j = 0; j < sub; j++) {
788 tctx->
tmp_buf, gain[sub*i+j], ftype);
796 float pgain_step = 25000. / ((1 << mtab->
pgain_bit) - 1);
806 decode_lsp(tctx, lpc_idx1[i], lpc_idx2[i], lpc_hist_idx[i], lsp,
811 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
819 int *got_frame_ptr,
AVPacket *avpkt)
821 const uint8_t *buf = avpkt->
data;
822 int buf_size = avpkt->
size;
828 int window_type, ret;
829 static const enum FrameType wtype_to_ftype_table[] = {
836 "Frame too small (%d bytes). Truncated file?\n", buf_size);
854 if (window_type > 8) {
859 ftype = wtype_to_ftype_table[window_type];
889 float norm = channels == 1 ? 2. : 1.;
891 for (i = 0; i < 3; i++) {
894 -sqrt(norm/bsize) / (1<<15))))
911 for (i = 0; i < 3; i++) {
913 double freq = 2*
M_PI/m;
915 (m / 4) *
sizeof(*tctx->
cos_tabs[i]), alloc_fail);
917 for (j = 0; j <= m/8; j++)
918 tctx->
cos_tabs[i][j] = cos((2*j + 1)*freq);
919 for (j = 1; j < m/8; j++)
941 const uint8_t line_len[2],
int length_div,
947 for (i = 0; i < line_len[0]; i++) {
950 if (num_blocks == 1 ||
951 (ftype ==
FT_LONG && num_vect % num_blocks) ||
952 (ftype !=
FT_LONG && num_vect & 1 ) ||
960 for (j = 0; j < num_vect && (j+num_vect*i < block_size*num_blocks); j++)
961 tab[i*num_vect+j] = i*num_vect + (j + shift) % num_vect;
981 const uint8_t line_len[2],
int length_div)
985 for (i = 0; i < num_vect; i++)
986 for (j = 0; j < line_len[i >= length_div]; j++)
987 out[cont++] = in[j*num_vect + i];
990 static void linear_perm(int16_t *out, int16_t *in,
int n_blocks,
int size)
992 int block_size = size/n_blocks;
995 for (i = 0; i <
size; i++)
996 out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks;
1004 int16_t *tmp_perm = (int16_t *) tctx->
tmp_buf;
1013 block_size, tctx->
length[ftype],
1036 int bsize_no_main_cb[3];
1041 for (i = 0; i < 3; i++)
1043 bse_bits[i] = n_ch *
1046 bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits +
1049 for (i = 0; i < 2; i++)
1050 bsize_no_main_cb[i] =
1055 for (i = 0; i < 4; i++) {
1058 int rounded_up, rounded_down, num_rounded_down, num_rounded_up;
1063 bit_size = total_fr_bits - bsize_no_main_cb[i];
1064 vect_size = n_ch * mtab->
size;
1067 tctx->
n_div[i] = (bit_size + 13) / 14;
1069 rounded_up = (bit_size + tctx->
n_div[i] - 1)/tctx->
n_div[i];
1070 rounded_down = (bit_size )/tctx->
n_div[i];
1071 num_rounded_down = rounded_up * tctx->
n_div[i] - bit_size;
1072 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
1079 rounded_up = (vect_size + tctx->
n_div[i] - 1)/tctx->
n_div[i];
1080 rounded_down = (vect_size )/tctx->
n_div[i];
1081 num_rounded_down = rounded_up * tctx->
n_div[i] - vect_size;
1082 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
1083 tctx->
length[i][0] = rounded_up;
1084 tctx->
length[i][1] = rounded_down;
1097 for (i = 0; i < 3; i++) {
1117 tctx->
avctx = avctx;
1131 default: avctx->
sample_rate = isampf * 1000;
break;
1141 switch ((isampf << 8) + ibps) {
1152 av_log(avctx,
AV_LOG_ERROR,
"This version does not support %d kHz - %d kbit/s/ch mode.\n", isampf, isampf);