media/libopus/silk/float/find_pred_coefs_FLP.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /***********************************************************************
michael@0 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
michael@0 3 Redistribution and use in source and binary forms, with or without
michael@0 4 modification, are permitted provided that the following conditions
michael@0 5 are met:
michael@0 6 - Redistributions of source code must retain the above copyright notice,
michael@0 7 this list of conditions and the following disclaimer.
michael@0 8 - Redistributions in binary form must reproduce the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer in the
michael@0 10 documentation and/or other materials provided with the distribution.
michael@0 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
michael@0 12 names of specific contributors, may be used to endorse or promote
michael@0 13 products derived from this software without specific prior written
michael@0 14 permission.
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 25 POSSIBILITY OF SUCH DAMAGE.
michael@0 26 ***********************************************************************/
michael@0 27
michael@0 28 #ifdef HAVE_CONFIG_H
michael@0 29 #include "config.h"
michael@0 30 #endif
michael@0 31
michael@0 32 #include "main_FLP.h"
michael@0 33
michael@0 34 /* Find LPC and LTP coefficients */
michael@0 35 void silk_find_pred_coefs_FLP(
michael@0 36 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
michael@0 37 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
michael@0 38 const silk_float res_pitch[], /* I Residual from pitch analysis */
michael@0 39 const silk_float x[], /* I Speech signal */
michael@0 40 opus_int condCoding /* I The type of conditional coding to use */
michael@0 41 )
michael@0 42 {
michael@0 43 opus_int i;
michael@0 44 silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
michael@0 45 silk_float invGains[ MAX_NB_SUBFR ], Wght[ MAX_NB_SUBFR ];
michael@0 46 opus_int16 NLSF_Q15[ MAX_LPC_ORDER ];
michael@0 47 const silk_float *x_ptr;
michael@0 48 silk_float *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];
michael@0 49 silk_float minInvGain;
michael@0 50
michael@0 51 /* Weighting for weighted least squares */
michael@0 52 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
michael@0 53 silk_assert( psEncCtrl->Gains[ i ] > 0.0f );
michael@0 54 invGains[ i ] = 1.0f / psEncCtrl->Gains[ i ];
michael@0 55 Wght[ i ] = invGains[ i ] * invGains[ i ];
michael@0 56 }
michael@0 57
michael@0 58 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
michael@0 59 /**********/
michael@0 60 /* VOICED */
michael@0 61 /**********/
michael@0 62 silk_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 );
michael@0 63
michael@0 64 /* LTP analysis */
michael@0 65 silk_find_LTP_FLP( psEncCtrl->LTPCoef, WLTP, &psEncCtrl->LTPredCodGain, res_pitch,
michael@0 66 psEncCtrl->pitchL, Wght, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length );
michael@0 67
michael@0 68 /* Quantize LTP gain parameters */
michael@0 69 silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex,
michael@0 70 &psEnc->sCmn.sum_log_gain_Q7, WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr );
michael@0 71
michael@0 72 /* Control LTP scaling */
michael@0 73 silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl, condCoding );
michael@0 74
michael@0 75 /* Create LTP residual */
michael@0 76 silk_LTP_analysis_filter_FLP( LPC_in_pre, x - psEnc->sCmn.predictLPCOrder, psEncCtrl->LTPCoef,
michael@0 77 psEncCtrl->pitchL, invGains, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder );
michael@0 78 } else {
michael@0 79 /************/
michael@0 80 /* UNVOICED */
michael@0 81 /************/
michael@0 82 /* Create signal with prepended subframes, scaled by inverse gains */
michael@0 83 x_ptr = x - psEnc->sCmn.predictLPCOrder;
michael@0 84 x_pre_ptr = LPC_in_pre;
michael@0 85 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
michael@0 86 silk_scale_copy_vector_FLP( x_pre_ptr, x_ptr, invGains[ i ],
michael@0 87 psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder );
michael@0 88 x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder;
michael@0 89 x_ptr += psEnc->sCmn.subfr_length;
michael@0 90 }
michael@0 91 silk_memset( psEncCtrl->LTPCoef, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( silk_float ) );
michael@0 92 psEncCtrl->LTPredCodGain = 0.0f;
michael@0 93 psEnc->sCmn.sum_log_gain_Q7 = 0;
michael@0 94 }
michael@0 95
michael@0 96 /* Limit on total predictive coding gain */
michael@0 97 if( psEnc->sCmn.first_frame_after_reset ) {
michael@0 98 minInvGain = 1.0f / MAX_PREDICTION_POWER_GAIN_AFTER_RESET;
michael@0 99 } else {
michael@0 100 minInvGain = (silk_float)pow( 2, psEncCtrl->LTPredCodGain / 3 ) / MAX_PREDICTION_POWER_GAIN;
michael@0 101 minInvGain /= 0.25f + 0.75f * psEncCtrl->coding_quality;
michael@0 102 }
michael@0 103
michael@0 104 /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */
michael@0 105 silk_find_LPC_FLP( &psEnc->sCmn, NLSF_Q15, LPC_in_pre, minInvGain );
michael@0 106
michael@0 107 /* Quantize LSFs */
michael@0 108 silk_process_NLSFs_FLP( &psEnc->sCmn, psEncCtrl->PredCoef, NLSF_Q15, psEnc->sCmn.prev_NLSFq_Q15 );
michael@0 109
michael@0 110 /* Calculate residual energy using quantized LPC coefficients */
michael@0 111 silk_residual_energy_FLP( psEncCtrl->ResNrg, LPC_in_pre, psEncCtrl->PredCoef, psEncCtrl->Gains,
michael@0 112 psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder );
michael@0 113
michael@0 114 /* Copy to prediction struct for use in next frame for interpolation */
michael@0 115 silk_memcpy( psEnc->sCmn.prev_NLSFq_Q15, NLSF_Q15, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) );
michael@0 116 }
michael@0 117

mercurial