Home | History | Annotate | Download | only in source
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 /*
     13  * This file contains the function WebRtcSpl_FilterAR().
     14  * The description header can be found in signal_processing_library.h
     15  *
     16  */
     17 
     18 #include "signal_processing_library.h"
     19 
     20 int WebRtcSpl_FilterAR(G_CONST WebRtc_Word16* a,
     21                        int a_length,
     22                        G_CONST WebRtc_Word16* x,
     23                        int x_length,
     24                        WebRtc_Word16* state,
     25                        int state_length,
     26                        WebRtc_Word16* state_low,
     27                        int state_low_length,
     28                        WebRtc_Word16* filtered,
     29                        WebRtc_Word16* filtered_low,
     30                        int filtered_low_length)
     31 {
     32     WebRtc_Word32 o;
     33     WebRtc_Word32 oLOW;
     34     int i, j, stop;
     35     G_CONST WebRtc_Word16* x_ptr = &x[0];
     36     WebRtc_Word16* filteredFINAL_ptr = filtered;
     37     WebRtc_Word16* filteredFINAL_LOW_ptr = filtered_low;
     38 
     39     state_low_length = state_low_length;
     40     filtered_low_length = filtered_low_length;
     41 
     42     for (i = 0; i < x_length; i++)
     43     {
     44         // Calculate filtered[i] and filtered_low[i]
     45         G_CONST WebRtc_Word16* a_ptr = &a[1];
     46         WebRtc_Word16* filtered_ptr = &filtered[i - 1];
     47         WebRtc_Word16* filtered_low_ptr = &filtered_low[i - 1];
     48         WebRtc_Word16* state_ptr = &state[state_length - 1];
     49         WebRtc_Word16* state_low_ptr = &state_low[state_length - 1];
     50 
     51         o = (WebRtc_Word32)(*x_ptr++) << 12;
     52         oLOW = (WebRtc_Word32)0;
     53 
     54         stop = (i < a_length) ? i + 1 : a_length;
     55         for (j = 1; j < stop; j++)
     56         {
     57             o -= WEBRTC_SPL_MUL_16_16(*a_ptr, *filtered_ptr--);
     58             oLOW -= WEBRTC_SPL_MUL_16_16(*a_ptr++, *filtered_low_ptr--);
     59         }
     60         for (j = i + 1; j < a_length; j++)
     61         {
     62             o -= WEBRTC_SPL_MUL_16_16(*a_ptr, *state_ptr--);
     63             oLOW -= WEBRTC_SPL_MUL_16_16(*a_ptr++, *state_low_ptr--);
     64         }
     65 
     66         o += (oLOW >> 12);
     67         *filteredFINAL_ptr = (WebRtc_Word16)((o + (WebRtc_Word32)2048) >> 12);
     68         *filteredFINAL_LOW_ptr++ = (WebRtc_Word16)(o - ((WebRtc_Word32)(*filteredFINAL_ptr++)
     69                 << 12));
     70     }
     71 
     72     // Save the filter state
     73     if (x_length >= state_length)
     74     {
     75         WebRtcSpl_CopyFromEndW16(filtered, x_length, a_length - 1, state);
     76         WebRtcSpl_CopyFromEndW16(filtered_low, x_length, a_length - 1, state_low);
     77     } else
     78     {
     79         for (i = 0; i < state_length - x_length; i++)
     80         {
     81             state[i] = state[i + x_length];
     82             state_low[i] = state_low[i + x_length];
     83         }
     84         for (i = 0; i < x_length; i++)
     85         {
     86             state[state_length - x_length + i] = filtered[i];
     87             state[state_length - x_length + i] = filtered_low[i];
     88         }
     89     }
     90 
     91     return x_length;
     92 }
     93