• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright  2019 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef ANDROID_FXLAB_COMBFILTER_H
17 #define ANDROID_FXLAB_COMBFILTER_H
18 
19 #include "utils/DelayLine.h"
20 
21 template <class iter_type>
22 class CombFilter {
23 
24 public:
25     // delay > 0 in samples
CombFilter(float blend,float feedForward,float feedBack,int delay)26     CombFilter(float blend, float feedForward, float feedBack, int delay) :
27         kBlend(blend),
28         kFeedForward(feedForward),
29         kFeedBack(feedBack),
30         kDelay(static_cast<size_t>(delay)) {}
31 
32 
operator()33     void operator () (typename std::iterator_traits<iter_type>::reference x) {
34         auto delayOutput = delayLine[kDelay];
35         auto delayInput = x + kFeedBack * delayOutput;
36         delayLine.push(delayInput);
37         x = delayInput * kBlend + delayOutput * kFeedForward;
38     }
operator()39     void operator () (iter_type begin, iter_type end) {
40         for (; begin != end; ++begin) {
41             operator()(*begin);
42         }
43     }
44 private:
45     // Weights
46     const float kBlend;
47     const float kFeedForward;
48     const float kFeedBack;
49     const size_t kDelay;
50 
51     DelayLine<typename std::iterator_traits<iter_type>::value_type> delayLine {kDelay + 1};
52 };
53 #endif //ANDROID_FXLAB_COMBFILTER_H
54