/src/opus/silk/float/find_LPC_FLP.c
Line | Count | Source (jump to first uncovered line) |
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 "define.h" |
33 | | #include "main_FLP.h" |
34 | | #include "tuning_parameters.h" |
35 | | |
36 | | /* LPC analysis */ |
37 | | void silk_find_LPC_FLP( |
38 | | silk_encoder_state *psEncC, /* I/O Encoder state */ |
39 | | opus_int16 NLSF_Q15[], /* O NLSFs */ |
40 | | const silk_float x[], /* I Input signal */ |
41 | | const silk_float minInvGain, /* I Inverse of max prediction gain */ |
42 | | int arch |
43 | | ) |
44 | 0 | { |
45 | 0 | opus_int k, subfr_length; |
46 | 0 | silk_float a[ MAX_LPC_ORDER ]; |
47 | | |
48 | | /* Used only for NLSF interpolation */ |
49 | 0 | silk_float res_nrg, res_nrg_2nd, res_nrg_interp; |
50 | 0 | opus_int16 NLSF0_Q15[ MAX_LPC_ORDER ]; |
51 | 0 | silk_float a_tmp[ MAX_LPC_ORDER ]; |
52 | 0 | silk_float LPC_res[ MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ]; |
53 | |
|
54 | 0 | subfr_length = psEncC->subfr_length + psEncC->predictLPCOrder; |
55 | | |
56 | | /* Default: No interpolation */ |
57 | 0 | psEncC->indices.NLSFInterpCoef_Q2 = 4; |
58 | | |
59 | | /* Burg AR analysis for the full frame */ |
60 | 0 | res_nrg = silk_burg_modified_FLP( a, x, minInvGain, subfr_length, psEncC->nb_subfr, psEncC->predictLPCOrder, arch ); |
61 | |
|
62 | 0 | if( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) { |
63 | | /* Optimal solution for last 10 ms; subtract residual energy here, as that's easier than */ |
64 | | /* adding it to the residual energy of the first 10 ms in each iteration of the search below */ |
65 | 0 | res_nrg -= silk_burg_modified_FLP( a_tmp, x + ( MAX_NB_SUBFR / 2 ) * subfr_length, minInvGain, subfr_length, MAX_NB_SUBFR / 2, psEncC->predictLPCOrder, arch ); |
66 | | |
67 | | /* Convert to NLSFs */ |
68 | 0 | silk_A2NLSF_FLP( NLSF_Q15, a_tmp, psEncC->predictLPCOrder ); |
69 | | |
70 | | /* Search over interpolation indices to find the one with lowest residual energy */ |
71 | 0 | res_nrg_2nd = silk_float_MAX; |
72 | 0 | for( k = 3; k >= 0; k-- ) { |
73 | | /* Interpolate NLSFs for first half */ |
74 | 0 | silk_interpolate( NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder ); |
75 | | |
76 | | /* Convert to LPC for residual energy evaluation */ |
77 | 0 | silk_NLSF2A_FLP( a_tmp, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch ); |
78 | | |
79 | | /* Calculate residual energy with LSF interpolation */ |
80 | 0 | silk_LPC_analysis_filter_FLP( LPC_res, a_tmp, x, 2 * subfr_length, psEncC->predictLPCOrder ); |
81 | 0 | res_nrg_interp = (silk_float)( |
82 | 0 | silk_energy_FLP( LPC_res + psEncC->predictLPCOrder, subfr_length - psEncC->predictLPCOrder ) + |
83 | 0 | silk_energy_FLP( LPC_res + psEncC->predictLPCOrder + subfr_length, subfr_length - psEncC->predictLPCOrder ) ); |
84 | | |
85 | | /* Determine whether current interpolated NLSFs are best so far */ |
86 | 0 | if( res_nrg_interp < res_nrg ) { |
87 | | /* Interpolation has lower residual energy */ |
88 | 0 | res_nrg = res_nrg_interp; |
89 | 0 | psEncC->indices.NLSFInterpCoef_Q2 = (opus_int8)k; |
90 | 0 | } else if( res_nrg_interp > res_nrg_2nd ) { |
91 | | /* No reason to continue iterating - residual energies will continue to climb */ |
92 | 0 | break; |
93 | 0 | } |
94 | 0 | res_nrg_2nd = res_nrg_interp; |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | 0 | if( psEncC->indices.NLSFInterpCoef_Q2 == 4 ) { |
99 | | /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */ |
100 | 0 | silk_A2NLSF_FLP( NLSF_Q15, a, psEncC->predictLPCOrder ); |
101 | 0 | } |
102 | |
|
103 | 0 | celt_assert( psEncC->indices.NLSFInterpCoef_Q2 == 4 || |
104 | 0 | ( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) ); |
105 | 0 | } |