Use dcp::file_to_string().
[dcpomatic.git] / src / lib / audio_filter.h
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_AUDIO_FILTER_H
22 #define DCPOMATIC_AUDIO_FILTER_H
23
24
25 #include <memory>
26 #include <vector>
27
28
29 class AudioBuffers;
30 struct audio_filter_impulse_input_test;
31
32
33 /** An audio filter which can take AudioBuffers and apply some filtering operation,
34  *  returning filtered samples
35  */
36 class AudioFilter
37 {
38 public:
39         explicit AudioFilter (float transition_bandwidth)
40         {
41                 _M = 4 / transition_bandwidth;
42                 if (_M % 2) {
43                         ++_M;
44                 }
45         }
46
47         virtual ~AudioFilter () {}
48
49         std::shared_ptr<AudioBuffers> run (std::shared_ptr<const AudioBuffers> in);
50
51         void flush ();
52
53 protected:
54         friend struct audio_filter_impulse_kernel_test;
55         friend struct audio_filter_impulse_input_test;
56
57         std::vector<float> sinc_blackman (float cutoff, bool invert) const;
58
59         std::vector<float> _ir;
60         int _M;
61         std::shared_ptr<AudioBuffers> _tail;
62 };
63
64
65 class LowPassAudioFilter : public AudioFilter
66 {
67 public:
68         /** Construct a windowed-sinc low-pass filter using the Blackman window.
69          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
70          *  @param cutoff Cutoff frequency as a fraction of the sampling rate.
71          */
72         LowPassAudioFilter (float transition_bandwidth, float cutoff);
73 };
74
75
76 class HighPassAudioFilter : public AudioFilter
77 {
78 public:
79         /** Construct a windowed-sinc high-pass filter using the Blackman window.
80          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
81          *  @param cutoff Cutoff frequency as a fraction of the sampling rate.
82          */
83         HighPassAudioFilter (float transition_bandwidth, float cutoff);
84 };
85
86
87 class BandPassAudioFilter : public AudioFilter
88 {
89 public:
90         /** Construct a windowed-sinc band-pass filter using the Blackman window.
91          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
92          *  @param lower Lower cutoff frequency as a fraction of the sampling rate.
93          *  @param higher Higher cutoff frequency as a fraction of the sampling rate.
94          */
95         BandPassAudioFilter (float transition_bandwidth, float lower, float higher);
96 };
97
98
99 #endif