comparison qcelpdec.c @ 8479:e818b3c06712 libavcodec

Part 2 of Kenan Gillet's QCELP silence handling patch.
author reynaldo
date Fri, 26 Dec 2008 16:49:06 +0000
parents c7e800518b8b
children c0f1e9a9402c
comparison
equal deleted inserted replaced
8478:2f7c09bb6bfb 8479:e818b3c06712
413 tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; 413 tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
414 for(j=0; j<40; j++) 414 for(j=0; j<40; j++)
415 *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127]; 415 *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127];
416 } 416 }
417 break; 417 break;
418 case SILENCE:
419 memset(cdn_vector, 0, 160 * sizeof(float));
420 break;
418 } 421 }
419 } 422 }
420 423
421 /** 424 /**
422 * Apply generic gain control. 425 * Apply generic gain control.
508 return memory + 143; 511 return memory + 143;
509 } 512 }
510 513
511 /** 514 /**
512 * Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector. 515 * Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.
513 * TIA/EIA/IS-733 2.4.5.2 516 * TIA/EIA/IS-733 2.4.5.2, 2.4.8.7.2
514 * 517 *
515 * @param q the context 518 * @param q the context
516 * @param cdn_vector the scaled codebook vector 519 * @param cdn_vector the scaled codebook vector
517 */ 520 */
518 static void apply_pitch_filters(QCELPContext *q, float *cdn_vector) 521 static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
519 { 522 {
520 int i; 523 int i;
521 const float *v_synthesis_filtered, *v_pre_filtered; 524 const float *v_synthesis_filtered, *v_pre_filtered;
522 525
523 if(q->bitrate >= RATE_HALF || 526 if(q->bitrate >= RATE_HALF ||
527 q->bitrate == SILENCE ||
524 (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) 528 (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF)))
525 { 529 {
526 530
527 if(q->bitrate >= RATE_HALF) 531 if(q->bitrate >= RATE_HALF)
528 { 532 {
536 } 540 }
537 }else 541 }else
538 { 542 {
539 float max_pitch_gain; 543 float max_pitch_gain;
540 544
545 if (q->bitrate == I_F_Q)
546 {
541 if (q->erasure_count < 3) 547 if (q->erasure_count < 3)
542 max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1); 548 max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1);
543 else 549 else
544 max_pitch_gain = 0.0; 550 max_pitch_gain = 0.0;
551 }else
552 {
553 assert(q->bitrate == SILENCE);
554 max_pitch_gain = 1.0;
555 }
545 for(i=0; i<4; i++) 556 for(i=0; i<4; i++)
546 q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain); 557 q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain);
547 558
548 memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac)); 559 memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac));
549 } 560 }
575 586
576 /** 587 /**
577 * Interpolates LSP frequencies and computes LPC coefficients 588 * Interpolates LSP frequencies and computes LPC coefficients
578 * for a given bitrate & pitch subframe. 589 * for a given bitrate & pitch subframe.
579 * 590 *
580 * TIA/EIA/IS-733 2.4.3.3.4 591 * TIA/EIA/IS-733 2.4.3.3.4, 2.4.8.7.2
581 * 592 *
582 * @param q the context 593 * @param q the context
583 * @param curr_lspf LSP frequencies vector of the current frame 594 * @param curr_lspf LSP frequencies vector of the current frame
584 * @param lpc float vector for the resulting LPC 595 * @param lpc float vector for the resulting LPC
585 * @param subframe_num frame number in decoded stream 596 * @param subframe_num frame number in decoded stream
603 weight, 1.0 - weight, 10); 614 weight, 1.0 - weight, 10);
604 ff_qcelp_lspf2lpc(interpolated_lspf, lpc); 615 ff_qcelp_lspf2lpc(interpolated_lspf, lpc);
605 }else if(q->bitrate >= RATE_QUARTER || 616 }else if(q->bitrate >= RATE_QUARTER ||
606 (q->bitrate == I_F_Q && !subframe_num)) 617 (q->bitrate == I_F_Q && !subframe_num))
607 ff_qcelp_lspf2lpc(curr_lspf, lpc); 618 ff_qcelp_lspf2lpc(curr_lspf, lpc);
619 else if(q->bitrate == SILENCE && !subframe_num)
620 ff_qcelp_lspf2lpc(q->prev_lspf, lpc);
608 } 621 }
609 622
610 static qcelp_packet_rate buf_size2bitrate(const int buf_size) 623 static qcelp_packet_rate buf_size2bitrate(const int buf_size)
611 { 624 {
612 switch(buf_size) 625 switch(buf_size)
664 }else 677 }else
665 return I_F_Q; 678 return I_F_Q;
666 679
667 if(bitrate == SILENCE) 680 if(bitrate == SILENCE)
668 { 681 {
669 // FIXME: the decoder should not handle SILENCE frames as I_F_Q frames 682 //FIXME: Remove experimental warning when tested with samples.
670 ff_log_missing_feature(avctx, "Blank frame", 1); 683 av_log(avctx, AV_LOG_WARNING, "'Blank frame handling is experimental."
671 bitrate = I_F_Q; 684 " If you want to help, upload a sample "
685 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
686 "and contact the ffmpeg-devel mailing list.\n");
672 } 687 }
673 return bitrate; 688 return bitrate;
674 } 689 }
675 690
676 static void warn_insufficient_frame_quality(AVCodecContext *avctx, 691 static void warn_insufficient_frame_quality(AVCodecContext *avctx,