eDSP  0.0.1
A cross-platform DSP library written in C++.
filter.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17  *
18  * File: filter.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 30/8/2018
21  */
22 #ifndef EDSP_FILTER_HPP
23 #define EDSP_FILTER_HPP
24 
25 #include <edsp/filter/biquad.hpp>
27 
28 #include <edsp/filter/internal/rbj_designer.hpp>
29 #include <edsp/filter/internal/zoelzer_designer.hpp>
30 #include <edsp/filter/internal/butterworth_designer.hpp>
31 #include <edsp/filter/internal/chebyshev_I_designer.hpp>
32 #include <edsp/filter/internal/chebyshev_II_designer.hpp>
33 
37 
38 namespace edsp { namespace filter {
39 
45  enum class DesignerType {
46  RBJ,
47  Zolzer,
48  Butterworth,
49  ChebyshevI,
50  ChebyshevII,
51  Bessel,
52  Elliptic,
53  Legendre
54  };
55 
56  template <typename T, DesignerType Designer, std::size_t MaxOrder>
57  struct designer {};
58 
64  template <typename T, std::size_t MaxOrder>
65  struct designer<T, DesignerType::RBJ, MaxOrder> {
76  template <FilterType Type, typename... Args>
77  constexpr biquad<T> design(T fc, T sample_rate, T Q, T gain_db = 1) const {
78  return RBJFilterDesigner<T, Type>{}(fc, sample_rate, Q, gain_db);
79  }
80  };
81 
87  template <typename T, std::size_t MaxOrder>
88  struct designer<T, DesignerType::Zolzer, MaxOrder> {
100  template <FilterType Type, typename... Args>
101  constexpr biquad<T> design(T fc, T sample_rate, T Q, T gain_db = 1) const {
102  return ZoelzerFilterDesigner<T, Type>{}(fc, sample_rate, Q, gain_db);
103  }
104  };
105 
111  template <typename T, std::size_t MaxOrder>
112  struct designer<T, DesignerType::Butterworth, MaxOrder> {
113  template <FilterType Type, typename... Args>
114  constexpr auto design(Args... arg) const -> decltype(ButterworthDesigner<T, Type, MaxOrder>{}(arg...)) {
115  return ButterworthDesigner<T, Type, MaxOrder>{}.operator()(arg...);
116  }
117  };
118 
124  template <typename T, std::size_t MaxOrder>
125  struct designer<T, DesignerType::ChebyshevI, MaxOrder> {
126  template <FilterType Type, typename... Args>
127  constexpr auto design(Args... arg) const
128  -> decltype(ChebyshevIDesigner<T, Type, MaxOrder>{}(std::declval<Args&&>()...)) {
129  return ChebyshevIDesigner<T, Type, MaxOrder>{}(arg...);
130  }
131  };
132 
138  template <typename T, std::size_t MaxOrder>
139  struct designer<T, DesignerType::ChebyshevII, MaxOrder> {
140  template <FilterType Type, typename... Args>
141  constexpr auto design(Args... arg) const
142  -> decltype(ChebyshevIIDesigner<T, Type, MaxOrder>{}(std::declval<Args&&>()...)) {
143  return ChebyshevIIDesigner<T, Type, MaxOrder>{}(arg...);
144  }
145  };
146 
154  template <typename T, DesignerType Designer, FilterType Type, std::size_t MaxOrder, typename... Args>
155  constexpr auto make_filter(Args... arg)
156  -> decltype(designer<T, Designer, MaxOrder>{}.template design<Type>(std::declval<Args&&>()...)) {
157  const auto creator = designer<T, Designer, MaxOrder>{};
158  return creator.template design<Type>(arg...);
159  }
160 
161 }} // namespace edsp::filter
162 
163 #endif // EDSP_FILTER_HPP
FilterType
The FilterType enum defines the different available filters.
Definition: biquad.hpp:38
template design< Type >(std::declval< Args &&>()...))
Definition: filter.hpp:156
constexpr auto design(Args... arg) const -> decltype(ButterworthDesigner< T, Type, MaxOrder >
Definition: filter.hpp:114
constexpr auto design(Args... arg) const -> decltype(ChebyshevIIDesigner< T, Type, MaxOrder >
Definition: filter.hpp:141
constexpr biquad< T > design(T fc, T sample_rate, T Q, T gain_db=1) const
Returns a filter which parameters represents the designed frequency response by using the Zoelzer for...
Definition: filter.hpp:101
This Biquad class implements a second-order recursive linear filter, containing two poles and two zer...
Definition: biquad.hpp:71
DesignerType
The DesignerType enum defines the different filter&#39;s implementation from different authors...
Definition: filter.hpp:45
Definition: filter.hpp:57
constexpr auto design(Args... arg) const -> decltype(ChebyshevIDesigner< T, Type, MaxOrder >
Definition: filter.hpp:127
constexpr auto make_filter(Args... arg) -> decltype(designer< T, Designer, MaxOrder >
Creates a filter using args as the parameter list for the construction.
Definition: filter.hpp:155
Definition: amplifier.hpp:29
constexpr biquad< T > design(T fc, T sample_rate, T Q, T gain_db=1) const
Returns a filter which parameters represents the designed frequency response by using the RBJ formula...
Definition: filter.hpp:77