2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
2010-03-15 15:11:48 -04:00
|
|
|
#include "audiographer/general/normalizer.h"
|
|
|
|
#include "audiographer/general/peak_reader.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class NormalizerTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (NormalizerTest);
|
|
|
|
CPPUNIT_TEST (testConstAmplify);
|
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samples = 1024;
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testConstAmplify()
|
|
|
|
{
|
|
|
|
float target = 0.0;
|
2017-09-18 12:39:17 -04:00
|
|
|
random_data = TestUtils::init_random_data(samples, 0.5);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2021-04-13 14:36:56 -04:00
|
|
|
normalizer.reset (new Normalizer(target, samples));
|
2009-12-27 09:46:23 -05:00
|
|
|
peak_reader.reset (new PeakReader());
|
|
|
|
sink.reset (new VectorSink<float>());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> const c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
peak_reader->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
float peak = peak_reader->get_peak();
|
|
|
|
normalizer->set_peak (peak);
|
|
|
|
normalizer->add_output (sink);
|
|
|
|
normalizer->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
peak_reader->reset();
|
2017-09-18 12:39:17 -04:00
|
|
|
ConstProcessContext<float> normalized (sink->get_array(), samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
peak_reader->process (normalized);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
peak = peak_reader->get_peak();
|
|
|
|
CPPUNIT_ASSERT (-FLT_EPSILON <= (peak - 1.0) && (peak - 1.0) <= 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Normalizer> normalizer;
|
|
|
|
std::shared_ptr<PeakReader> peak_reader;
|
|
|
|
std::shared_ptr<VectorSink<float> > sink;
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
float * random_data;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples;
|
2009-12-27 09:46:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (NormalizerTest);
|