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 #include "SKP_Silk_main_FIX.h"
29 
SKP_Silk_LTP_analysis_filter_FIX(SKP_int16 * LTP_res,const SKP_int16 * x,const SKP_int16 LTPCoef_Q14[LTP_ORDER * NB_SUBFR],const SKP_int pitchL[NB_SUBFR],const SKP_int32 invGains_Qxx[NB_SUBFR],const SKP_int Qxx,const SKP_int subfr_length,const SKP_int pre_length)30 void SKP_Silk_LTP_analysis_filter_FIX(
31     SKP_int16       *LTP_res,                           /* O:   LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length )  */
32     const SKP_int16 *x,                                 /* I:   Pointer to input signal with at least max( pitchL ) preceeding samples  */
33     const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I:   LTP_ORDER LTP coefficients for each NB_SUBFR subframe                   */
34     const SKP_int   pitchL[ NB_SUBFR ],                 /* I:   Pitch lag, one for each subframe                                        */
35     const SKP_int32 invGains_Qxx[ NB_SUBFR ],           /* I:   Inverse quantization gains, one for each subframe                       */
36     const SKP_int   Qxx,                                /* I:   Inverse quantization gains Q domain                                     */
37     const SKP_int   subfr_length,                       /* I:   Length of each subframe                                                 */
38     const SKP_int   pre_length                          /* I:   Length of the preceeding samples starting at &x[0] for each subframe    */
39 )
40 {
41     const SKP_int16 *x_ptr, *x_lag_ptr;
42     SKP_int16   Btmp_Q14[ LTP_ORDER ];
43     SKP_int16   *LTP_res_ptr;
44     SKP_int     k, i, j;
45     SKP_int32   LTP_est;
46 
47     x_ptr = x;
48     LTP_res_ptr = LTP_res;
49     for( k = 0; k < NB_SUBFR; k++ ) {
50 
51         x_lag_ptr = x_ptr - pitchL[ k ];
52         for( i = 0; i < LTP_ORDER; i++ ) {
53             Btmp_Q14[ i ] = LTPCoef_Q14[ k * LTP_ORDER + i ];
54         }
55 
56         /* LTP analysis FIR filter */
57         for( i = 0; i < subfr_length + pre_length; i++ ) {
58             LTP_res_ptr[ i ] = x_ptr[ i ];
59 
60             /* Long-term prediction */
61             LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] );
62             for( j = 1; j < LTP_ORDER; j++ ) {
63                 LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] );
64             }
65             LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0
66 
67             /* Subtract long-term prediction */
68             LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est );
69 
70             /* Scale residual */
71             if( Qxx == 16 ) {
72                 LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Qxx[ k ], LTP_res_ptr[ i ] );
73             } else {
74                 LTP_res_ptr[ i ] = ( SKP_int16 )SKP_CHECK_FIT16( SKP_RSHIFT64( SKP_SMULL( invGains_Qxx[ k ], LTP_res_ptr[ i ] ), Qxx ) );
75             }
76 
77             x_lag_ptr++;
78         }
79 
80         /* Update pointers */
81         LTP_res_ptr += subfr_length + pre_length;
82         x_ptr       += subfr_length;
83     }
84 }
85 
86