2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 /** @file test/audio_filter_test.cc
22 * @brief Basic tests of audio filters.
25 #include <boost/test/unit_test.hpp>
26 #include "lib/audio_filter.h"
27 #include "lib/audio_buffers.h"
29 using boost::shared_ptr;
32 audio_filter_impulse_test_one (AudioFilter& f, int block_size, int num_blocks)
36 for (int i = 0; i < num_blocks; ++i) {
38 shared_ptr<AudioBuffers> in (new AudioBuffers (1, block_size));
39 for (int j = 0; j < block_size; ++j) {
40 in->data()[0][j] = c + j;
43 shared_ptr<AudioBuffers> out = f.run (in);
45 for (int j = 0; j < out->frames(); ++j) {
46 BOOST_CHECK_EQUAL (out->data()[0][j], c + j);
53 /** Create a filter with an impulse as a kernel and check that it
54 * passes data through unaltered.
56 BOOST_AUTO_TEST_CASE (audio_filter_impulse_kernel_test)
60 f._ir = new float[f._M + 1];
63 for (int i = 1; i <= f._M; ++i) {
67 audio_filter_impulse_test_one (f, 32, 1);
68 audio_filter_impulse_test_one (f, 256, 1);
69 audio_filter_impulse_test_one (f, 2048, 1);
72 /** Create filters and pass them impulses as input and check that
73 * the filter kernels comes back.
75 BOOST_AUTO_TEST_CASE (audio_filter_impulse_input_test)
77 LowPassAudioFilter lpf (0.02, 0.3);
79 shared_ptr<AudioBuffers> in (new AudioBuffers (1, 1751));
83 shared_ptr<AudioBuffers> out = lpf.run (in);
84 for (int j = 0; j < out->frames(); ++j) {
86 BOOST_CHECK_EQUAL (out->data(0)[j], lpf._ir[j]);
88 BOOST_CHECK_EQUAL (out->data(0)[j], 0);
92 HighPassAudioFilter hpf (0.02, 0.3);
94 in.reset (new AudioBuffers (1, 9133));
99 for (int j = 0; j < out->frames(); ++j) {
101 BOOST_CHECK_EQUAL (out->data(0)[j], hpf._ir[j]);
103 BOOST_CHECK_EQUAL (out->data(0)[j], 0);