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 13 matching lines...) Expand all Loading... |
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 POSSIBILITY OF SUCH DAMAGE. | 25 POSSIBILITY OF SUCH DAMAGE. |
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 "SigProc_FIX.h" | 32 #include "SigProc_FIX.h" |
33 #include "SigProc_FLP.h" | 33 #include "SigProc_FLP.h" |
34 | 34 #include "define.h" |
35 #define RC_THRESHOLD 0.9999f | |
36 | 35 |
37 /* compute inverse of LPC prediction gain, and */ | 36 /* compute inverse of LPC prediction gain, and */ |
38 /* test if LPC coefficients are stable (all poles within unit circle) */ | 37 /* test if LPC coefficients are stable (all poles within unit circle) */ |
39 /* this code is based on silk_a2k_FLP() */ | 38 /* this code is based on silk_a2k_FLP() */ |
40 silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction ga
in, energy domain */ | 39 silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction ga
in, energy domain */ |
41 const silk_float *A, /* I prediction coefficients [ord
er] */ | 40 const silk_float *A, /* I prediction coefficients [ord
er] */ |
42 opus_int32 order /* I prediction order
*/ | 41 opus_int32 order /* I prediction order
*/ |
43 ) | 42 ) |
44 { | 43 { |
45 opus_int k, n; | 44 opus_int k, n; |
46 double invGain, rc, rc_mult1, rc_mult2; | 45 double invGain, rc, rc_mult1, rc_mult2, tmp1, tmp2; |
47 silk_float Atmp[ 2 ][ SILK_MAX_ORDER_LPC ]; | 46 silk_float Atmp[ SILK_MAX_ORDER_LPC ]; |
48 silk_float *Aold, *Anew; | |
49 | 47 |
50 Anew = Atmp[ order & 1 ]; | 48 silk_memcpy( Atmp, A, order * sizeof(silk_float) ); |
51 silk_memcpy( Anew, A, order * sizeof(silk_float) ); | |
52 | 49 |
53 invGain = 1.0; | 50 invGain = 1.0; |
54 for( k = order - 1; k > 0; k-- ) { | 51 for( k = order - 1; k > 0; k-- ) { |
55 rc = -Anew[ k ]; | 52 rc = -Atmp[ k ]; |
56 if( rc > RC_THRESHOLD || rc < -RC_THRESHOLD ) { | 53 rc_mult1 = 1.0f - rc * rc; |
| 54 invGain *= rc_mult1; |
| 55 if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { |
57 return 0.0f; | 56 return 0.0f; |
58 } | 57 } |
59 rc_mult1 = 1.0f - rc * rc; | |
60 rc_mult2 = 1.0f / rc_mult1; | 58 rc_mult2 = 1.0f / rc_mult1; |
61 invGain *= rc_mult1; | 59 for( n = 0; n < (k + 1) >> 1; n++ ) { |
62 /* swap pointers */ | 60 tmp1 = Atmp[ n ]; |
63 Aold = Anew; | 61 tmp2 = Atmp[ k - n - 1 ]; |
64 Anew = Atmp[ k & 1 ]; | 62 Atmp[ n ] = (silk_float)( ( tmp1 - tmp2 * rc ) * rc_mult2 ); |
65 for( n = 0; n < k; n++ ) { | 63 Atmp[ k - n - 1 ] = (silk_float)( ( tmp2 - tmp1 * rc ) * rc_mult2 ); |
66 Anew[ n ] = (silk_float)( ( Aold[ n ] - Aold[ k - n - 1 ] * rc ) * r
c_mult2 ); | |
67 } | 64 } |
68 } | 65 } |
69 rc = -Anew[ 0 ]; | 66 rc = -Atmp[ 0 ]; |
70 if( rc > RC_THRESHOLD || rc < -RC_THRESHOLD ) { | 67 rc_mult1 = 1.0f - rc * rc; |
| 68 invGain *= rc_mult1; |
| 69 if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { |
71 return 0.0f; | 70 return 0.0f; |
72 } | 71 } |
73 rc_mult1 = 1.0f - rc * rc; | |
74 invGain *= rc_mult1; | |
75 return (silk_float)invGain; | 72 return (silk_float)invGain; |
76 } | 73 } |
OLD | NEW |