/*********************************************************************** Copyright (c) 2006-2011, Skype Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of Internet Society, IETF or IETF Trust, nor the names of specific contributors, may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#ifdef HAVE_CONFIG_H #include"config.h" #endif
/***************************************************************************** * Pitch analyser function
******************************************************************************/ #include"SigProc_FLP.h" #include"SigProc_FIX.h" #include"pitch_est_defines.h" #include"pitch.h"
#define SCRATCH_SIZE 22
/************************************************************/ /* Internally used functions */ /************************************************************/ staticvoid silk_P_Ana_calc_corr_st3(
silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ const silk_float frame[], /* I vector to correlate */
opus_int start_lag, /* I start lag */
opus_int sf_length, /* I sub frame length */
opus_int nb_subfr, /* I number of subframes */
opus_int complexity, /* I Complexity setting */ int arch /* I Run-time architecture */
);
staticvoid silk_P_Ana_calc_energy_st3(
silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ const silk_float frame[], /* I vector to correlate */
opus_int start_lag, /* I start lag */
opus_int sf_length, /* I sub frame length */
opus_int nb_subfr, /* I number of subframes */
opus_int complexity /* I Complexity setting */
);
/************************************************************/ /* CORE PITCH ANALYSIS FUNCTION */ /************************************************************/
opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */ const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */
opus_int16 *lagIndex, /* O Lag Index */
opus_int8 *contourIndex, /* O Pitch contour Index */
silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */
opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */ const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */ const opus_int Fs_kHz, /* I sample frequency (kHz) */ const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ const opus_int nb_subfr, /* I Number of 5 ms subframes */ int arch /* I Run-time architecture */
)
{
opus_int i, k, d, j;
silk_float frame_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ];
silk_float frame_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ];
opus_int16 frame_8_FIX[ PE_MAX_FRAME_LENGTH_MS * 8 ];
opus_int16 frame_4_FIX[ PE_MAX_FRAME_LENGTH_MS * 4 ];
opus_int32 filt_state[ 6 ];
silk_float threshold, contour_bias;
silk_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ];
opus_val32 xcorr[ PE_MAX_LAG_MS * 4 - PE_MIN_LAG_MS * 4 + 1 ];
silk_float CC[ PE_NB_CBKS_STAGE2_EXT ]; const silk_float *target_ptr, *basis_ptr; double cross_corr, normalizer, energy, energy_tmp;
opus_int d_srch[ PE_D_SRCH_LENGTH ];
opus_int16 d_comp[ (PE_MAX_LAG >> 1) + 5 ];
opus_int length_d_srch, length_d_comp;
silk_float Cmax, CCmax, CCmax_b, CCmax_new_b, CCmax_new;
opus_int CBimax, CBimax_new, lag, start_lag, end_lag, lag_new;
opus_int cbk_size;
silk_float lag_log2, prevLag_log2, delta_lag_log2_sqr;
silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ];
silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ];
opus_int lag_counter;
opus_int frame_length, frame_length_8kHz, frame_length_4kHz;
opus_int sf_length, sf_length_8kHz, sf_length_4kHz;
opus_int min_lag, min_lag_8kHz, min_lag_4kHz;
opus_int max_lag, max_lag_8kHz, max_lag_4kHz;
opus_int nb_cbk_search; const opus_int8 *Lag_CB_ptr;
/* Check for valid sampling frequency */
celt_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 );
/* Low-pass filter */ for( i = frame_length_4kHz - 1; i > 0; i-- ) {
frame_4kHz[ i ] = silk_ADD_SAT16( frame_4kHz[ i ], frame_4kHz[ i - 1 ] );
}
/****************************************************************************** * FIRST STAGE, operating in 4 khz
******************************************************************************/
silk_memset(C, 0, sizeof(silk_float) * nb_subfr * ((PE_MAX_LAG >> 1) + 5));
target_ptr = &frame_4kHz[ silk_LSHIFT( sf_length_4kHz, 2 ) ]; for( k = 0; k < nb_subfr >> 1; k++ ) { /* Check that we are within range of the array */
celt_assert( target_ptr >= frame_4kHz );
celt_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
basis_ptr = target_ptr - min_lag_4kHz;
/* Check that we are within range of the array */
celt_assert( basis_ptr >= frame_4kHz );
celt_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
/* From now on normalizer is computed recursively */ for( d = min_lag_4kHz + 1; d <= max_lag_4kHz; d++ ) {
basis_ptr--;
/* Check that we are within range of the array */
silk_assert( basis_ptr >= frame_4kHz );
silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
/* Convolution */ for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) {
d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ] + d_comp[ i - 3 ];
}
length_d_comp = 0; for( i = min_lag_8kHz; i < max_lag_8kHz + 4; i++ ) { if( d_comp[ i ] > 0 ) {
d_comp[ length_d_comp ] = (opus_int16)( i - 2 );
length_d_comp++;
}
}
/********************************************************************************** ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation
*************************************************************************************/ /********************************************************************************* * Find energy of each subframe projected onto its history, for a range of delays
*********************************************************************************/
silk_memset( C, 0, PE_MAX_NB_SUBFR*((PE_MAX_LAG >> 1) + 5) * sizeof(silk_float));
for( k = 0; k < nb_subfr; k++ ) {
pitch_out[ k ] = lag_new + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size );
pitch_out[ k ] = silk_LIMIT( pitch_out[ k ], min_lag, PE_MAX_LAG_MS * Fs_kHz );
}
*lagIndex = (opus_int16)( lag_new - min_lag );
*contourIndex = (opus_int8)CBimax;
} else { /* Fs_kHz == 8 */ /* Save Lags */ for( k = 0; k < nb_subfr; k++ ) {
pitch_out[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size );
pitch_out[ k ] = silk_LIMIT( pitch_out[ k ], min_lag_8kHz, PE_MAX_LAG_MS * 8 );
}
*lagIndex = (opus_int16)( lag - min_lag_8kHz );
*contourIndex = (opus_int8)CBimax;
}
celt_assert( *lagIndex >= 0 ); /* return as voiced */ return 0;
}
/*********************************************************************** * Calculates the correlations used in stage 3 search. In order to cover * the whole lag codebook for all the searched offset lags (lag +- 2), * the following correlations are needed in each sub frame: * * sf1: lag range [-8,...,7] total 16 correlations * sf2: lag range [-4,...,4] total 9 correlations * sf3: lag range [-3,....4] total 8 correltions * sf4: lag range [-6,....8] total 15 correlations * * In total 48 correlations. The direct implementation computed in worst * case 4*12*5 = 240 correlations, but more likely around 120.
***********************************************************************/ staticvoid silk_P_Ana_calc_corr_st3(
silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ const silk_float frame[], /* I vector to correlate */
opus_int start_lag, /* I start lag */
opus_int sf_length, /* I sub frame length */
opus_int nb_subfr, /* I number of subframes */
opus_int complexity, /* I Complexity setting */ int arch /* I Run-time architecture */
)
{ const silk_float *target_ptr;
opus_int i, j, k, lag_counter, lag_low, lag_high;
opus_int nb_cbk_search, delta, idx, cbk_size;
silk_float scratch_mem[ SCRATCH_SIZE ];
opus_val32 xcorr[ SCRATCH_SIZE ]; const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.