/src/opus/silk/fixed/find_LTP_FIX.c
Line | Count | Source |
1 | | /*********************************************************************** |
2 | | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 | | Redistribution and use in source and binary forms, with or without |
4 | | modification, are permitted provided that the following conditions |
5 | | are met: |
6 | | - Redistributions of source code must retain the above copyright notice, |
7 | | this list of conditions and the following disclaimer. |
8 | | - Redistributions in binary form must reproduce the above copyright |
9 | | notice, this list of conditions and the following disclaimer in the |
10 | | documentation and/or other materials provided with the distribution. |
11 | | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
12 | | names of specific contributors, may be used to endorse or promote |
13 | | products derived from this software without specific prior written |
14 | | permission. |
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | | POSSIBILITY OF SUCH DAMAGE. |
26 | | ***********************************************************************/ |
27 | | |
28 | | #ifdef HAVE_CONFIG_H |
29 | | #include "config.h" |
30 | | #endif |
31 | | |
32 | | #include "main_FIX.h" |
33 | | #include "tuning_parameters.h" |
34 | | |
35 | | void silk_find_LTP_FIX( |
36 | | opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */ |
37 | | opus_int32 xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* O Correlation vector */ |
38 | | const opus_int16 r_ptr[], /* I Residual signal after LPC */ |
39 | | const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ |
40 | | const opus_int subfr_length, /* I Subframe length */ |
41 | | const opus_int nb_subfr, /* I Number of subframes */ |
42 | | int arch /* I Run-time architecture */ |
43 | | ) |
44 | 499k | { |
45 | 499k | opus_int i, k, extra_shifts; |
46 | 499k | opus_int xx_shifts, xX_shifts, XX_shifts; |
47 | 499k | const opus_int16 *lag_ptr; |
48 | 499k | opus_int32 *XXLTP_Q17_ptr, *xXLTP_Q17_ptr; |
49 | 499k | opus_int32 xx, nrg, temp; |
50 | | |
51 | 499k | xXLTP_Q17_ptr = xXLTP_Q17; |
52 | 499k | XXLTP_Q17_ptr = XXLTP_Q17; |
53 | 2.29M | for( k = 0; k < nb_subfr; k++ ) { |
54 | 1.79M | lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); |
55 | | |
56 | 1.79M | silk_sum_sqr_shift( &xx, &xx_shifts, r_ptr, subfr_length + LTP_ORDER ); /* xx in Q( -xx_shifts ) */ |
57 | 1.79M | silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, XXLTP_Q17_ptr, &nrg, &XX_shifts, arch ); /* XXLTP_Q17_ptr and nrg in Q( -XX_shifts ) */ |
58 | 1.79M | extra_shifts = xx_shifts - XX_shifts; |
59 | 1.79M | if( extra_shifts > 0 ) { |
60 | | /* Shift XX */ |
61 | 124k | xX_shifts = xx_shifts; |
62 | 3.24M | for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { |
63 | 3.11M | XXLTP_Q17_ptr[ i ] = silk_RSHIFT32( XXLTP_Q17_ptr[ i ], extra_shifts ); /* Q( -xX_shifts ) */ |
64 | 3.11M | } |
65 | 124k | nrg = silk_RSHIFT32( nrg, extra_shifts ); /* Q( -xX_shifts ) */ |
66 | 1.66M | } else if( extra_shifts < 0 ) { |
67 | | /* Shift xx */ |
68 | 120k | xX_shifts = XX_shifts; |
69 | 120k | xx = silk_RSHIFT32( xx, -extra_shifts ); /* Q( -xX_shifts ) */ |
70 | 1.54M | } else { |
71 | 1.54M | xX_shifts = xx_shifts; |
72 | 1.54M | } |
73 | 1.79M | silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xXLTP_Q17_ptr, xX_shifts, arch ); /* xXLTP_Q17_ptr in Q( -xX_shifts ) */ |
74 | | |
75 | | /* At this point all correlations are in Q(-xX_shifts) */ |
76 | 1.79M | temp = silk_SMLAWB( 1, nrg, SILK_FIX_CONST( LTP_CORR_INV_MAX, 16 ) ); |
77 | 1.79M | temp = silk_max( temp, xx ); |
78 | 1.79M | TIC(div) |
79 | | #if 0 |
80 | | for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { |
81 | | XXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( XXLTP_Q17_ptr[ i ], temp, 17 ); |
82 | | } |
83 | | for( i = 0; i < LTP_ORDER; i++ ) { |
84 | | xXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( xXLTP_Q17_ptr[ i ], temp, 17 ); |
85 | | } |
86 | | #else |
87 | 46.5M | for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { |
88 | 44.7M | XXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)XXLTP_Q17_ptr[ i ], 17 ) / temp ); |
89 | 44.7M | } |
90 | 10.7M | for( i = 0; i < LTP_ORDER; i++ ) { |
91 | 8.95M | xXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)xXLTP_Q17_ptr[ i ], 17 ) / temp ); |
92 | 8.95M | } |
93 | 1.79M | #endif |
94 | 1.79M | TOC(div) |
95 | 1.79M | r_ptr += subfr_length; |
96 | 1.79M | XXLTP_Q17_ptr += LTP_ORDER * LTP_ORDER; |
97 | 1.79M | xXLTP_Q17_ptr += LTP_ORDER; |
98 | 1.79M | } |
99 | 499k | } |