annotate src/opus-1.3/silk/fixed/find_pitch_lags_FIX.c @ 157:570d27da3fb5

Update exclusion list
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 25 Jan 2019 13:49:22 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifdef HAVE_CONFIG_H
cannam@154 29 #include "config.h"
cannam@154 30 #endif
cannam@154 31
cannam@154 32 #include "main_FIX.h"
cannam@154 33 #include "stack_alloc.h"
cannam@154 34 #include "tuning_parameters.h"
cannam@154 35
cannam@154 36 /* Find pitch lags */
cannam@154 37 void silk_find_pitch_lags_FIX(
cannam@154 38 silk_encoder_state_FIX *psEnc, /* I/O encoder state */
cannam@154 39 silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
cannam@154 40 opus_int16 res[], /* O residual */
cannam@154 41 const opus_int16 x[], /* I Speech signal */
cannam@154 42 int arch /* I Run-time architecture */
cannam@154 43 )
cannam@154 44 {
cannam@154 45 opus_int buf_len, i, scale;
cannam@154 46 opus_int32 thrhld_Q13, res_nrg;
cannam@154 47 const opus_int16 *x_ptr;
cannam@154 48 VARDECL( opus_int16, Wsig );
cannam@154 49 opus_int16 *Wsig_ptr;
cannam@154 50 opus_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
cannam@154 51 opus_int16 rc_Q15[ MAX_FIND_PITCH_LPC_ORDER ];
cannam@154 52 opus_int32 A_Q24[ MAX_FIND_PITCH_LPC_ORDER ];
cannam@154 53 opus_int16 A_Q12[ MAX_FIND_PITCH_LPC_ORDER ];
cannam@154 54 SAVE_STACK;
cannam@154 55
cannam@154 56 /******************************************/
cannam@154 57 /* Set up buffer lengths etc based on Fs */
cannam@154 58 /******************************************/
cannam@154 59 buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
cannam@154 60
cannam@154 61 /* Safety check */
cannam@154 62 celt_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
cannam@154 63
cannam@154 64 /*************************************/
cannam@154 65 /* Estimate LPC AR coefficients */
cannam@154 66 /*************************************/
cannam@154 67
cannam@154 68 /* Calculate windowed signal */
cannam@154 69
cannam@154 70 ALLOC( Wsig, psEnc->sCmn.pitch_LPC_win_length, opus_int16 );
cannam@154 71
cannam@154 72 /* First LA_LTP samples */
cannam@154 73 x_ptr = x + buf_len - psEnc->sCmn.pitch_LPC_win_length;
cannam@154 74 Wsig_ptr = Wsig;
cannam@154 75 silk_apply_sine_window( Wsig_ptr, x_ptr, 1, psEnc->sCmn.la_pitch );
cannam@154 76
cannam@154 77 /* Middle un - windowed samples */
cannam@154 78 Wsig_ptr += psEnc->sCmn.la_pitch;
cannam@154 79 x_ptr += psEnc->sCmn.la_pitch;
cannam@154 80 silk_memcpy( Wsig_ptr, x_ptr, ( psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( opus_int16 ) );
cannam@154 81
cannam@154 82 /* Last LA_LTP samples */
cannam@154 83 Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 );
cannam@154 84 x_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 );
cannam@154 85 silk_apply_sine_window( Wsig_ptr, x_ptr, 2, psEnc->sCmn.la_pitch );
cannam@154 86
cannam@154 87 /* Calculate autocorrelation sequence */
cannam@154 88 silk_autocorr( auto_corr, &scale, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1, arch );
cannam@154 89
cannam@154 90 /* Add white noise, as fraction of energy */
cannam@154 91 auto_corr[ 0 ] = silk_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SILK_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) ) + 1;
cannam@154 92
cannam@154 93 /* Calculate the reflection coefficients using schur */
cannam@154 94 res_nrg = silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
cannam@154 95
cannam@154 96 /* Prediction gain */
cannam@154 97 psEncCtrl->predGain_Q16 = silk_DIV32_varQ( auto_corr[ 0 ], silk_max_int( res_nrg, 1 ), 16 );
cannam@154 98
cannam@154 99 /* Convert reflection coefficients to prediction coefficients */
cannam@154 100 silk_k2a( A_Q24, rc_Q15, psEnc->sCmn.pitchEstimationLPCOrder );
cannam@154 101
cannam@154 102 /* Convert From 32 bit Q24 to 16 bit Q12 coefs */
cannam@154 103 for( i = 0; i < psEnc->sCmn.pitchEstimationLPCOrder; i++ ) {
cannam@154 104 A_Q12[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT( A_Q24[ i ], 12 ) );
cannam@154 105 }
cannam@154 106
cannam@154 107 /* Do BWE */
cannam@154 108 silk_bwexpander( A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, SILK_FIX_CONST( FIND_PITCH_BANDWIDTH_EXPANSION, 16 ) );
cannam@154 109
cannam@154 110 /*****************************************/
cannam@154 111 /* LPC analysis filtering */
cannam@154 112 /*****************************************/
cannam@154 113 silk_LPC_analysis_filter( res, x, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.arch );
cannam@154 114
cannam@154 115 if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) {
cannam@154 116 /* Threshold for pitch estimator */
cannam@154 117 thrhld_Q13 = SILK_FIX_CONST( 0.6, 13 );
cannam@154 118 thrhld_Q13 = silk_SMLABB( thrhld_Q13, SILK_FIX_CONST( -0.004, 13 ), psEnc->sCmn.pitchEstimationLPCOrder );
cannam@154 119 thrhld_Q13 = silk_SMLAWB( thrhld_Q13, SILK_FIX_CONST( -0.1, 21 ), psEnc->sCmn.speech_activity_Q8 );
cannam@154 120 thrhld_Q13 = silk_SMLABB( thrhld_Q13, SILK_FIX_CONST( -0.15, 13 ), silk_RSHIFT( psEnc->sCmn.prevSignalType, 1 ) );
cannam@154 121 thrhld_Q13 = silk_SMLAWB( thrhld_Q13, SILK_FIX_CONST( -0.1, 14 ), psEnc->sCmn.input_tilt_Q15 );
cannam@154 122 thrhld_Q13 = silk_SAT16( thrhld_Q13 );
cannam@154 123
cannam@154 124 /*****************************************/
cannam@154 125 /* Call pitch estimator */
cannam@154 126 /*****************************************/
cannam@154 127 if( silk_pitch_analysis_core( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex, &psEnc->sCmn.indices.contourIndex,
cannam@154 128 &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16,
cannam@154 129 (opus_int)thrhld_Q13, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr,
cannam@154 130 psEnc->sCmn.arch) == 0 )
cannam@154 131 {
cannam@154 132 psEnc->sCmn.indices.signalType = TYPE_VOICED;
cannam@154 133 } else {
cannam@154 134 psEnc->sCmn.indices.signalType = TYPE_UNVOICED;
cannam@154 135 }
cannam@154 136 } else {
cannam@154 137 silk_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) );
cannam@154 138 psEnc->sCmn.indices.lagIndex = 0;
cannam@154 139 psEnc->sCmn.indices.contourIndex = 0;
cannam@154 140 psEnc->LTPCorr_Q15 = 0;
cannam@154 141 }
cannam@154 142 RESTORE_STACK;
cannam@154 143 }