OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. | 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 Redistribution and use in source and binary forms, with or without | 3 Redistribution and use in source and binary forms, with or without |
4 modification, are permitted provided that the following conditions | 4 modification, are permitted provided that the following conditions |
5 are met: | 5 are met: |
6 - Redistributions of source code must retain the above copyright notice, | 6 - Redistributions of source code must retain the above copyright notice, |
7 this list of conditions and the following disclaimer. | 7 this list of conditions and the following disclaimer. |
8 - Redistributions in binary form must reproduce the above copyright | 8 - Redistributions in binary form must reproduce the above copyright |
9 notice, this list of conditions and the following disclaimer in the | 9 notice, this list of conditions and the following disclaimer in the |
10 documentation and/or other materials provided with the distribution. | 10 documentation and/or other materials provided with the distribution. |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 /************************************************************/ | 42 /************************************************************/ |
43 /* Internally used functions */ | 43 /* Internally used functions */ |
44 /************************************************************/ | 44 /************************************************************/ |
45 static void silk_P_Ana_calc_corr_st3( | 45 static void silk_P_Ana_calc_corr_st3( |
46 silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB
_STAGE3_LAGS ], /* O 3 DIM correlation array */ | 46 silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB
_STAGE3_LAGS ], /* O 3 DIM correlation array */ |
47 const silk_float frame[], /* I vector to correlate
*/ | 47 const silk_float frame[], /* I vector to correlate
*/ |
48 opus_int start_lag, /* I start lag
*/ | 48 opus_int start_lag, /* I start lag
*/ |
49 opus_int sf_length, /* I sub frame length
*/ | 49 opus_int sf_length, /* I sub frame length
*/ |
50 opus_int nb_subfr, /* I number of subframes
*/ | 50 opus_int nb_subfr, /* I number of subframes
*/ |
51 opus_int complexity /* I Complexity setting
*/ | 51 opus_int complexity, /* I Complexity setting
*/ |
| 52 int arch /* I Run-time architecture
*/ |
52 ); | 53 ); |
53 | 54 |
54 static void silk_P_Ana_calc_energy_st3( | 55 static void silk_P_Ana_calc_energy_st3( |
55 silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_S
TAGE3_LAGS ], /* O 3 DIM correlation array */ | 56 silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_S
TAGE3_LAGS ], /* O 3 DIM correlation array */ |
56 const silk_float frame[], /* I vector to correlate
*/ | 57 const silk_float frame[], /* I vector to correlate
*/ |
57 opus_int start_lag, /* I start lag
*/ | 58 opus_int start_lag, /* I start lag
*/ |
58 opus_int sf_length, /* I sub frame length
*/ | 59 opus_int sf_length, /* I sub frame length
*/ |
59 opus_int nb_subfr, /* I number of subframes
*/ | 60 opus_int nb_subfr, /* I number of subframes
*/ |
60 opus_int complexity /* I Complexity setting
*/ | 61 opus_int complexity /* I Complexity setting
*/ |
61 ); | 62 ); |
62 | 63 |
63 /************************************************************/ | 64 /************************************************************/ |
64 /* CORE PITCH ANALYSIS FUNCTION */ | 65 /* CORE PITCH ANALYSIS FUNCTION */ |
65 /************************************************************/ | 66 /************************************************************/ |
66 opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
1 unvoiced */ | 67 opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
1 unvoiced */ |
67 const silk_float *frame, /* I Signal of length PE_FRAME_LE
NGTH_MS*Fs_kHz */ | 68 const silk_float *frame, /* I Signal of length PE_FRAME_LE
NGTH_MS*Fs_kHz */ |
68 opus_int *pitch_out, /* O Pitch lag values [nb_subfr]
*/ | 69 opus_int *pitch_out, /* O Pitch lag values [nb_subfr]
*/ |
69 opus_int16 *lagIndex, /* O Lag Index
*/ | 70 opus_int16 *lagIndex, /* O Lag Index
*/ |
70 opus_int8 *contourIndex, /* O Pitch contour Index
*/ | 71 opus_int8 *contourIndex, /* O Pitch contour Index
*/ |
71 silk_float *LTPCorr, /* I/O Normalized correlation; inpu
t: value from previous frame */ | 72 silk_float *LTPCorr, /* I/O Normalized correlation; inpu
t: value from previous frame */ |
72 opus_int prevLag, /* I Last lag of previous frame;
set to zero is unvoiced */ | 73 opus_int prevLag, /* I Last lag of previous frame;
set to zero is unvoiced */ |
73 const silk_float search_thres1, /* I First stage threshold for la
g candidates 0 - 1 */ | 74 const silk_float search_thres1, /* I First stage threshold for la
g candidates 0 - 1 */ |
74 const silk_float search_thres2, /* I Final threshold for lag cand
idates 0 - 1 */ | 75 const silk_float search_thres2, /* I Final threshold for lag cand
idates 0 - 1 */ |
75 const opus_int Fs_kHz, /* I sample frequency (kHz)
*/ | 76 const opus_int Fs_kHz, /* I sample frequency (kHz)
*/ |
76 const opus_int complexity, /* I Complexity setting, 0-2, whe
re 2 is highest */ | 77 const opus_int complexity, /* I Complexity setting, 0-2, whe
re 2 is highest */ |
77 const opus_int nb_subfr /* I Number of 5 ms subframes
*/ | 78 const opus_int nb_subfr, /* I Number of 5 ms subframes
*/ |
| 79 int arch /* I Run-time architecture
*/ |
78 ) | 80 ) |
79 { | 81 { |
80 opus_int i, k, d, j; | 82 opus_int i, k, d, j; |
81 silk_float frame_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ]; | 83 silk_float frame_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ]; |
82 silk_float frame_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ]; | 84 silk_float frame_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ]; |
83 opus_int16 frame_8_FIX[ PE_MAX_FRAME_LENGTH_MS * 8 ]; | 85 opus_int16 frame_8_FIX[ PE_MAX_FRAME_LENGTH_MS * 8 ]; |
84 opus_int16 frame_4_FIX[ PE_MAX_FRAME_LENGTH_MS * 4 ]; | 86 opus_int16 frame_4_FIX[ PE_MAX_FRAME_LENGTH_MS * 4 ]; |
85 opus_int32 filt_state[ 6 ]; | 87 opus_int32 filt_state[ 6 ]; |
86 silk_float threshold, contour_bias; | 88 silk_float threshold, contour_bias; |
87 silk_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ]; | 89 silk_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 /* Check that we are within range of the array */ | 171 /* Check that we are within range of the array */ |
170 silk_assert( target_ptr >= frame_4kHz ); | 172 silk_assert( target_ptr >= frame_4kHz ); |
171 silk_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4k
Hz ); | 173 silk_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4k
Hz ); |
172 | 174 |
173 basis_ptr = target_ptr - min_lag_4kHz; | 175 basis_ptr = target_ptr - min_lag_4kHz; |
174 | 176 |
175 /* Check that we are within range of the array */ | 177 /* Check that we are within range of the array */ |
176 silk_assert( basis_ptr >= frame_4kHz ); | 178 silk_assert( basis_ptr >= frame_4kHz ); |
177 silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kH
z ); | 179 silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kH
z ); |
178 | 180 |
179 celt_pitch_xcorr( target_ptr, target_ptr-max_lag_4kHz, xcorr, sf_length_
8kHz, max_lag_4kHz - min_lag_4kHz + 1 ); | 181 celt_pitch_xcorr( target_ptr, target_ptr-max_lag_4kHz, xcorr, sf_length_
8kHz, max_lag_4kHz - min_lag_4kHz + 1, arch ); |
180 | 182 |
181 /* Calculate first vector products before loop */ | 183 /* Calculate first vector products before loop */ |
182 cross_corr = xcorr[ max_lag_4kHz - min_lag_4kHz ]; | 184 cross_corr = xcorr[ max_lag_4kHz - min_lag_4kHz ]; |
183 normalizer = silk_energy_FLP( target_ptr, sf_length_8kHz ) + | 185 normalizer = silk_energy_FLP( target_ptr, sf_length_8kHz ) + |
184 silk_energy_FLP( basis_ptr, sf_length_8kHz ) + | 186 silk_energy_FLP( basis_ptr, sf_length_8kHz ) + |
185 sf_length_8kHz * 4000.0f; | 187 sf_length_8kHz * 4000.0f; |
186 | 188 |
187 C[ 0 ][ min_lag_4kHz ] += (silk_float)( 2 * cross_corr / normalizer ); | 189 C[ 0 ][ min_lag_4kHz ] += (silk_float)( 2 * cross_corr / normalizer ); |
188 | 190 |
189 /* From now on normalizer is computed recursively */ | 191 /* From now on normalizer is computed recursively */ |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 404 |
403 lag = silk_LIMIT_int( lag, min_lag, max_lag ); | 405 lag = silk_LIMIT_int( lag, min_lag, max_lag ); |
404 start_lag = silk_max_int( lag - 2, min_lag ); | 406 start_lag = silk_max_int( lag - 2, min_lag ); |
405 end_lag = silk_min_int( lag + 2, max_lag ); | 407 end_lag = silk_min_int( lag + 2, max_lag ); |
406 lag_new = lag; /* to avoid undefine
d lag */ | 408 lag_new = lag; /* to avoid undefine
d lag */ |
407 CBimax = 0; /* to avoid undefine
d lag */ | 409 CBimax = 0; /* to avoid undefine
d lag */ |
408 | 410 |
409 CCmax = -1000.0f; | 411 CCmax = -1000.0f; |
410 | 412 |
411 /* Calculate the correlations and energies needed in stage 3 */ | 413 /* Calculate the correlations and energies needed in stage 3 */ |
412 silk_P_Ana_calc_corr_st3( cross_corr_st3, frame, start_lag, sf_length, n
b_subfr, complexity ); | 414 silk_P_Ana_calc_corr_st3( cross_corr_st3, frame, start_lag, sf_length, n
b_subfr, complexity, arch ); |
413 silk_P_Ana_calc_energy_st3( energies_st3, frame, start_lag, sf_length, n
b_subfr, complexity ); | 415 silk_P_Ana_calc_energy_st3( energies_st3, frame, start_lag, sf_length, n
b_subfr, complexity ); |
414 | 416 |
415 lag_counter = 0; | 417 lag_counter = 0; |
416 silk_assert( lag == silk_SAT16( lag ) ); | 418 silk_assert( lag == silk_SAT16( lag ) ); |
417 contour_bias = PE_FLATCONTOUR_BIAS / lag; | 419 contour_bias = PE_FLATCONTOUR_BIAS / lag; |
418 | 420 |
419 /* Set up cbk parameters according to complexity setting and frame lengt
h */ | 421 /* Set up cbk parameters according to complexity setting and frame lengt
h */ |
420 if( nb_subfr == PE_MAX_NB_SUBFR ) { | 422 if( nb_subfr == PE_MAX_NB_SUBFR ) { |
421 nb_cbk_search = (opus_int)silk_nb_cbk_searchs_stage3[ complexity ]; | 423 nb_cbk_search = (opus_int)silk_nb_cbk_searchs_stage3[ complexity ]; |
422 cbk_size = PE_NB_CBKS_STAGE3_MAX; | 424 cbk_size = PE_NB_CBKS_STAGE3_MAX; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 * | 488 * |
487 * In total 48 correlations. The direct implementation computed in worst | 489 * In total 48 correlations. The direct implementation computed in worst |
488 * case 4*12*5 = 240 correlations, but more likely around 120. | 490 * case 4*12*5 = 240 correlations, but more likely around 120. |
489 ***********************************************************************/ | 491 ***********************************************************************/ |
490 static void silk_P_Ana_calc_corr_st3( | 492 static void silk_P_Ana_calc_corr_st3( |
491 silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB
_STAGE3_LAGS ], /* O 3 DIM correlation array */ | 493 silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB
_STAGE3_LAGS ], /* O 3 DIM correlation array */ |
492 const silk_float frame[], /* I vector to correlate
*/ | 494 const silk_float frame[], /* I vector to correlate
*/ |
493 opus_int start_lag, /* I start lag
*/ | 495 opus_int start_lag, /* I start lag
*/ |
494 opus_int sf_length, /* I sub frame length
*/ | 496 opus_int sf_length, /* I sub frame length
*/ |
495 opus_int nb_subfr, /* I number of subframes
*/ | 497 opus_int nb_subfr, /* I number of subframes
*/ |
496 opus_int complexity /* I Complexity setting
*/ | 498 opus_int complexity, /* I Complexity setting
*/ |
| 499 int arch /* I Run-time architecture
*/ |
497 ) | 500 ) |
498 { | 501 { |
499 const silk_float *target_ptr, *basis_ptr; | 502 const silk_float *target_ptr; |
500 opus_int i, j, k, lag_counter, lag_low, lag_high; | 503 opus_int i, j, k, lag_counter, lag_low, lag_high; |
501 opus_int nb_cbk_search, delta, idx, cbk_size; | 504 opus_int nb_cbk_search, delta, idx, cbk_size; |
502 silk_float scratch_mem[ SCRATCH_SIZE ]; | 505 silk_float scratch_mem[ SCRATCH_SIZE ]; |
503 opus_val32 xcorr[ SCRATCH_SIZE ]; | 506 opus_val32 xcorr[ SCRATCH_SIZE ]; |
504 const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; | 507 const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; |
505 | 508 |
506 silk_assert( complexity >= SILK_PE_MIN_COMPLEX ); | 509 silk_assert( complexity >= SILK_PE_MIN_COMPLEX ); |
507 silk_assert( complexity <= SILK_PE_MAX_COMPLEX ); | 510 silk_assert( complexity <= SILK_PE_MAX_COMPLEX ); |
508 | 511 |
509 if( nb_subfr == PE_MAX_NB_SUBFR ) { | 512 if( nb_subfr == PE_MAX_NB_SUBFR ) { |
(...skipping 10 matching lines...) Expand all Loading... |
520 } | 523 } |
521 | 524 |
522 target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of
frame */ | 525 target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of
frame */ |
523 for( k = 0; k < nb_subfr; k++ ) { | 526 for( k = 0; k < nb_subfr; k++ ) { |
524 lag_counter = 0; | 527 lag_counter = 0; |
525 | 528 |
526 /* Calculate the correlations for each subframe */ | 529 /* Calculate the correlations for each subframe */ |
527 lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | 530 lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); |
528 lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); | 531 lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); |
529 silk_assert(lag_high-lag_low+1 <= SCRATCH_SIZE); | 532 silk_assert(lag_high-lag_low+1 <= SCRATCH_SIZE); |
530 celt_pitch_xcorr( target_ptr, target_ptr - start_lag - lag_high, xcorr,
sf_length, lag_high - lag_low + 1 ); | 533 celt_pitch_xcorr( target_ptr, target_ptr - start_lag - lag_high, xcorr,
sf_length, lag_high - lag_low + 1, arch ); |
531 for( j = lag_low; j <= lag_high; j++ ) { | 534 for( j = lag_low; j <= lag_high; j++ ) { |
532 basis_ptr = target_ptr - ( start_lag + j ); | |
533 silk_assert( lag_counter < SCRATCH_SIZE ); | 535 silk_assert( lag_counter < SCRATCH_SIZE ); |
534 scratch_mem[ lag_counter ] = xcorr[ lag_high - j ]; | 536 scratch_mem[ lag_counter ] = xcorr[ lag_high - j ]; |
535 lag_counter++; | 537 lag_counter++; |
536 } | 538 } |
537 | 539 |
538 delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | 540 delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); |
539 for( i = 0; i < nb_cbk_search; i++ ) { | 541 for( i = 0; i < nb_cbk_search; i++ ) { |
540 /* Fill out the 3 dim array that stores the correlations for */ | 542 /* Fill out the 3 dim array that stores the correlations for */ |
541 /* each code_book vector for each start lag */ | 543 /* each code_book vector for each start lag */ |
542 idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; | 544 idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { | 621 for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { |
620 silk_assert( idx + j < SCRATCH_SIZE ); | 622 silk_assert( idx + j < SCRATCH_SIZE ); |
621 silk_assert( idx + j < lag_counter ); | 623 silk_assert( idx + j < lag_counter ); |
622 energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; | 624 energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; |
623 silk_assert( energies_st3[ k ][ i ][ j ] >= 0.0f ); | 625 silk_assert( energies_st3[ k ][ i ][ j ] >= 0.0f ); |
624 } | 626 } |
625 } | 627 } |
626 target_ptr += sf_length; | 628 target_ptr += sf_length; |
627 } | 629 } |
628 } | 630 } |
OLD | NEW |