synapse-app-sdk
C++ SDK for Synapse Apps
Loading...
Searching...
No Matches
bandpass.hpp
1#pragma once
2#include "synapse-app-sdk/dsp/filter/base_filter.hpp"
3#include <iostream>
4#include <memory>
5
6namespace synapse {
7
18template <int FilterOrder>
19std::unique_ptr<synapse::BaseFilter> create_bandpass_filter(const float sample_rate_hz,
20 const float low_cutoff_hz,
21 const float high_cutoff_hz) {
22 // TODO: Validate input
23 const double bandwidth = high_cutoff_hz - low_cutoff_hz;
24 const double center_frequency = high_cutoff_hz - (bandwidth / 2);
25 if (bandwidth <= 0) {
26 return nullptr;
27 }
28 Iir::Butterworth::BandPass<FilterOrder> filter;
29 try {
30 filter.setup(sample_rate_hz, center_frequency, bandwidth);
31 return std::make_unique<FilterWrapper<decltype(filter)>>(std::move(filter));
32 } catch (const std::exception& e) {
33 std::cerr << "Error setting up filter with" << "sample_rate: " << sample_rate_hz
34 << "center: " << center_frequency << "bandwidth: " << bandwidth << "why: " << e.what()
35 << std::endl;
36 return nullptr;
37 }
38}
39
40} // namespace synapse
Wrapper class that adapts various filter implementations to the BaseFilter interface.
Definition base_filter.hpp:31