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 15 matching lines...) Expand all Loading... |
26 ***********************************************************************/ | 26 ***********************************************************************/ |
27 | 27 |
28 #ifdef HAVE_CONFIG_H | 28 #ifdef HAVE_CONFIG_H |
29 #include "config.h" | 29 #include "config.h" |
30 #endif | 30 #endif |
31 | 31 |
32 #include "main_FLP.h" | 32 #include "main_FLP.h" |
33 #include "tuning_parameters.h" | 33 #include "tuning_parameters.h" |
34 | 34 |
35 void silk_find_LTP_FLP( | 35 void silk_find_LTP_FLP( |
36 silk_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O
LTP coefs */ | 36 silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ],
/* O Weight for LTP quantization */ |
37 silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]
, /* O Weight for LTP quantization */ | 37 silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* O
Weight for LTP quantization */ |
38 silk_float *LTPredCodGain, /* O
LTP coding gain */ | 38 const silk_float r_ptr[], /* I
LPC residual */ |
39 const silk_float r_lpc[], /* I
LPC residual */ | 39 const opus_int lag[ MAX_NB_SUBFR ], /* I
LTP lags */ |
40 const opus_int lag[ MAX_NB_SUBFR ], /* I
LTP lags */ | |
41 const silk_float Wght[ MAX_NB_SUBFR ], /* I
Weights */ | |
42 const opus_int subfr_length, /* I
Subframe length */ | 40 const opus_int subfr_length, /* I
Subframe length */ |
43 const opus_int nb_subfr, /* I
number of subframes */ | 41 const opus_int nb_subfr /* I
number of subframes */ |
44 const opus_int mem_offset /* I
Number of samples in LTP memory */ | |
45 ) | 42 ) |
46 { | 43 { |
47 opus_int i, k; | 44 opus_int k; |
48 silk_float *b_ptr, temp, *WLTP_ptr; | 45 silk_float *xX_ptr, *XX_ptr; |
49 silk_float LPC_res_nrg, LPC_LTP_res_nrg; | 46 const silk_float *lag_ptr; |
50 silk_float d[ MAX_NB_SUBFR ], m, g, delta_b[ LTP_ORDER ]; | 47 silk_float xx, temp; |
51 silk_float w[ MAX_NB_SUBFR ], nrg[ MAX_NB_SUBFR ], regu; | |
52 silk_float Rr[ LTP_ORDER ], rr[ MAX_NB_SUBFR ]; | |
53 const silk_float *r_ptr, *lag_ptr; | |
54 | 48 |
55 b_ptr = b; | 49 xX_ptr = xX; |
56 WLTP_ptr = WLTP; | 50 XX_ptr = XX; |
57 r_ptr = &r_lpc[ mem_offset ]; | |
58 for( k = 0; k < nb_subfr; k++ ) { | 51 for( k = 0; k < nb_subfr; k++ ) { |
59 lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); | 52 lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); |
| 53 silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, XX_ptr ); |
| 54 silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xX_ptr ); |
| 55 xx = ( silk_float )silk_energy_FLP( r_ptr, subfr_length + LTP_ORDER ); |
| 56 temp = 1.0f / silk_max( xx, LTP_CORR_INV_MAX * 0.5f * ( XX_ptr[ 0 ] + XX
_ptr[ 24 ] ) + 1.0f ); |
| 57 silk_scale_vector_FLP( XX_ptr, temp, LTP_ORDER * LTP_ORDER ); |
| 58 silk_scale_vector_FLP( xX_ptr, temp, LTP_ORDER ); |
60 | 59 |
61 silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, WLTP_ptr ); | 60 r_ptr += subfr_length; |
62 silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr ); | 61 XX_ptr += LTP_ORDER * LTP_ORDER; |
63 | 62 xX_ptr += LTP_ORDER; |
64 rr[ k ] = ( silk_float )silk_energy_FLP( r_ptr, subfr_length ); | |
65 regu = 1.0f + rr[ k ] + | |
66 matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ) + | |
67 matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ); | |
68 regu *= LTP_DAMPING / 3; | |
69 silk_regularize_correlations_FLP( WLTP_ptr, &rr[ k ], regu, LTP_ORDER ); | |
70 silk_solve_LDL_FLP( WLTP_ptr, LTP_ORDER, Rr, b_ptr ); | |
71 | |
72 /* Calculate residual energy */ | |
73 nrg[ k ] = silk_residual_energy_covar_FLP( b_ptr, WLTP_ptr, Rr, rr[ k ],
LTP_ORDER ); | |
74 | |
75 temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); | |
76 silk_scale_vector_FLP( WLTP_ptr, temp, LTP_ORDER * LTP_ORDER ); | |
77 w[ k ] = matrix_ptr( WLTP_ptr, LTP_ORDER / 2, LTP_ORDER / 2, LTP_ORDER )
; | |
78 | |
79 r_ptr += subfr_length; | |
80 b_ptr += LTP_ORDER; | |
81 WLTP_ptr += LTP_ORDER * LTP_ORDER; | |
82 } | |
83 | |
84 /* Compute LTP coding gain */ | |
85 if( LTPredCodGain != NULL ) { | |
86 LPC_LTP_res_nrg = 1e-6f; | |
87 LPC_res_nrg = 0.0f; | |
88 for( k = 0; k < nb_subfr; k++ ) { | |
89 LPC_res_nrg += rr[ k ] * Wght[ k ]; | |
90 LPC_LTP_res_nrg += nrg[ k ] * Wght[ k ]; | |
91 } | |
92 | |
93 silk_assert( LPC_LTP_res_nrg > 0 ); | |
94 *LTPredCodGain = 3.0f * silk_log2( LPC_res_nrg / LPC_LTP_res_nrg ); | |
95 } | |
96 | |
97 /* Smoothing */ | |
98 /* d = sum( B, 1 ); */ | |
99 b_ptr = b; | |
100 for( k = 0; k < nb_subfr; k++ ) { | |
101 d[ k ] = 0; | |
102 for( i = 0; i < LTP_ORDER; i++ ) { | |
103 d[ k ] += b_ptr[ i ]; | |
104 } | |
105 b_ptr += LTP_ORDER; | |
106 } | |
107 /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */ | |
108 temp = 1e-3f; | |
109 for( k = 0; k < nb_subfr; k++ ) { | |
110 temp += w[ k ]; | |
111 } | |
112 m = 0; | |
113 for( k = 0; k < nb_subfr; k++ ) { | |
114 m += d[ k ] * w[ k ]; | |
115 } | |
116 m = m / temp; | |
117 | |
118 b_ptr = b; | |
119 for( k = 0; k < nb_subfr; k++ ) { | |
120 g = LTP_SMOOTHING / ( LTP_SMOOTHING + w[ k ] ) * ( m - d[ k ] ); | |
121 temp = 0; | |
122 for( i = 0; i < LTP_ORDER; i++ ) { | |
123 delta_b[ i ] = silk_max_float( b_ptr[ i ], 0.1f ); | |
124 temp += delta_b[ i ]; | |
125 } | |
126 temp = g / temp; | |
127 for( i = 0; i < LTP_ORDER; i++ ) { | |
128 b_ptr[ i ] = b_ptr[ i ] + delta_b[ i ] * temp; | |
129 } | |
130 b_ptr += LTP_ORDER; | |
131 } | 63 } |
132 } | 64 } |
OLD | NEW |