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 24 matching lines...) Expand all Loading... |
35 #include "pitch.h" | 35 #include "pitch.h" |
36 | 36 |
37 #define MAX_FRAME_SIZE 384 /* subfr_length * nb_subfr =
( 0.005 * 16000 + 16 ) * 4 = 384 */ | 37 #define MAX_FRAME_SIZE 384 /* subfr_length * nb_subfr =
( 0.005 * 16000 + 16 ) * 4 = 384 */ |
38 | 38 |
39 #define QA 25 | 39 #define QA 25 |
40 #define N_BITS_HEAD_ROOM 2 | 40 #define N_BITS_HEAD_ROOM 2 |
41 #define MIN_RSHIFTS -16 | 41 #define MIN_RSHIFTS -16 |
42 #define MAX_RSHIFTS (32 - QA) | 42 #define MAX_RSHIFTS (32 - QA) |
43 | 43 |
44 /* Compute reflection coefficients from input signal */ | 44 /* Compute reflection coefficients from input signal */ |
45 void silk_burg_modified( | 45 void silk_burg_modified_c( |
46 opus_int32 *res_nrg, /* O Residual energy
*/ | 46 opus_int32 *res_nrg, /* O Residual energy
*/ |
47 opus_int *res_nrg_Q, /* O Residual energy Q va
lue */ | 47 opus_int *res_nrg_Q, /* O Residual energy Q va
lue */ |
48 opus_int32 A_Q16[], /* O Prediction coefficie
nts (length order) */ | 48 opus_int32 A_Q16[], /* O Prediction coefficie
nts (length order) */ |
49 const opus_int16 x[], /* I Input signal, length
: nb_subfr * ( D + subfr_length ) */ | 49 const opus_int16 x[], /* I Input signal, length
: nb_subfr * ( D + subfr_length ) */ |
50 const opus_int32 minInvGain_Q30, /* I Inverse of max predi
ction gain */ | 50 const opus_int32 minInvGain_Q30, /* I Inverse of max predi
ction gain */ |
51 const opus_int subfr_length, /* I Input signal subfram
e length (incl. D preceding samples) */ | 51 const opus_int subfr_length, /* I Input signal subfram
e length (incl. D preceding samples) */ |
52 const opus_int nb_subfr, /* I Number of subframes
stacked in x */ | 52 const opus_int nb_subfr, /* I Number of subframes
stacked in x */ |
53 const opus_int D, /* I Order
*/ | 53 const opus_int D, /* I Order
*/ |
54 int arch /* I Run-time architectur
e */ | 54 int arch /* I Run-time architectur
e */ |
55 ) | 55 ) |
56 { | 56 { |
57 opus_int k, n, s, lz, rshifts, rshifts_extra, reached_max_gain; | 57 opus_int k, n, s, lz, rshifts, reached_max_gain; |
58 opus_int32 C0, num, nrg, rc_Q31, invGain_Q30, Atmp_QA, Atmp1, tmp1, tm
p2, x1, x2; | 58 opus_int32 C0, num, nrg, rc_Q31, invGain_Q30, Atmp_QA, Atmp1, tmp1, tm
p2, x1, x2; |
59 const opus_int16 *x_ptr; | 59 const opus_int16 *x_ptr; |
60 opus_int32 C_first_row[ SILK_MAX_ORDER_LPC ]; | 60 opus_int32 C_first_row[ SILK_MAX_ORDER_LPC ]; |
61 opus_int32 C_last_row[ SILK_MAX_ORDER_LPC ]; | 61 opus_int32 C_last_row[ SILK_MAX_ORDER_LPC ]; |
62 opus_int32 Af_QA[ SILK_MAX_ORDER_LPC ]; | 62 opus_int32 Af_QA[ SILK_MAX_ORDER_LPC ]; |
63 opus_int32 CAf[ SILK_MAX_ORDER_LPC + 1 ]; | 63 opus_int32 CAf[ SILK_MAX_ORDER_LPC + 1 ]; |
64 opus_int32 CAb[ SILK_MAX_ORDER_LPC + 1 ]; | 64 opus_int32 CAb[ SILK_MAX_ORDER_LPC + 1 ]; |
65 opus_int32 xcorr[ SILK_MAX_ORDER_LPC ]; | 65 opus_int32 xcorr[ SILK_MAX_ORDER_LPC ]; |
| 66 opus_int64 C0_64; |
66 | 67 |
67 silk_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); | 68 silk_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); |
68 | 69 |
69 /* Compute autocorrelations, added over subframes */ | 70 /* Compute autocorrelations, added over subframes */ |
70 silk_sum_sqr_shift( &C0, &rshifts, x, nb_subfr * subfr_length ); | 71 C0_64 = silk_inner_prod16_aligned_64( x, x, subfr_length*nb_subfr, arch ); |
71 if( rshifts > MAX_RSHIFTS ) { | 72 lz = silk_CLZ64(C0_64); |
72 C0 = silk_LSHIFT32( C0, rshifts - MAX_RSHIFTS ); | 73 rshifts = 32 + 1 + N_BITS_HEAD_ROOM - lz; |
73 silk_assert( C0 > 0 ); | 74 if (rshifts > MAX_RSHIFTS) rshifts = MAX_RSHIFTS; |
74 rshifts = MAX_RSHIFTS; | 75 if (rshifts < MIN_RSHIFTS) rshifts = MIN_RSHIFTS; |
| 76 |
| 77 if (rshifts > 0) { |
| 78 C0 = (opus_int32)silk_RSHIFT64(C0_64, rshifts ); |
75 } else { | 79 } else { |
76 lz = silk_CLZ32( C0 ) - 1; | 80 C0 = silk_LSHIFT32((opus_int32)C0_64, -rshifts ); |
77 rshifts_extra = N_BITS_HEAD_ROOM - lz; | |
78 if( rshifts_extra > 0 ) { | |
79 rshifts_extra = silk_min( rshifts_extra, MAX_RSHIFTS - rshifts ); | |
80 C0 = silk_RSHIFT32( C0, rshifts_extra ); | |
81 } else { | |
82 rshifts_extra = silk_max( rshifts_extra, MIN_RSHIFTS - rshifts ); | |
83 C0 = silk_LSHIFT32( C0, -rshifts_extra ); | |
84 } | |
85 rshifts += rshifts_extra; | |
86 } | 81 } |
| 82 |
87 CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32
), C0 ) + 1; /* Q(-rshifts) */ | 83 CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32
), C0 ) + 1; /* Q(-rshifts) */ |
88 silk_memset( C_first_row, 0, SILK_MAX_ORDER_LPC * sizeof( opus_int32 ) ); | 84 silk_memset( C_first_row, 0, SILK_MAX_ORDER_LPC * sizeof( opus_int32 ) ); |
89 if( rshifts > 0 ) { | 85 if( rshifts > 0 ) { |
90 for( s = 0; s < nb_subfr; s++ ) { | 86 for( s = 0; s < nb_subfr; s++ ) { |
91 x_ptr = x + s * subfr_length; | 87 x_ptr = x + s * subfr_length; |
92 for( n = 1; n < D + 1; n++ ) { | 88 for( n = 1; n < D + 1; n++ ) { |
93 C_first_row[ n - 1 ] += (opus_int32)silk_RSHIFT64( | 89 C_first_row[ n - 1 ] += (opus_int32)silk_RSHIFT64( |
94 silk_inner_prod16_aligned_64( x_ptr, x_ptr + n, subfr_length
- n ), rshifts ); | 90 silk_inner_prod16_aligned_64( x_ptr, x_ptr + n, subfr_length
- n, arch ), rshifts ); |
95 } | 91 } |
96 } | 92 } |
97 } else { | 93 } else { |
98 for( s = 0; s < nb_subfr; s++ ) { | 94 for( s = 0; s < nb_subfr; s++ ) { |
99 int i; | 95 int i; |
100 opus_int32 d; | 96 opus_int32 d; |
101 x_ptr = x + s * subfr_length; | 97 x_ptr = x + s * subfr_length; |
102 celt_pitch_xcorr(x_ptr, x_ptr + 1, xcorr, subfr_length - D, D, arch
); | 98 celt_pitch_xcorr(x_ptr, x_ptr + 1, xcorr, subfr_length - D, D, arch
); |
103 for( n = 1; n < D + 1; n++ ) { | 99 for( n = 1; n < D + 1; n++ ) { |
104 for ( i = n + subfr_length - D, d = 0; i < subfr_length; i++ ) | 100 for ( i = n + subfr_length - D, d = 0; i < subfr_length; i++ ) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 241 |
246 if( reached_max_gain ) { | 242 if( reached_max_gain ) { |
247 for( k = 0; k < D; k++ ) { | 243 for( k = 0; k < D; k++ ) { |
248 /* Scale coefficients */ | 244 /* Scale coefficients */ |
249 A_Q16[ k ] = -silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 ); | 245 A_Q16[ k ] = -silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 ); |
250 } | 246 } |
251 /* Subtract energy of preceding samples from C0 */ | 247 /* Subtract energy of preceding samples from C0 */ |
252 if( rshifts > 0 ) { | 248 if( rshifts > 0 ) { |
253 for( s = 0; s < nb_subfr; s++ ) { | 249 for( s = 0; s < nb_subfr; s++ ) { |
254 x_ptr = x + s * subfr_length; | 250 x_ptr = x + s * subfr_length; |
255 C0 -= (opus_int32)silk_RSHIFT64( silk_inner_prod16_aligned_64( x
_ptr, x_ptr, D ), rshifts ); | 251 C0 -= (opus_int32)silk_RSHIFT64( silk_inner_prod16_aligned_64( x
_ptr, x_ptr, D, arch ), rshifts ); |
256 } | 252 } |
257 } else { | 253 } else { |
258 for( s = 0; s < nb_subfr; s++ ) { | 254 for( s = 0; s < nb_subfr; s++ ) { |
259 x_ptr = x + s * subfr_length; | 255 x_ptr = x + s * subfr_length; |
260 C0 -= silk_LSHIFT32( silk_inner_prod_aligned( x_ptr, x_ptr, D ),
-rshifts ); | 256 C0 -= silk_LSHIFT32( silk_inner_prod_aligned( x_ptr, x_ptr, D, a
rch), -rshifts); |
261 } | 257 } |
262 } | 258 } |
263 /* Approximate residual energy */ | 259 /* Approximate residual energy */ |
264 *res_nrg = silk_LSHIFT( silk_SMMUL( invGain_Q30, C0 ), 2 ); | 260 *res_nrg = silk_LSHIFT( silk_SMMUL( invGain_Q30, C0 ), 2 ); |
265 *res_nrg_Q = -rshifts; | 261 *res_nrg_Q = -rshifts; |
266 } else { | 262 } else { |
267 /* Return residual energy */ | 263 /* Return residual energy */ |
268 nrg = CAf[ 0 ];
/* Q( -rshifts ) */ | 264 nrg = CAf[ 0 ];
/* Q( -rshifts ) */ |
269 tmp1 = (opus_int32)1 << 16;
/* Q16 */ | 265 tmp1 = (opus_int32)1 << 16;
/* Q16 */ |
270 for( k = 0; k < D; k++ ) { | 266 for( k = 0; k < D; k++ ) { |
271 Atmp1 = silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 );
/* Q16 */ | 267 Atmp1 = silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 );
/* Q16 */ |
272 nrg = silk_SMLAWW( nrg, CAf[ k + 1 ], Atmp1 );
/* Q( -rshifts ) */ | 268 nrg = silk_SMLAWW( nrg, CAf[ k + 1 ], Atmp1 );
/* Q( -rshifts ) */ |
273 tmp1 = silk_SMLAWW( tmp1, Atmp1, Atmp1 );
/* Q16 */ | 269 tmp1 = silk_SMLAWW( tmp1, Atmp1, Atmp1 );
/* Q16 */ |
274 A_Q16[ k ] = -Atmp1; | 270 A_Q16[ k ] = -Atmp1; |
275 } | 271 } |
276 *res_nrg = silk_SMLAWW( nrg, silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_F
AC, 32 ), C0 ), -tmp1 );/* Q( -rshifts ) */ | 272 *res_nrg = silk_SMLAWW( nrg, silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_F
AC, 32 ), C0 ), -tmp1 );/* Q( -rshifts ) */ |
277 *res_nrg_Q = -rshifts; | 273 *res_nrg_Q = -rshifts; |
278 } | 274 } |
279 } | 275 } |
OLD | NEW |