annotate src/opus-1.3/silk/float/find_pitch_lags_FLP.c @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +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 <stdlib.h>
Chris@69 33 #include "main_FLP.h"
Chris@69 34 #include "tuning_parameters.h"
Chris@69 35
Chris@69 36 void silk_find_pitch_lags_FLP(
Chris@69 37 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
Chris@69 38 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
Chris@69 39 silk_float res[], /* O Residual */
Chris@69 40 const silk_float x[], /* I Speech signal */
Chris@69 41 int arch /* I Run-time architecture */
Chris@69 42 )
Chris@69 43 {
Chris@69 44 opus_int buf_len;
Chris@69 45 silk_float thrhld, res_nrg;
Chris@69 46 const silk_float *x_buf_ptr, *x_buf;
Chris@69 47 silk_float auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
Chris@69 48 silk_float A[ MAX_FIND_PITCH_LPC_ORDER ];
Chris@69 49 silk_float refl_coef[ MAX_FIND_PITCH_LPC_ORDER ];
Chris@69 50 silk_float Wsig[ FIND_PITCH_LPC_WIN_MAX ];
Chris@69 51 silk_float *Wsig_ptr;
Chris@69 52
Chris@69 53 /******************************************/
Chris@69 54 /* Set up buffer lengths etc based on Fs */
Chris@69 55 /******************************************/
Chris@69 56 buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
Chris@69 57
Chris@69 58 /* Safety check */
Chris@69 59 celt_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
Chris@69 60
Chris@69 61 x_buf = x - psEnc->sCmn.ltp_mem_length;
Chris@69 62
Chris@69 63 /******************************************/
Chris@69 64 /* Estimate LPC AR coeficients */
Chris@69 65 /******************************************/
Chris@69 66
Chris@69 67 /* Calculate windowed signal */
Chris@69 68
Chris@69 69 /* First LA_LTP samples */
Chris@69 70 x_buf_ptr = x_buf + buf_len - psEnc->sCmn.pitch_LPC_win_length;
Chris@69 71 Wsig_ptr = Wsig;
Chris@69 72 silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
Chris@69 73
Chris@69 74 /* Middle non-windowed samples */
Chris@69 75 Wsig_ptr += psEnc->sCmn.la_pitch;
Chris@69 76 x_buf_ptr += psEnc->sCmn.la_pitch;
Chris@69 77 silk_memcpy( Wsig_ptr, x_buf_ptr, ( psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ) ) * sizeof( silk_float ) );
Chris@69 78
Chris@69 79 /* Last LA_LTP samples */
Chris@69 80 Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 );
Chris@69 81 x_buf_ptr += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 );
Chris@69 82 silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );
Chris@69 83
Chris@69 84 /* Calculate autocorrelation sequence */
Chris@69 85 silk_autocorrelation_FLP( auto_corr, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 );
Chris@69 86
Chris@69 87 /* Add white noise, as a fraction of the energy */
Chris@69 88 auto_corr[ 0 ] += auto_corr[ 0 ] * FIND_PITCH_WHITE_NOISE_FRACTION + 1;
Chris@69 89
Chris@69 90 /* Calculate the reflection coefficients using Schur */
Chris@69 91 res_nrg = silk_schur_FLP( refl_coef, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
Chris@69 92
Chris@69 93 /* Prediction gain */
Chris@69 94 psEncCtrl->predGain = auto_corr[ 0 ] / silk_max_float( res_nrg, 1.0f );
Chris@69 95
Chris@69 96 /* Convert reflection coefficients to prediction coefficients */
Chris@69 97 silk_k2a_FLP( A, refl_coef, psEnc->sCmn.pitchEstimationLPCOrder );
Chris@69 98
Chris@69 99 /* Bandwidth expansion */
Chris@69 100 silk_bwexpander_FLP( A, psEnc->sCmn.pitchEstimationLPCOrder, FIND_PITCH_BANDWIDTH_EXPANSION );
Chris@69 101
Chris@69 102 /*****************************************/
Chris@69 103 /* LPC analysis filtering */
Chris@69 104 /*****************************************/
Chris@69 105 silk_LPC_analysis_filter_FLP( res, A, x_buf, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
Chris@69 106
Chris@69 107 if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) {
Chris@69 108 /* Threshold for pitch estimator */
Chris@69 109 thrhld = 0.6f;
Chris@69 110 thrhld -= 0.004f * psEnc->sCmn.pitchEstimationLPCOrder;
Chris@69 111 thrhld -= 0.1f * psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f );
Chris@69 112 thrhld -= 0.15f * (psEnc->sCmn.prevSignalType >> 1);
Chris@69 113 thrhld -= 0.1f * psEnc->sCmn.input_tilt_Q15 * ( 1.0f / 32768.0f );
Chris@69 114
Chris@69 115 /*****************************************/
Chris@69 116 /* Call Pitch estimator */
Chris@69 117 /*****************************************/
Chris@69 118 if( silk_pitch_analysis_core_FLP( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex,
Chris@69 119 &psEnc->sCmn.indices.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16 / 65536.0f,
Chris@69 120 thrhld, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr, arch ) == 0 )
Chris@69 121 {
Chris@69 122 psEnc->sCmn.indices.signalType = TYPE_VOICED;
Chris@69 123 } else {
Chris@69 124 psEnc->sCmn.indices.signalType = TYPE_UNVOICED;
Chris@69 125 }
Chris@69 126 } else {
Chris@69 127 silk_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) );
Chris@69 128 psEnc->sCmn.indices.lagIndex = 0;
Chris@69 129 psEnc->sCmn.indices.contourIndex = 0;
Chris@69 130 psEnc->LTPCorr = 0;
Chris@69 131 }
Chris@69 132 }