blob: b08fd73a0e1a1d4d5b771afe917c7a8ddef618c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "tests/utils.h"
#include "audiographer/general/normalizer.h"
#include "audiographer/general/peak_reader.h"
using namespace AudioGrapher;
class NormalizerTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (NormalizerTest);
CPPUNIT_TEST (testConstAmplify);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp()
{
frames = 1024;
}
void tearDown()
{
delete [] random_data;
}
void testConstAmplify()
{
float target = 0.0;
random_data = TestUtils::init_random_data(frames, 0.5);
normalizer.reset (new Normalizer(target));
peak_reader.reset (new PeakReader());
sink.reset (new VectorSink<float>());
ProcessContext<float> const c (random_data, frames, 1);
peak_reader->process (c);
float peak = peak_reader->get_peak();
normalizer->alloc_buffer (frames);
normalizer->set_peak (peak);
normalizer->add_output (sink);
normalizer->process (c);
peak_reader->reset();
ConstProcessContext<float> normalized (sink->get_array(), frames, 1);
peak_reader->process (normalized);
peak = peak_reader->get_peak();
CPPUNIT_ASSERT (-FLT_EPSILON <= (peak - 1.0) && (peak - 1.0) <= 0.0);
}
private:
boost::shared_ptr<Normalizer> normalizer;
boost::shared_ptr<PeakReader> peak_reader;
boost::shared_ptr<VectorSink<float> > sink;
float * random_data;
nframes_t frames;
};
CPPUNIT_TEST_SUITE_REGISTRATION (NormalizerTest);
|