Rename TYPE_DEBUG_PLAYER to TYPE_DEBUG_VIDEO_VIEW.
[dcpomatic.git] / src / lib / audio_filter.h
1 /*
2     Copyright (C) 2014 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 #include <boost/shared_ptr.hpp>
25
26 class AudioBuffers;
27 struct audio_filter_impulse_input_test;
28
29 /** An audio filter which can take AudioBuffers and apply some filtering operation,
30  *  returning filtered samples
31  */
32 class AudioFilter
33 {
34 public:
35         explicit AudioFilter (float transition_bandwidth)
36                 : _ir (0)
37         {
38                 _M = 4 / transition_bandwidth;
39                 if (_M % 2) {
40                         ++_M;
41                 }
42         }
43
44         virtual ~AudioFilter ();
45
46         boost::shared_ptr<AudioBuffers> run (boost::shared_ptr<const AudioBuffers> in);
47
48         void flush ();
49
50 protected:
51         friend struct audio_filter_impulse_kernel_test;
52         friend struct audio_filter_impulse_input_test;
53
54         float* sinc_blackman (float cutoff, bool invert) const;
55
56         float* _ir;
57         int _M;
58         boost::shared_ptr<AudioBuffers> _tail;
59 };
60
61 class LowPassAudioFilter : public AudioFilter
62 {
63 public:
64         /** Construct a windowed-sinc low-pass filter using the Blackman window.
65          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
66          *  @param cutoff Cutoff frequency as a fraction of the sampling rate.
67          */
68         LowPassAudioFilter (float transition_bandwidth, float cutoff);
69 };
70
71 class HighPassAudioFilter : public AudioFilter
72 {
73 public:
74         /** Construct a windowed-sinc high-pass filter using the Blackman window.
75          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
76          *  @param cutoff Cutoff frequency as a fraction of the sampling rate.
77          */
78         HighPassAudioFilter (float transition_bandwidth, float cutoff);
79 };
80
81 class BandPassAudioFilter : public AudioFilter
82 {
83 public:
84         /** Construct a windowed-sinc band-pass filter using the Blackman window.
85          *  @param transition_bandwidth Transition bandwidth as a fraction of the sampling rate.
86          *  @param lower Lower cutoff frequency as a fraction of the sampling rate.
87          *  @param higher Higher cutoff frequency as a fraction of the sampling rate.
88          */
89         BandPassAudioFilter (float transition_bandwidth, float lower, float higher);
90 };
91
92 #endif