diff options
author | Alejandro Luebs <aluebs@webrtc.org> | 2015-04-14 15:51:28 -0700 |
---|---|---|
committer | Alejandro Luebs <aluebs@webrtc.org> | 2015-04-14 22:51:22 +0000 |
commit | a9c0ae284c464e962492c53f0d11bb2fc99da910 (patch) | |
tree | 1cbe197e4d3f418cb8dfc5f77a6c29586ba836cc /webrtc/common_audio/sparse_fir_filter.h | |
parent | e432800aeb6b695bda14acf2d60c0200803b5218 (diff) | |
download | webrtc-a9c0ae284c464e962492c53f0d11bb2fc99da910.tar.gz |
Add a sparse FIR filter implementation
A Finite Impulse Response filter implementation which takes advantage of sparse coefficients.
The coefficients are assumed to be uniformly distributed and have an initial offset.
BUG=webrtc:3146
R=andrew@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/49659004
Cr-Commit-Position: refs/heads/master@{#9002}
Diffstat (limited to 'webrtc/common_audio/sparse_fir_filter.h')
-rw-r--r-- | webrtc/common_audio/sparse_fir_filter.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/webrtc/common_audio/sparse_fir_filter.h b/webrtc/common_audio/sparse_fir_filter.h new file mode 100644 index 0000000000..f5f3fadcce --- /dev/null +++ b/webrtc/common_audio/sparse_fir_filter.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_COMMON_AUDIO_SPARSE_FIR_FILTER_H_ +#define WEBRTC_COMMON_AUDIO_SPARSE_FIR_FILTER_H_ + +#include <cstring> +#include <vector> + +namespace webrtc { + +// A Finite Impulse Response filter implementation which takes advantage of a +// sparse structure with uniformly distributed non-zero coefficients. +class SparseFIRFilter { + public: + // |num_nonzero_coeffs| is the number of non-zero coefficients, + // |nonzero_coeffs|. They are assumed to be uniformly distributed every + // |sparsity| samples and with an initial |offset|. The rest of the filter + // coefficients will be assumed zeros. For example, with sparsity = 3, and + // offset = 1 the filter coefficients will be: + // B = [0 coeffs[0] 0 0 coeffs[1] 0 0 coeffs[2] ... ] + // All initial state values will be zeros. + SparseFIRFilter(const float* nonzero_coeffs, + size_t num_nonzero_coeffs, + size_t sparsity, + size_t offset); + + // Filters the |in| data supplied. + // |out| must be previously allocated and it must be at least of |length|. + void Filter(const float* in, size_t length, float* out); + + private: + const size_t sparsity_; + const size_t offset_; + const std::vector<float> nonzero_coeffs_; + std::vector<float> state_; +}; + +} // namespace webrtc + +#endif // WEBRTC_COMMON_AUDIO_SPARSE_FIR_FILTER_H_ |