andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | abf0cd8 | 2013-05-27 09:49:58 +0000 | [diff] [blame] | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 19 | |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 20 | int WebRtcSpl_FilterAR(const int16_t* a, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 21 | int a_length, |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 22 | const int16_t* x, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | int x_length, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 24 | int16_t* state, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | int state_length, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 26 | int16_t* state_low, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 27 | int state_low_length, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 28 | int16_t* filtered, |
| 29 | int16_t* filtered_low, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | int filtered_low_length) |
| 31 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 32 | int32_t o; |
| 33 | int32_t oLOW; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 34 | int i, j, stop; |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 35 | const int16_t* x_ptr = &x[0]; |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 36 | int16_t* filteredFINAL_ptr = filtered; |
| 37 | int16_t* filteredFINAL_LOW_ptr = filtered_low; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 38 | |
| 39 | for (i = 0; i < x_length; i++) |
| 40 | { |
| 41 | // Calculate filtered[i] and filtered_low[i] |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 42 | const int16_t* a_ptr = &a[1]; |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 43 | int16_t* filtered_ptr = &filtered[i - 1]; |
| 44 | int16_t* filtered_low_ptr = &filtered_low[i - 1]; |
| 45 | int16_t* state_ptr = &state[state_length - 1]; |
| 46 | int16_t* state_low_ptr = &state_low[state_length - 1]; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 47 | |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 48 | o = (int32_t)(*x_ptr++) << 12; |
| 49 | oLOW = (int32_t)0; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 50 | |
| 51 | stop = (i < a_length) ? i + 1 : a_length; |
| 52 | for (j = 1; j < stop; j++) |
| 53 | { |
| 54 | o -= WEBRTC_SPL_MUL_16_16(*a_ptr, *filtered_ptr--); |
| 55 | oLOW -= WEBRTC_SPL_MUL_16_16(*a_ptr++, *filtered_low_ptr--); |
| 56 | } |
| 57 | for (j = i + 1; j < a_length; j++) |
| 58 | { |
| 59 | o -= WEBRTC_SPL_MUL_16_16(*a_ptr, *state_ptr--); |
| 60 | oLOW -= WEBRTC_SPL_MUL_16_16(*a_ptr++, *state_low_ptr--); |
| 61 | } |
| 62 | |
| 63 | o += (oLOW >> 12); |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 64 | *filteredFINAL_ptr = (int16_t)((o + (int32_t)2048) >> 12); |
| 65 | *filteredFINAL_LOW_ptr++ = (int16_t)(o - ((int32_t)(*filteredFINAL_ptr++) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 66 | << 12)); |
| 67 | } |
| 68 | |
| 69 | // Save the filter state |
| 70 | if (x_length >= state_length) |
| 71 | { |
| 72 | WebRtcSpl_CopyFromEndW16(filtered, x_length, a_length - 1, state); |
| 73 | WebRtcSpl_CopyFromEndW16(filtered_low, x_length, a_length - 1, state_low); |
| 74 | } else |
| 75 | { |
| 76 | for (i = 0; i < state_length - x_length; i++) |
| 77 | { |
| 78 | state[i] = state[i + x_length]; |
| 79 | state_low[i] = state_low[i + x_length]; |
| 80 | } |
| 81 | for (i = 0; i < x_length; i++) |
| 82 | { |
| 83 | state[state_length - x_length + i] = filtered[i]; |
| 84 | state[state_length - x_length + i] = filtered_low[i]; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return x_length; |
| 89 | } |