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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 /************************************************************/ | 56 /************************************************************/ |
57 /* Internally used functions */ | 57 /* Internally used functions */ |
58 /************************************************************/ | 58 /************************************************************/ |
59 static void silk_P_Ana_calc_corr_st3( | 59 static void silk_P_Ana_calc_corr_st3( |
60 silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation ar
ray */ | 60 silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation ar
ray */ |
61 const opus_int16 frame[], /* I vector to correlate
*/ | 61 const opus_int16 frame[], /* I vector to correlate
*/ |
62 opus_int start_lag, /* I lag offset to search
around */ | 62 opus_int start_lag, /* I lag offset to search
around */ |
63 opus_int sf_length, /* I length of a 5 ms sub
frame */ | 63 opus_int sf_length, /* I length of a 5 ms sub
frame */ |
64 opus_int nb_subfr, /* I number of subframes
*/ | 64 opus_int nb_subfr, /* I number of subframes
*/ |
65 opus_int complexity /* I Complexity setting
*/ | 65 opus_int complexity, /* I Complexity setting
*/ |
| 66 int arch /* I Run-time architectur
e */ |
66 ); | 67 ); |
67 | 68 |
68 static void silk_P_Ana_calc_energy_st3( | 69 static void silk_P_Ana_calc_energy_st3( |
69 silk_pe_stage3_vals energies_st3[], /* O 3 DIM energy array *
/ | 70 silk_pe_stage3_vals energies_st3[], /* O 3 DIM energy array *
/ |
70 const opus_int16 frame[], /* I vector to calc energ
y in */ | 71 const opus_int16 frame[], /* I vector to calc energ
y in */ |
71 opus_int start_lag, /* I lag offset to search
around */ | 72 opus_int start_lag, /* I lag offset to search
around */ |
72 opus_int sf_length, /* I length of one 5 ms s
ubframe */ | 73 opus_int sf_length, /* I length of one 5 ms s
ubframe */ |
73 opus_int nb_subfr, /* I number of subframes
*/ | 74 opus_int nb_subfr, /* I number of subframes
*/ |
74 opus_int complexity /* I Complexity setting
*/ | 75 opus_int complexity /* I Complexity setting
*/ |
75 ); | 76 ); |
76 | 77 |
77 /*************************************************************/ | 78 /*************************************************************/ |
78 /* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ | 79 /* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ |
79 /*************************************************************/ | 80 /*************************************************************/ |
80 opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0
voiced, 1 unvoiced */ | 81 opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0
voiced, 1 unvoiced */ |
81 const opus_int16 *frame, /* I Signal of length PE_
FRAME_LENGTH_MS*Fs_kHz */ | 82 const opus_int16 *frame, /* I Signal of length PE_
FRAME_LENGTH_MS*Fs_kHz */ |
82 opus_int *pitch_out, /* O 4 pitch lag values
*/ | 83 opus_int *pitch_out, /* O 4 pitch lag values
*/ |
83 opus_int16 *lagIndex, /* O Lag Index
*/ | 84 opus_int16 *lagIndex, /* O Lag Index
*/ |
84 opus_int8 *contourIndex, /* O Pitch contour Index
*/ | 85 opus_int8 *contourIndex, /* O Pitch contour Index
*/ |
85 opus_int *LTPCorr_Q15, /* I/O Normalized correlati
on; input: value from previous frame */ | 86 opus_int *LTPCorr_Q15, /* I/O Normalized correlati
on; input: value from previous frame */ |
86 opus_int prevLag, /* I Last lag of previous
frame; set to zero is unvoiced */ | 87 opus_int prevLag, /* I Last lag of previous
frame; set to zero is unvoiced */ |
87 const opus_int32 search_thres1_Q16, /* I First stage threshol
d for lag candidates 0 - 1 */ | 88 const opus_int32 search_thres1_Q16, /* I First stage threshol
d for lag candidates 0 - 1 */ |
88 const opus_int search_thres2_Q13, /* I Final threshold for
lag candidates 0 - 1 */ | 89 const opus_int search_thres2_Q13, /* I Final threshold for
lag candidates 0 - 1 */ |
89 const opus_int Fs_kHz, /* I Sample frequency (kH
z) */ | 90 const opus_int Fs_kHz, /* I Sample frequency (kH
z) */ |
90 const opus_int complexity, /* I Complexity setting,
0-2, where 2 is highest */ | 91 const opus_int complexity, /* I Complexity setting,
0-2, where 2 is highest */ |
91 const opus_int nb_subfr /* I number of 5 ms subfr
ames */ | 92 const opus_int nb_subfr, /* I number of 5 ms subfr
ames */ |
| 93 int arch /* I Run-time architectur
e */ |
92 ) | 94 ) |
93 { | 95 { |
94 VARDECL( opus_int16, frame_8kHz ); | 96 VARDECL( opus_int16, frame_8kHz ); |
95 VARDECL( opus_int16, frame_4kHz ); | 97 VARDECL( opus_int16, frame_4kHz ); |
96 opus_int32 filt_state[ 6 ]; | 98 opus_int32 filt_state[ 6 ]; |
97 const opus_int16 *input_frame_ptr; | 99 const opus_int16 *input_frame_ptr; |
98 opus_int i, k, d, j; | 100 opus_int i, k, d, j; |
99 VARDECL( opus_int16, C ); | 101 VARDECL( opus_int16, C ); |
100 VARDECL( opus_int32, xcorr32 ); | 102 VARDECL( opus_int32, xcorr32 ); |
101 const opus_int16 *target_ptr, *basis_ptr; | 103 const opus_int16 *target_ptr, *basis_ptr; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 /* Check that we are within range of the array */ | 184 /* Check that we are within range of the array */ |
183 silk_assert( target_ptr >= frame_4kHz ); | 185 silk_assert( target_ptr >= frame_4kHz ); |
184 silk_assert( target_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4k
Hz ); | 186 silk_assert( target_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4k
Hz ); |
185 | 187 |
186 basis_ptr = target_ptr - MIN_LAG_4KHZ; | 188 basis_ptr = target_ptr - MIN_LAG_4KHZ; |
187 | 189 |
188 /* Check that we are within range of the array */ | 190 /* Check that we are within range of the array */ |
189 silk_assert( basis_ptr >= frame_4kHz ); | 191 silk_assert( basis_ptr >= frame_4kHz ); |
190 silk_assert( basis_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4kH
z ); | 192 silk_assert( basis_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4kH
z ); |
191 | 193 |
192 celt_pitch_xcorr( target_ptr, target_ptr - MAX_LAG_4KHZ, xcorr32, SF_LEN
GTH_8KHZ, MAX_LAG_4KHZ - MIN_LAG_4KHZ + 1 ); | 194 celt_pitch_xcorr( target_ptr, target_ptr - MAX_LAG_4KHZ, xcorr32, SF_LEN
GTH_8KHZ, MAX_LAG_4KHZ - MIN_LAG_4KHZ + 1, arch ); |
193 | 195 |
194 /* Calculate first vector products before loop */ | 196 /* Calculate first vector products before loop */ |
195 cross_corr = xcorr32[ MAX_LAG_4KHZ - MIN_LAG_4KHZ ]; | 197 cross_corr = xcorr32[ MAX_LAG_4KHZ - MIN_LAG_4KHZ ]; |
196 normalizer = silk_inner_prod_aligned( target_ptr, target_ptr, SF_LENGTH_
8KHZ ); | 198 normalizer = silk_inner_prod_aligned( target_ptr, target_ptr, SF_LENGTH_
8KHZ ); |
197 normalizer = silk_ADD32( normalizer, silk_inner_prod_aligned( basis_ptr,
basis_ptr, SF_LENGTH_8KHZ ) ); | 199 normalizer = silk_ADD32( normalizer, silk_inner_prod_aligned( basis_ptr,
basis_ptr, SF_LENGTH_8KHZ ) ); |
198 normalizer = silk_ADD32( normalizer, silk_SMULBB( SF_LENGTH_8KHZ, 4000 )
); | 200 normalizer = silk_ADD32( normalizer, silk_SMULBB( SF_LENGTH_8KHZ, 4000 )
); |
199 | 201 |
200 matrix_ptr( C, k, 0, CSTRIDE_4KHZ ) = | 202 matrix_ptr( C, k, 0, CSTRIDE_4KHZ ) = |
201 (opus_int16)silk_DIV32_varQ( cross_corr, normalizer, 13 + 1 );
/* Q13 */ | 203 (opus_int16)silk_DIV32_varQ( cross_corr, normalizer, 13 + 1 );
/* Q13 */ |
202 | 204 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 *LTPCorr_Q15 = (opus_int)silk_LSHIFT( silk_DIV32_16( CCmax, nb_subfr ), 2 ); | 460 *LTPCorr_Q15 = (opus_int)silk_LSHIFT( silk_DIV32_16( CCmax, nb_subfr ), 2 ); |
459 silk_assert( *LTPCorr_Q15 >= 0 ); | 461 silk_assert( *LTPCorr_Q15 >= 0 ); |
460 | 462 |
461 if( Fs_kHz > 8 ) { | 463 if( Fs_kHz > 8 ) { |
462 VARDECL( opus_int16, scratch_mem ); | 464 VARDECL( opus_int16, scratch_mem ); |
463 /***********************************************************************
****/ | 465 /***********************************************************************
****/ |
464 /* Scale input signal down to avoid correlations measures from overflowi
ng */ | 466 /* Scale input signal down to avoid correlations measures from overflowi
ng */ |
465 /***********************************************************************
****/ | 467 /***********************************************************************
****/ |
466 /* find scaling as max scaling for each subframe */ | 468 /* find scaling as max scaling for each subframe */ |
467 silk_sum_sqr_shift( &energy, &shift, frame, frame_length ); | 469 silk_sum_sqr_shift( &energy, &shift, frame, frame_length ); |
468 ALLOC( scratch_mem, shift > 0 ? frame_length : 0, opus_int16 ); | 470 ALLOC( scratch_mem, shift > 0 ? frame_length : ALLOC_NONE, opus_int16 ); |
469 if( shift > 0 ) { | 471 if( shift > 0 ) { |
470 /* Move signal to scratch mem because the input signal should be unc
hanged */ | 472 /* Move signal to scratch mem because the input signal should be unc
hanged */ |
471 shift = silk_RSHIFT( shift, 1 ); | 473 shift = silk_RSHIFT( shift, 1 ); |
472 for( i = 0; i < frame_length; i++ ) { | 474 for( i = 0; i < frame_length; i++ ) { |
473 scratch_mem[ i ] = silk_RSHIFT( frame[ i ], shift ); | 475 scratch_mem[ i ] = silk_RSHIFT( frame[ i ], shift ); |
474 } | 476 } |
475 input_frame_ptr = scratch_mem; | 477 input_frame_ptr = scratch_mem; |
476 } else { | 478 } else { |
477 input_frame_ptr = frame; | 479 input_frame_ptr = frame; |
478 } | 480 } |
(...skipping 30 matching lines...) Expand all Loading... |
509 Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; | 511 Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; |
510 } else { | 512 } else { |
511 nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; | 513 nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; |
512 cbk_size = PE_NB_CBKS_STAGE3_10MS; | 514 cbk_size = PE_NB_CBKS_STAGE3_10MS; |
513 Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; | 515 Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; |
514 } | 516 } |
515 | 517 |
516 /* Calculate the correlations and energies needed in stage 3 */ | 518 /* Calculate the correlations and energies needed in stage 3 */ |
517 ALLOC( energies_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); | 519 ALLOC( energies_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); |
518 ALLOC( cross_corr_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); | 520 ALLOC( cross_corr_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); |
519 silk_P_Ana_calc_corr_st3( cross_corr_st3, input_frame_ptr, start_lag, s
f_length, nb_subfr, complexity ); | 521 silk_P_Ana_calc_corr_st3( cross_corr_st3, input_frame_ptr, start_lag, s
f_length, nb_subfr, complexity, arch ); |
520 silk_P_Ana_calc_energy_st3( energies_st3, input_frame_ptr, start_lag, sf
_length, nb_subfr, complexity ); | 522 silk_P_Ana_calc_energy_st3( energies_st3, input_frame_ptr, start_lag, sf
_length, nb_subfr, complexity ); |
521 | 523 |
522 lag_counter = 0; | 524 lag_counter = 0; |
523 silk_assert( lag == silk_SAT16( lag ) ); | 525 silk_assert( lag == silk_SAT16( lag ) ); |
524 contour_bias_Q15 = silk_DIV32_16( SILK_FIX_CONST( PE_FLATCONTOUR_BIAS, 1
5 ), lag ); | 526 contour_bias_Q15 = silk_DIV32_16( SILK_FIX_CONST( PE_FLATCONTOUR_BIAS, 1
5 ), lag ); |
525 | 527 |
526 target_ptr = &input_frame_ptr[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; | 528 target_ptr = &input_frame_ptr[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; |
527 energy_target = silk_ADD32( silk_inner_prod_aligned( target_ptr, target_
ptr, nb_subfr * sf_length ), 1 ); | 529 energy_target = silk_ADD32( silk_inner_prod_aligned( target_ptr, target_
ptr, nb_subfr * sf_length ), 1 ); |
528 for( d = start_lag; d <= end_lag; d++ ) { | 530 for( d = start_lag; d <= end_lag; d++ ) { |
529 for( j = 0; j < nb_cbk_search; j++ ) { | 531 for( j = 0; j < nb_cbk_search; j++ ) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 * | 592 * |
591 * In total 48 correlations. The direct implementation computed in worst | 593 * In total 48 correlations. The direct implementation computed in worst |
592 * case 4*12*5 = 240 correlations, but more likely around 120. | 594 * case 4*12*5 = 240 correlations, but more likely around 120. |
593 ***********************************************************************/ | 595 ***********************************************************************/ |
594 static void silk_P_Ana_calc_corr_st3( | 596 static void silk_P_Ana_calc_corr_st3( |
595 silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation ar
ray */ | 597 silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation ar
ray */ |
596 const opus_int16 frame[], /* I vector to correlate
*/ | 598 const opus_int16 frame[], /* I vector to correlate
*/ |
597 opus_int start_lag, /* I lag offset to search
around */ | 599 opus_int start_lag, /* I lag offset to search
around */ |
598 opus_int sf_length, /* I length of a 5 ms sub
frame */ | 600 opus_int sf_length, /* I length of a 5 ms sub
frame */ |
599 opus_int nb_subfr, /* I number of subframes
*/ | 601 opus_int nb_subfr, /* I number of subframes
*/ |
600 opus_int complexity /* I Complexity setting
*/ | 602 opus_int complexity, /* I Complexity setting
*/ |
| 603 int arch /* I Run-time architectur
e */ |
601 ) | 604 ) |
602 { | 605 { |
603 const opus_int16 *target_ptr; | 606 const opus_int16 *target_ptr; |
604 opus_int i, j, k, lag_counter, lag_low, lag_high; | 607 opus_int i, j, k, lag_counter, lag_low, lag_high; |
605 opus_int nb_cbk_search, delta, idx, cbk_size; | 608 opus_int nb_cbk_search, delta, idx, cbk_size; |
606 VARDECL( opus_int32, scratch_mem ); | 609 VARDECL( opus_int32, scratch_mem ); |
607 VARDECL( opus_int32, xcorr32 ); | 610 VARDECL( opus_int32, xcorr32 ); |
608 const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; | 611 const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; |
609 SAVE_STACK; | 612 SAVE_STACK; |
610 | 613 |
(...skipping 16 matching lines...) Expand all Loading... |
627 ALLOC( xcorr32, SCRATCH_SIZE, opus_int32 ); | 630 ALLOC( xcorr32, SCRATCH_SIZE, opus_int32 ); |
628 | 631 |
629 target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of
frame */ | 632 target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of
frame */ |
630 for( k = 0; k < nb_subfr; k++ ) { | 633 for( k = 0; k < nb_subfr; k++ ) { |
631 lag_counter = 0; | 634 lag_counter = 0; |
632 | 635 |
633 /* Calculate the correlations for each subframe */ | 636 /* Calculate the correlations for each subframe */ |
634 lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | 637 lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); |
635 lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); | 638 lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); |
636 silk_assert(lag_high-lag_low+1 <= SCRATCH_SIZE); | 639 silk_assert(lag_high-lag_low+1 <= SCRATCH_SIZE); |
637 celt_pitch_xcorr( target_ptr, target_ptr - start_lag - lag_high, xcorr32
, sf_length, lag_high - lag_low + 1 ); | 640 celt_pitch_xcorr( target_ptr, target_ptr - start_lag - lag_high, xcorr32
, sf_length, lag_high - lag_low + 1, arch ); |
638 for( j = lag_low; j <= lag_high; j++ ) { | 641 for( j = lag_low; j <= lag_high; j++ ) { |
639 silk_assert( lag_counter < SCRATCH_SIZE ); | 642 silk_assert( lag_counter < SCRATCH_SIZE ); |
640 scratch_mem[ lag_counter ] = xcorr32[ lag_high - j ]; | 643 scratch_mem[ lag_counter ] = xcorr32[ lag_high - j ]; |
641 lag_counter++; | 644 lag_counter++; |
642 } | 645 } |
643 | 646 |
644 delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | 647 delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); |
645 for( i = 0; i < nb_cbk_search; i++ ) { | 648 for( i = 0; i < nb_cbk_search; i++ ) { |
646 /* Fill out the 3 dim array that stores the correlations for */ | 649 /* Fill out the 3 dim array that stores the correlations for */ |
647 /* each code_book vector for each start lag */ | 650 /* each code_book vector for each start lag */ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 matrix_ptr( energies_st3, k, i, nb_cbk_search )[ j ] = | 735 matrix_ptr( energies_st3, k, i, nb_cbk_search )[ j ] = |
733 scratch_mem[ idx + j ]; | 736 scratch_mem[ idx + j ]; |
734 silk_assert( | 737 silk_assert( |
735 matrix_ptr( energies_st3, k, i, nb_cbk_search )[ j ] >= 0 ); | 738 matrix_ptr( energies_st3, k, i, nb_cbk_search )[ j ] >= 0 ); |
736 } | 739 } |
737 } | 740 } |
738 target_ptr += sf_length; | 741 target_ptr += sf_length; |
739 } | 742 } |
740 RESTORE_STACK; | 743 RESTORE_STACK; |
741 } | 744 } |
OLD | NEW |