annotate src/opus-1.3/silk/fixed/find_pitch_lags_FIX.c @ 83:ae30d91d2ffe

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