1
// ------------------------------------------------------------------------
2
// audiofx_amplitu_test.h: Unit tests for EFFECT_AMPLIFY* classes
3
// Copyright (C) 2009 Kai Vehmanen
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// ------------------------------------------------------------------------
28
#include "kvu_inttypes.h"
30
#include "audiofx_amplitude.h"
31
#include "samplebuffer_functions.h"
32
#include "eca-test-case.h"
37
* Unit test for EFFECT_AMPLIFY
39
class EFFECT_AMPLIFY_TEST : public ECA_TEST_CASE {
43
virtual string do_name(void) const { return("EFFECT_AMPLIFY"); }
44
virtual void do_run(void);
48
virtual ~EFFECT_AMPLIFY_TEST(void) { }
54
void EFFECT_AMPLIFY_TEST::do_run(void)
56
const int bufsize = 1024;
57
const int channels = 12;
58
const SAMPLE_BUFFER::sample_t multiplier = 112.1f;
60
std::fprintf(stdout, "%s: tests for %s class\n",
61
name().c_str(), __FILE__);
63
/* case: multiply_by */
65
std::fprintf(stdout, "%s: EFFECT_AMPLIFY::process\n",
67
SAMPLE_BUFFER sbuf_test (bufsize, channels);
68
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
70
EFFECT_AMPLIFY amp_test;
71
EFFECT_AMPLIFY amp_ref;
73
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_ref);
74
sbuf_test.copy_all_content(sbuf_ref);
76
amp_test.init(&sbuf_test);
77
amp_ref.init(&sbuf_ref);
79
amp_test.set_parameter(1, multiplier);
80
amp_ref.set_parameter(1, multiplier);
83
amp_ref.process_ref();
85
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
86
ECA_TEST_FAILURE("optimized EFFECT_AMPLIFY");
92
* Unit test for EFFECT_AMPLIFY_CHANNEL
94
class EFFECT_AMPLIFY_CHANNEL_TEST : public ECA_TEST_CASE {
98
virtual string do_name(void) const { return("EFFECT_AMPLIFY_CHANNEL"); }
99
virtual void do_run(void);
103
virtual ~EFFECT_AMPLIFY_CHANNEL_TEST(void) { }
109
void EFFECT_AMPLIFY_CHANNEL_TEST::do_run(void)
111
const int bufsize = 1024;
112
const int channels = 12;
113
const SAMPLE_BUFFER::sample_t multiplier = 112.1f;
115
std::fprintf(stdout, "%s: tests for %s class\n",
116
name().c_str(), __FILE__);
118
/* case: process() */
120
std::fprintf(stdout, "%s: process()\n", __FILE__);
121
SAMPLE_BUFFER sbuf_test (bufsize, channels);
122
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
124
EFFECT_AMPLIFY_CHANNEL amp_test;
125
EFFECT_AMPLIFY_CHANNEL amp_ref;
127
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_ref);
128
sbuf_test.copy_all_content(sbuf_ref);
130
amp_test.init(&sbuf_test);
131
amp_ref.init(&sbuf_ref);
133
amp_test.set_parameter(1, multiplier);
134
amp_test.set_parameter(2, 3);
135
amp_ref.set_parameter(1, multiplier);
136
amp_ref.set_parameter(2, 3);
139
amp_ref.process_ref();
141
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
142
ECA_TEST_FAILURE("optimized process()");