1 /***********************************************************************
2 Copyright (c) 2006-2010, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, (subject to the limitations in the disclaimer below)
5 are permitted provided that the following conditions 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 Skype Limited, nor the names of specific
12 contributors, may be used to endorse or promote products derived from
13 this software without specific prior written permission.
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27 
28 /*                                                                      *
29  * SKP_Silk_schur.c                                                   *
30  *                                                                      *
31  * Calculates the reflection coefficients from the correlation sequence *
32  *                                                                      *
33  * Copyright 2008 (c), Skype Limited                                    *
34  * Date: 080103                                                         *
35  *                                                                      */
36 #include "SKP_Silk_SigProc_FIX.h"
37 
38 /* Faster than schur64(), but much less accurate.                       */
39 /* uses SMLAWB(), requiring armv5E and higher.                          */
SKP_Silk_schur(SKP_int16 * rc_Q15,const SKP_int32 * c,const SKP_int32 order)40 void SKP_Silk_schur(
41     SKP_int16            *rc_Q15,                /* O:    reflection coefficients [order] Q15         */
42     const SKP_int32      *c,                     /* I:    correlations [order+1]                      */
43     const SKP_int32      order                   /* I:    prediction order                            */
44 )
45 {
46     SKP_int        k, n, lz;
47     SKP_int32    C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ];
48     SKP_int32    Ctmp1, Ctmp2, rc_tmp_Q15;
49 
50     /* Get number of leading zeros */
51     lz = SKP_Silk_CLZ32( c[ 0 ] );
52 
53     /* Copy correlations and adjust level to Q30 */
54     if( lz < 2 ) {
55         /* lz must be 1, so shift one to the right */
56         for( k = 0; k < order + 1; k++ ) {
57             C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_RSHIFT( c[ k ], 1 );
58         }
59     } else if( lz > 2 ) {
60         /* Shift to the left */
61         lz -= 2;
62         for( k = 0; k < order + 1; k++ ) {
63             C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_LSHIFT( c[k], lz );
64         }
65     } else {
66         /* No need to shift */
67         for( k = 0; k < order + 1; k++ ) {
68             C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];
69         }
70     }
71 
72     for( k = 0; k < order; k++ ) {
73 
74         /* Get reflection coefficient */
75         rc_tmp_Q15 = -SKP_DIV32_16( C[ k + 1 ][ 0 ], SKP_max_32( SKP_RSHIFT( C[ 0 ][ 1 ], 15 ), 1 ) );
76 
77         /* Clip (shouldn't happen for properly conditioned inputs) */
78         rc_tmp_Q15 = SKP_SAT16( rc_tmp_Q15 );
79 
80         /* Store */
81         rc_Q15[ k ] = (SKP_int16)rc_tmp_Q15;
82 
83         /* Update correlations */
84         for( n = 0; n < order - k; n++ ) {
85             Ctmp1 = C[ n + k + 1 ][ 0 ];
86             Ctmp2 = C[ n ][ 1 ];
87             C[ n + k + 1 ][ 0 ] = SKP_SMLAWB( Ctmp1, SKP_LSHIFT( Ctmp2, 1 ), rc_tmp_Q15 );
88             C[ n ][ 1 ]         = SKP_SMLAWB( Ctmp2, SKP_LSHIFT( Ctmp1, 1 ), rc_tmp_Q15 );
89         }
90     }
91 }
92