RavEngine
Loading...
Searching...
No Matches
fir_filter.h
1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_DSP_FIR_FILTER_H_
18#define RESONANCE_AUDIO_DSP_FIR_FILTER_H_
19
20#include "base/audio_buffer.h"
21
22namespace vraudio {
23
24class FirFilter {
25 public:
26 // Constructs a |FirFilter| from a mono |AudioBuffer| of filter coefficients.
27 //
28 // @param filter_coefficients FIR filter coefficients.
29 // @param frames_per_buffer Number of frames of data in each audio buffer.
30 FirFilter(const AudioBuffer::Channel& filter_coefficients,
31 size_t frames_per_buffer);
32
33 // Filters an array of input with a finite impulse response (FIR) filter in
34 // the time domain. All pointers and lengths passed must be SIMD compatible.
35 //
36 // @param input Pointer to an aray of input.
37 // @param output Pointer to a cleared block of memory of the input length.
38 void Process(const AudioBuffer::Channel& input, AudioBuffer::Channel* output);
39
40 // Returns the length of the filter kernel after zeropadding.
41 //
42 // @return Length of the FIR filter in frames.
43 size_t filter_length() const { return filter_length_; }
44
45 private:
46 // Length of the filter kernel in frames after zeropadding.
47 size_t filter_length_;
48
49 // Number of filter chunks equivalent to the filter length after zeropadding
50 // divided by the SIMD_LENGTH.
51 size_t num_filter_chunks_;
52
53 // Coefficients of the filter stored in a repeated format.
54 AudioBuffer coefficients_;
55
56 // Aligned buffer of previous and current input.
57 AudioBuffer state_;
58};
59
60} // namespace vraudio
61
62#endif // RESONANCE_AUDIO_DSP_FIR_FILTER_H_
Definition audio_buffer.h:78
Definition channel_view.h:30
Definition fir_filter.h:24