00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #include <stddef.h>
00031
00032 #include "avcodec.h"
00033 #include "internal.h"
00034 #include "get_bits.h"
00035
00036 #include "qcelpdata.h"
00037
00038 #include "celp_math.h"
00039 #include "celp_filters.h"
00040 #include "acelp_filters.h"
00041 #include "acelp_vectors.h"
00042 #include "lsp.h"
00043
00044 #undef NDEBUG
00045 #include <assert.h>
00046
00047 typedef enum
00048 {
00049 I_F_Q = -1,
00050 SILENCE,
00051 RATE_OCTAVE,
00052 RATE_QUARTER,
00053 RATE_HALF,
00054 RATE_FULL
00055 } qcelp_packet_rate;
00056
00057 typedef struct
00058 {
00059 AVFrame avframe;
00060 GetBitContext gb;
00061 qcelp_packet_rate bitrate;
00062 QCELPFrame frame;
00064 uint8_t erasure_count;
00065 uint8_t octave_count;
00066 float prev_lspf[10];
00067 float predictor_lspf[10];
00068 float pitch_synthesis_filter_mem[303];
00069 float pitch_pre_filter_mem[303];
00070 float rnd_fir_filter_mem[180];
00071 float formant_mem[170];
00072 float last_codebook_gain;
00073 int prev_g1[2];
00074 int prev_bitrate;
00075 float pitch_gain[4];
00076 uint8_t pitch_lag[4];
00077 uint16_t first16bits;
00078 uint8_t warned_buf_mismatch_bitrate;
00079
00080
00081 float postfilter_synth_mem[10];
00082 float postfilter_agc_mem;
00083 float postfilter_tilt_mem;
00084 } QCELPContext;
00085
00091 static av_cold int qcelp_decode_init(AVCodecContext *avctx)
00092 {
00093 QCELPContext *q = avctx->priv_data;
00094 int i;
00095
00096 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
00097
00098 for(i=0; i<10; i++)
00099 q->prev_lspf[i] = (i+1)/11.;
00100
00101 avcodec_get_frame_defaults(&q->avframe);
00102 avctx->coded_frame = &q->avframe;
00103
00104 return 0;
00105 }
00106
00118 static int decode_lspf(QCELPContext *q, float *lspf)
00119 {
00120 int i;
00121 float tmp_lspf, smooth, erasure_coeff;
00122 const float *predictors;
00123
00124 if (q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) {
00125 predictors = (q->prev_bitrate != RATE_OCTAVE &&
00126 q->prev_bitrate != I_F_Q ?
00127 q->prev_lspf : q->predictor_lspf);
00128
00129 if (q->bitrate == RATE_OCTAVE) {
00130 q->octave_count++;
00131
00132 for (i=0; i<10; i++) {
00133 q->predictor_lspf[i] =
00134 lspf[i] = (q->frame.lspv[i] ? QCELP_LSP_SPREAD_FACTOR
00135 : -QCELP_LSP_SPREAD_FACTOR)
00136 + predictors[i] * QCELP_LSP_OCTAVE_PREDICTOR
00137 + (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR)/11);
00138 }
00139 smooth = (q->octave_count < 10 ? .875 : 0.1);
00140 } else {
00141 erasure_coeff = QCELP_LSP_OCTAVE_PREDICTOR;
00142
00143 assert(q->bitrate == I_F_Q);
00144
00145 if(q->erasure_count > 1)
00146 erasure_coeff *= (q->erasure_count < 4 ? 0.9 : 0.7);
00147
00148 for(i = 0; i < 10; i++) {
00149 q->predictor_lspf[i] =
00150 lspf[i] = (i + 1) * ( 1 - erasure_coeff)/11
00151 + erasure_coeff * predictors[i];
00152 }
00153 smooth = 0.125;
00154 }
00155
00156
00157 lspf[0] = FFMAX(lspf[0], QCELP_LSP_SPREAD_FACTOR);
00158 for(i=1; i<10; i++)
00159 lspf[i] = FFMAX(lspf[i], (lspf[i-1] + QCELP_LSP_SPREAD_FACTOR));
00160
00161 lspf[9] = FFMIN(lspf[9], (1.0 - QCELP_LSP_SPREAD_FACTOR));
00162 for(i=9; i>0; i--)
00163 lspf[i-1] = FFMIN(lspf[i-1], (lspf[i] - QCELP_LSP_SPREAD_FACTOR));
00164
00165
00166 ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10);
00167 } else {
00168 q->octave_count = 0;
00169
00170 tmp_lspf = 0.;
00171 for (i = 0; i < 5; i++) {
00172 lspf[2*i+0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001;
00173 lspf[2*i+1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001;
00174 }
00175
00176
00177 if (q->bitrate == RATE_QUARTER) {
00178 if(lspf[9] <= .70 || lspf[9] >= .97)
00179 return -1;
00180 for(i=3; i<10; i++)
00181 if(fabs(lspf[i] - lspf[i-2]) < .08)
00182 return -1;
00183 } else {
00184 if(lspf[9] <= .66 || lspf[9] >= .985)
00185 return -1;
00186 for(i=4; i<10; i++)
00187 if (fabs(lspf[i] - lspf[i-4]) < .0931)
00188 return -1;
00189 }
00190 }
00191 return 0;
00192 }
00193
00202 static void decode_gain_and_index(QCELPContext *q,
00203 float *gain) {
00204 int i, subframes_count, g1[16];
00205 float slope;
00206
00207 if (q->bitrate >= RATE_QUARTER) {
00208 switch (q->bitrate) {
00209 case RATE_FULL: subframes_count = 16; break;
00210 case RATE_HALF: subframes_count = 4; break;
00211 default: subframes_count = 5;
00212 }
00213 for(i = 0; i < subframes_count; i++) {
00214 g1[i] = 4 * q->frame.cbgain[i];
00215 if (q->bitrate == RATE_FULL && !((i+1) & 3)) {
00216 g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32);
00217 }
00218
00219 gain[i] = qcelp_g12ga[g1[i]];
00220
00221 if (q->frame.cbsign[i]) {
00222 gain[i] = -gain[i];
00223 q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127;
00224 }
00225 }
00226
00227 q->prev_g1[0] = g1[i-2];
00228 q->prev_g1[1] = g1[i-1];
00229 q->last_codebook_gain = qcelp_g12ga[g1[i-1]];
00230
00231 if (q->bitrate == RATE_QUARTER) {
00232
00233 gain[7] = gain[4];
00234 gain[6] = 0.4*gain[3] + 0.6*gain[4];
00235 gain[5] = gain[3];
00236 gain[4] = 0.8*gain[2] + 0.2*gain[3];
00237 gain[3] = 0.2*gain[1] + 0.8*gain[2];
00238 gain[2] = gain[1];
00239 gain[1] = 0.6*gain[0] + 0.4*gain[1];
00240 }
00241 } else if (q->bitrate != SILENCE) {
00242 if (q->bitrate == RATE_OCTAVE) {
00243 g1[0] = 2 * q->frame.cbgain[0]
00244 + av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54);
00245 subframes_count = 8;
00246 } else {
00247 assert(q->bitrate == I_F_Q);
00248
00249 g1[0] = q->prev_g1[1];
00250 switch (q->erasure_count) {
00251 case 1 : break;
00252 case 2 : g1[0] -= 1; break;
00253 case 3 : g1[0] -= 2; break;
00254 default: g1[0] -= 6;
00255 }
00256 if(g1[0] < 0)
00257 g1[0] = 0;
00258 subframes_count = 4;
00259 }
00260
00261 slope = 0.5*(qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count;
00262 for(i=1; i<=subframes_count; i++)
00263 gain[i-1] = q->last_codebook_gain + slope * i;
00264
00265 q->last_codebook_gain = gain[i-2];
00266 q->prev_g1[0] = q->prev_g1[1];
00267 q->prev_g1[1] = g1[0];
00268 }
00269 }
00270
00280 static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain)
00281 {
00282 int i, diff, prev_diff=0;
00283
00284 for(i=1; i<5; i++) {
00285 diff = cbgain[i] - cbgain[i-1];
00286 if(FFABS(diff) > 10)
00287 return -1;
00288 else if(FFABS(diff - prev_diff) > 12)
00289 return -1;
00290 prev_diff = diff;
00291 }
00292 return 0;
00293 }
00294
00316 static void compute_svector(QCELPContext *q, const float *gain,
00317 float *cdn_vector)
00318 {
00319 int i, j, k;
00320 uint16_t cbseed, cindex;
00321 float *rnd, tmp_gain, fir_filter_value;
00322
00323 switch (q->bitrate) {
00324 case RATE_FULL:
00325 for (i = 0; i < 16; i++) {
00326 tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
00327 cindex = -q->frame.cindex[i];
00328 for(j=0; j<10; j++)
00329 *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cindex++ & 127];
00330 }
00331 break;
00332 case RATE_HALF:
00333 for (i = 0; i < 4; i++) {
00334 tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO;
00335 cindex = -q->frame.cindex[i];
00336 for (j = 0; j < 40; j++)
00337 *cdn_vector++ = tmp_gain * qcelp_rate_half_codebook[cindex++ & 127];
00338 }
00339 break;
00340 case RATE_QUARTER:
00341 cbseed = (0x0003 & q->frame.lspv[4])<<14 |
00342 (0x003F & q->frame.lspv[3])<< 8 |
00343 (0x0060 & q->frame.lspv[2])<< 1 |
00344 (0x0007 & q->frame.lspv[1])<< 3 |
00345 (0x0038 & q->frame.lspv[0])>> 3 ;
00346 rnd = q->rnd_fir_filter_mem + 20;
00347 for (i = 0; i < 8; i++) {
00348 tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
00349 for (k = 0; k < 20; k++) {
00350 cbseed = 521 * cbseed + 259;
00351 *rnd = (int16_t)cbseed;
00352
00353
00354 fir_filter_value = 0.0;
00355 for(j=0; j<10; j++)
00356 fir_filter_value += qcelp_rnd_fir_coefs[j ]
00357 * (rnd[-j ] + rnd[-20+j]);
00358
00359 fir_filter_value += qcelp_rnd_fir_coefs[10] * rnd[-10];
00360 *cdn_vector++ = tmp_gain * fir_filter_value;
00361 rnd++;
00362 }
00363 }
00364 memcpy(q->rnd_fir_filter_mem, q->rnd_fir_filter_mem + 160, 20 * sizeof(float));
00365 break;
00366 case RATE_OCTAVE:
00367 cbseed = q->first16bits;
00368 for (i = 0; i < 8; i++) {
00369 tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
00370 for (j = 0; j < 20; j++) {
00371 cbseed = 521 * cbseed + 259;
00372 *cdn_vector++ = tmp_gain * (int16_t)cbseed;
00373 }
00374 }
00375 break;
00376 case I_F_Q:
00377 cbseed = -44;
00378 for (i = 0; i < 4; i++) {
00379 tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
00380 for(j=0; j<40; j++)
00381 *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127];
00382 }
00383 break;
00384 case SILENCE:
00385 memset(cdn_vector, 0, 160 * sizeof(float));
00386 break;
00387 }
00388 }
00389
00399 static void apply_gain_ctrl(float *v_out, const float *v_ref,
00400 const float *v_in)
00401 {
00402 int i;
00403
00404 for (i = 0; i < 160; i += 40)
00405 ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i,
00406 ff_dot_productf(v_ref + i,
00407 v_ref + i, 40),
00408 40);
00409 }
00410
00428 static const float *do_pitchfilter(float memory[303], const float v_in[160],
00429 const float gain[4], const uint8_t *lag,
00430 const uint8_t pfrac[4])
00431 {
00432 int i, j;
00433 float *v_lag, *v_out;
00434 const float *v_len;
00435
00436 v_out = memory + 143;
00437
00438 for (i = 0; i < 4; i++) {
00439 if (gain[i]) {
00440 v_lag = memory + 143 + 40 * i - lag[i];
00441 for (v_len = v_in + 40; v_in < v_len; v_in++) {
00442 if (pfrac[i]) {
00443 for(j=0, *v_out=0.; j<4; j++)
00444 *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
00445 }else
00446 *v_out = *v_lag;
00447
00448 *v_out = *v_in + gain[i] * *v_out;
00449
00450 v_lag++;
00451 v_out++;
00452 }
00453 } else {
00454 memcpy(v_out, v_in, 40 * sizeof(float));
00455 v_in += 40;
00456 v_out += 40;
00457 }
00458 }
00459
00460 memmove(memory, memory + 160, 143 * sizeof(float));
00461 return memory + 143;
00462 }
00463
00471 static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
00472 {
00473 int i;
00474 const float *v_synthesis_filtered, *v_pre_filtered;
00475
00476 if(q->bitrate >= RATE_HALF ||
00477 q->bitrate == SILENCE ||
00478 (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) {
00479
00480 if(q->bitrate >= RATE_HALF) {
00481
00482
00483 for (i = 0; i < 4; i++) {
00484 q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0;
00485
00486 q->pitch_lag[i] = q->frame.plag[i] + 16;
00487 }
00488 } else {
00489 float max_pitch_gain;
00490
00491 if (q->bitrate == I_F_Q) {
00492 if (q->erasure_count < 3)
00493 max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1);
00494 else
00495 max_pitch_gain = 0.0;
00496 } else {
00497 assert(q->bitrate == SILENCE);
00498 max_pitch_gain = 1.0;
00499 }
00500 for(i=0; i<4; i++)
00501 q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain);
00502
00503 memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac));
00504 }
00505
00506
00507 v_synthesis_filtered = do_pitchfilter(q->pitch_synthesis_filter_mem,
00508 cdn_vector, q->pitch_gain,
00509 q->pitch_lag, q->frame.pfrac);
00510
00511
00512 for(i=0; i<4; i++)
00513 q->pitch_gain[i] = 0.5 * FFMIN(q->pitch_gain[i], 1.0);
00514
00515 v_pre_filtered = do_pitchfilter(q->pitch_pre_filter_mem,
00516 v_synthesis_filtered,
00517 q->pitch_gain, q->pitch_lag,
00518 q->frame.pfrac);
00519
00520 apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered);
00521 } else {
00522 memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17,
00523 143 * sizeof(float));
00524 memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float));
00525 memset(q->pitch_gain, 0, sizeof(q->pitch_gain));
00526 memset(q->pitch_lag, 0, sizeof(q->pitch_lag));
00527 }
00528 }
00529
00542 static void lspf2lpc(const float *lspf, float *lpc)
00543 {
00544 double lsp[10];
00545 double bandwidth_expansion_coeff = QCELP_BANDWIDTH_EXPANSION_COEFF;
00546 int i;
00547
00548 for (i=0; i<10; i++)
00549 lsp[i] = cos(M_PI * lspf[i]);
00550
00551 ff_acelp_lspd2lpc(lsp, lpc, 5);
00552
00553 for (i = 0; i < 10; i++) {
00554 lpc[i] *= bandwidth_expansion_coeff;
00555 bandwidth_expansion_coeff *= QCELP_BANDWIDTH_EXPANSION_COEFF;
00556 }
00557 }
00558
00570 static void interpolate_lpc(QCELPContext *q, const float *curr_lspf,
00571 float *lpc, const int subframe_num)
00572 {
00573 float interpolated_lspf[10];
00574 float weight;
00575
00576 if(q->bitrate >= RATE_QUARTER)
00577 weight = 0.25 * (subframe_num + 1);
00578 else if(q->bitrate == RATE_OCTAVE && !subframe_num)
00579 weight = 0.625;
00580 else
00581 weight = 1.0;
00582
00583 if (weight != 1.0) {
00584 ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
00585 weight, 1.0 - weight, 10);
00586 lspf2lpc(interpolated_lspf, lpc);
00587 }else if(q->bitrate >= RATE_QUARTER ||
00588 (q->bitrate == I_F_Q && !subframe_num))
00589 lspf2lpc(curr_lspf, lpc);
00590 else if(q->bitrate == SILENCE && !subframe_num)
00591 lspf2lpc(q->prev_lspf, lpc);
00592 }
00593
00594 static qcelp_packet_rate buf_size2bitrate(const int buf_size)
00595 {
00596 switch (buf_size) {
00597 case 35: return RATE_FULL;
00598 case 17: return RATE_HALF;
00599 case 8: return RATE_QUARTER;
00600 case 4: return RATE_OCTAVE;
00601 case 1: return SILENCE;
00602 }
00603
00604 return I_F_Q;
00605 }
00606
00619 static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_size,
00620 const uint8_t **buf)
00621 {
00622 qcelp_packet_rate bitrate;
00623
00624 if ((bitrate = buf_size2bitrate(buf_size)) >= 0) {
00625 if (bitrate > **buf) {
00626 QCELPContext *q = avctx->priv_data;
00627 if (!q->warned_buf_mismatch_bitrate) {
00628 av_log(avctx, AV_LOG_WARNING,
00629 "Claimed bitrate and buffer size mismatch.\n");
00630 q->warned_buf_mismatch_bitrate = 1;
00631 }
00632 bitrate = **buf;
00633 } else if (bitrate < **buf) {
00634 av_log(avctx, AV_LOG_ERROR,
00635 "Buffer is too small for the claimed bitrate.\n");
00636 return I_F_Q;
00637 }
00638 (*buf)++;
00639 } else if ((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) {
00640 av_log(avctx, AV_LOG_WARNING,
00641 "Bitrate byte is missing, guessing the bitrate from packet size.\n");
00642 }else
00643 return I_F_Q;
00644
00645 if (bitrate == SILENCE) {
00646
00647 av_log_ask_for_sample(avctx, "'Blank frame handling is experimental.");
00648 }
00649 return bitrate;
00650 }
00651
00652 static void warn_insufficient_frame_quality(AVCodecContext *avctx,
00653 const char *message)
00654 {
00655 av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number,
00656 message);
00657 }
00658
00659 static void postfilter(QCELPContext *q, float *samples, float *lpc)
00660 {
00661 static const float pow_0_775[10] = {
00662 0.775000, 0.600625, 0.465484, 0.360750, 0.279582,
00663 0.216676, 0.167924, 0.130141, 0.100859, 0.078166
00664 }, pow_0_625[10] = {
00665 0.625000, 0.390625, 0.244141, 0.152588, 0.095367,
00666 0.059605, 0.037253, 0.023283, 0.014552, 0.009095
00667 };
00668 float lpc_s[10], lpc_p[10], pole_out[170], zero_out[160];
00669 int n;
00670
00671 for (n = 0; n < 10; n++) {
00672 lpc_s[n] = lpc[n] * pow_0_625[n];
00673 lpc_p[n] = lpc[n] * pow_0_775[n];
00674 }
00675
00676 ff_celp_lp_zero_synthesis_filterf(zero_out, lpc_s,
00677 q->formant_mem + 10, 160, 10);
00678 memcpy(pole_out, q->postfilter_synth_mem, sizeof(float) * 10);
00679 ff_celp_lp_synthesis_filterf(pole_out + 10, lpc_p, zero_out, 160, 10);
00680 memcpy(q->postfilter_synth_mem, pole_out + 160, sizeof(float) * 10);
00681
00682 ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160);
00683
00684 ff_adaptive_gain_control(samples, pole_out + 10,
00685 ff_dot_productf(q->formant_mem + 10, q->formant_mem + 10, 160),
00686 160, 0.9375, &q->postfilter_agc_mem);
00687 }
00688
00689 static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
00690 int *got_frame_ptr, AVPacket *avpkt)
00691 {
00692 const uint8_t *buf = avpkt->data;
00693 int buf_size = avpkt->size;
00694 QCELPContext *q = avctx->priv_data;
00695 float *outbuffer;
00696 int i, ret;
00697 float quantized_lspf[10], lpc[10];
00698 float gain[16];
00699 float *formant_mem;
00700
00701
00702 q->avframe.nb_samples = 160;
00703 if ((ret = avctx->get_buffer(avctx, &q->avframe)) < 0) {
00704 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00705 return ret;
00706 }
00707 outbuffer = (float *)q->avframe.data[0];
00708
00709 if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) {
00710 warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
00711 goto erasure;
00712 }
00713
00714 if(q->bitrate == RATE_OCTAVE &&
00715 (q->first16bits = AV_RB16(buf)) == 0xFFFF) {
00716 warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on.");
00717 goto erasure;
00718 }
00719
00720 if (q->bitrate > SILENCE) {
00721 const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate];
00722 const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate]
00723 + qcelp_unpacking_bitmaps_lengths[q->bitrate];
00724 uint8_t *unpacked_data = (uint8_t *)&q->frame;
00725
00726 init_get_bits(&q->gb, buf, 8*buf_size);
00727
00728 memset(&q->frame, 0, sizeof(QCELPFrame));
00729
00730 for(; bitmaps < bitmaps_end; bitmaps++)
00731 unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos;
00732
00733
00734 if (q->frame.reserved) {
00735 warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area.");
00736 goto erasure;
00737 }
00738 if(q->bitrate == RATE_QUARTER &&
00739 codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) {
00740 warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed.");
00741 goto erasure;
00742 }
00743
00744 if (q->bitrate >= RATE_HALF) {
00745 for (i = 0; i < 4; i++) {
00746 if (q->frame.pfrac[i] && q->frame.plag[i] >= 124) {
00747 warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter.");
00748 goto erasure;
00749 }
00750 }
00751 }
00752 }
00753
00754 decode_gain_and_index(q, gain);
00755 compute_svector(q, gain, outbuffer);
00756
00757 if (decode_lspf(q, quantized_lspf) < 0) {
00758 warn_insufficient_frame_quality(avctx, "Badly received packets in frame.");
00759 goto erasure;
00760 }
00761
00762
00763 apply_pitch_filters(q, outbuffer);
00764
00765 if (q->bitrate == I_F_Q) {
00766 erasure:
00767 q->bitrate = I_F_Q;
00768 q->erasure_count++;
00769 decode_gain_and_index(q, gain);
00770 compute_svector(q, gain, outbuffer);
00771 decode_lspf(q, quantized_lspf);
00772 apply_pitch_filters(q, outbuffer);
00773 }else
00774 q->erasure_count = 0;
00775
00776 formant_mem = q->formant_mem + 10;
00777 for (i = 0; i < 4; i++) {
00778 interpolate_lpc(q, quantized_lspf, lpc, i);
00779 ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40,
00780 10);
00781 formant_mem += 40;
00782 }
00783
00784
00785 postfilter(q, outbuffer, lpc);
00786
00787 memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float));
00788
00789 memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf));
00790 q->prev_bitrate = q->bitrate;
00791
00792 *got_frame_ptr = 1;
00793 *(AVFrame *)data = q->avframe;
00794
00795 return buf_size;
00796 }
00797
00798 AVCodec ff_qcelp_decoder =
00799 {
00800 .name = "qcelp",
00801 .type = AVMEDIA_TYPE_AUDIO,
00802 .id = CODEC_ID_QCELP,
00803 .init = qcelp_decode_init,
00804 .decode = qcelp_decode_frame,
00805 .capabilities = CODEC_CAP_DR1,
00806 .priv_data_size = sizeof(QCELPContext),
00807 .long_name = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"),
00808 };