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)
58 f._ir.resize (f._M + 1);
61 for (int i = 1; i <= f._M; ++i) {
65 audio_filter_impulse_test_one (f, 32, 1);
66 audio_filter_impulse_test_one (f, 256, 1);
67 audio_filter_impulse_test_one (f, 2048, 1);
70 /** Create filters and pass them impulses as input and check that
71 * the filter kernels comes back.
73 BOOST_AUTO_TEST_CASE (audio_filter_impulse_input_test)
75 LowPassAudioFilter lpf (0.02, 0.3);
77 shared_ptr<AudioBuffers> in (new AudioBuffers (1, 1751));
81 shared_ptr<AudioBuffers> out = lpf.run (in);
82 for (int j = 0; j < out->frames(); ++j) {
84 BOOST_CHECK_EQUAL (out->data(0)[j], lpf._ir[j]);
86 BOOST_CHECK_EQUAL (out->data(0)[j], 0);
90 HighPassAudioFilter hpf (0.02, 0.3);
92 in.reset (new AudioBuffers (1, 9133));
97 for (int j = 0; j < out->frames(); ++j) {
99 BOOST_CHECK_EQUAL (out->data(0)[j], hpf._ir[j]);
101 BOOST_CHECK_EQUAL (out->data(0)[j], 0);