2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file test/audio_filter_test.cc
21 * @brief Basic tests of audio filters.
24 #include <boost/test/unit_test.hpp>
25 #include "lib/audio_filter.h"
26 #include "lib/audio_buffers.h"
28 using boost::shared_ptr;
31 audio_filter_impulse_test_one (AudioFilter& f, int block_size, int num_blocks)
35 for (int i = 0; i < num_blocks; ++i) {
37 shared_ptr<AudioBuffers> in (new AudioBuffers (1, block_size));
38 for (int j = 0; j < block_size; ++j) {
39 in->data()[0][j] = c + j;
42 shared_ptr<AudioBuffers> out = f.run (in);
44 for (int j = 0; j < out->frames(); ++j) {
45 BOOST_CHECK_EQUAL (out->data()[0][j], c + j);
52 /** Create a filter with an impulse as a kernel and check that it
53 * passes data through unaltered.
55 BOOST_AUTO_TEST_CASE (audio_filter_impulse_kernel_test)
59 f._ir = new float[f._M + 1];
62 for (int i = 1; i <= f._M; ++i) {
66 audio_filter_impulse_test_one (f, 32, 1);
67 audio_filter_impulse_test_one (f, 256, 1);
68 audio_filter_impulse_test_one (f, 2048, 1);
71 /** Create filters and pass them impulses as input and check that
72 * the filter kernels comes back.
74 BOOST_AUTO_TEST_CASE (audio_filter_impulse_input_test)
76 LowPassAudioFilter lpf (0.02, 0.3);
78 shared_ptr<AudioBuffers> in (new AudioBuffers (1, 1751));
82 shared_ptr<AudioBuffers> out = lpf.run (in);
83 for (int j = 0; j < out->frames(); ++j) {
85 BOOST_CHECK_EQUAL (out->data(0)[j], lpf._ir[j]);
87 BOOST_CHECK_EQUAL (out->data(0)[j], 0);
91 HighPassAudioFilter hpf (0.02, 0.3);
93 in.reset (new AudioBuffers (1, 9133));
98 for (int j = 0; j < out->frames(); ++j) {
100 BOOST_CHECK_EQUAL (out->data(0)[j], hpf._ir[j]);
102 BOOST_CHECK_EQUAL (out->data(0)[j], 0);