/************************************************************/ /* Internally used functions */ /************************************************************/ staticvoid silk_P_Ana_calc_corr_st3(
silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation array */ const opus_int16 frame[], /* I vector to correlate */
opus_int start_lag, /* I lag offset to search around */
opus_int sf_length, /* I length of a 5 ms subframe */
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_pe_stage3_vals energies_st3[], /* O 3 DIM energy array */ const opus_int16 frame[], /* I vector to calc energy in */
opus_int start_lag, /* I lag offset to search around */
opus_int sf_length, /* I length of one 5 ms subframe */
opus_int nb_subfr, /* I number of subframes */
opus_int complexity, /* I Complexity setting */ int arch /* I Run-time architecture */
);
/*************************************************************/ /* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ /*************************************************************/
opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ const opus_int16 *frame_unscaled, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
opus_int *pitch_out, /* O 4 pitch lag values */
opus_int16 *lagIndex, /* O Lag Index */
opus_int8 *contourIndex, /* O Pitch contour Index */
opus_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */
opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ const opus_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ const opus_int search_thres2_Q13, /* 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 */
)
{
VARDECL( opus_int16, frame_8kHz_buf );
VARDECL( opus_int16, frame_4kHz );
VARDECL( opus_int16, frame_scaled );
opus_int32 filt_state[ 6 ]; const opus_int16 *frame, *frame_8kHz;
opus_int i, k, d, j;
VARDECL( opus_int16, C );
VARDECL( opus_int32, xcorr32 ); const opus_int16 *target_ptr, *basis_ptr;
opus_int32 cross_corr, normalizer, energy, energy_basis, energy_target;
opus_int d_srch[ PE_D_SRCH_LENGTH ], Cmax, length_d_srch, length_d_comp, shift;
VARDECL( opus_int16, d_comp );
opus_int32 sum, threshold, lag_counter;
opus_int CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new;
opus_int32 CC[ PE_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new;
VARDECL( silk_pe_stage3_vals, energies_st3 );
VARDECL( silk_pe_stage3_vals, cross_corr_st3 );
opus_int frame_length, frame_length_8kHz, frame_length_4kHz;
opus_int sf_length;
opus_int min_lag;
opus_int max_lag;
opus_int32 contour_bias_Q15, diff;
opus_int nb_cbk_search, cbk_size;
opus_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q13; const opus_int8 *Lag_CB_ptr;
SAVE_STACK;
/* Check for valid sampling frequency */
celt_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 );
/* Decimate again to 4 kHz */
silk_memset( filt_state, 0, 2 * sizeof( opus_int32 ) );/* Set state to zero */
ALLOC( frame_4kHz, frame_length_4kHz, opus_int16 );
silk_resampler_down2( filt_state, frame_4kHz, frame_8kHz, frame_length_8kHz );
/* 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 ] );
}
/****************************************************************************** *FIRSTSTAGE,operatingin4khz
******************************************************************************/
ALLOC( C, nb_subfr * CSTRIDE_8KHZ, opus_int16 );
ALLOC( xcorr32, MAX_LAG_4KHZ-MIN_LAG_4KHZ+1, opus_int32 );
silk_memset( C, 0, (nb_subfr >> 1) * CSTRIDE_4KHZ * sizeof( opus_int16 ) );
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 );
cross_corr = xcorr32[ MAX_LAG_4KHZ - d ];
/* Add contribution of new sample and remove contribution from oldest sample */
normalizer = silk_ADD32( normalizer,
silk_SMULBB( basis_ptr[ 0 ], basis_ptr[ 0 ] ) -
silk_SMULBB( basis_ptr[ SF_LENGTH_8KHZ ], basis_ptr[ SF_LENGTH_8KHZ ] ) );
target_ptr = &frame_8kHz[ PE_LTP_MEM_LENGTH_MS * 8 ]; for( k = 0; k < nb_subfr; k++ ) {
/* Check that we are within range of the array */
celt_assert( target_ptr >= frame_8kHz );
celt_assert( target_ptr + SF_LENGTH_8KHZ <= frame_8kHz + frame_length_8kHz );
/* Check that we are within range of the array */
silk_assert( basis_ptr >= frame_8kHz );
silk_assert( basis_ptr + SF_LENGTH_8KHZ <= frame_8kHz + frame_length_8kHz );
if( CCmax_new_b > CCmax_b && /* Find maximum biased correlation */
CCmax_new > silk_SMULBB( nb_subfr, search_thres2_Q13 ) && /* Correlation needs to be high enough to be voiced */
silk_CB_lags_stage2[ 0 ][ CBimax_new ] <= MIN_LAG_8KHZ /* Lag must be in range */
) {
CCmax_b = CCmax_new_b;
CCmax = CCmax_new;
lag = d;
CBimax = CBimax_new;
}
}
if( Fs_kHz > 8 ) { /* Search in original signal */
CBimax_old = CBimax; /* Compensate for decimation */
silk_assert( lag == silk_SAT16( lag ) ); if( Fs_kHz == 12 ) {
lag = silk_RSHIFT( silk_SMULBB( lag, 3 ), 1 );
} elseif( Fs_kHz == 16 ) {
lag = silk_LSHIFT( lag, 1 );
} else {
lag = silk_SMULBB( lag, 3 );
}
lag = silk_LIMIT_int( lag, min_lag, max_lag );
start_lag = silk_max_int( lag - 2, min_lag );
end_lag = silk_min_int( lag + 2, max_lag );
lag_new = lag; /* to avoid undefined lag */
CBimax = 0; /* to avoid undefined lag */
CCmax = silk_int32_MIN; /* pitch lags according to second stage */ for( k = 0; k < nb_subfr; k++ ) {
pitch_out[ k ] = lag + 2 * silk_CB_lags_stage2[ k ][ CBimax_old ];
}
delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); for( i = 0; i < nb_cbk_search; i++ ) { /* Fill out the 3 dim array that stores the correlations for */ /* each code_book vector for each start lag */
idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) {
silk_assert( idx + j < SCRATCH_SIZE );
silk_assert( idx + j < lag_counter );
matrix_ptr( cross_corr_st3, k, i, nb_cbk_search )[ j ] =
scratch_mem[ idx + j ];
}
}
target_ptr += sf_length;
}
RESTORE_STACK;
}
/********************************************************************/ /* Calculate the energies for first two subframes. The energies are */ /* calculated recursively. */ /********************************************************************/ staticvoid silk_P_Ana_calc_energy_st3(
silk_pe_stage3_vals energies_st3[], /* O 3 DIM energy array */ const opus_int16 frame[], /* I vector to calc energy in */
opus_int start_lag, /* I lag offset to search around */
opus_int sf_length, /* I length of one 5 ms subframe */
opus_int nb_subfr, /* I number of subframes */
opus_int complexity, /* I Complexity setting */ int arch /* I Run-time architecture */
)
{ const opus_int16 *target_ptr, *basis_ptr;
opus_int32 energy;
opus_int k, i, j, lag_counter;
opus_int nb_cbk_search, delta, idx, cbk_size, lag_diff;
VARDECL( opus_int32, scratch_mem ); const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
SAVE_STACK;
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.