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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
* Copyright (c) 2001-2002 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "EnvelopeExtractor.hxx"
#include "EnvelopeGenerator.hxx"
#if 0
#include "GnuplotSnapshot.hxx"
#endif
//#include "NodeTmpl.hxx"
//#include "StreamBuffer.hxx"
//#include "CircularStreamImpl.hxx"
#include "WaveGenerator.hxx"
#include "MonoAudioFileWriter.hxx"
#include "Controller.hxx"
#include <CLAM/AudioOutPort.hxx>
#include <iostream>
#include <cstdlib>
namespace CLAMTest {
using namespace CLAM;
class EnvelopeExtractorTest {
int mDataLength;
int mSampleRate;
int mFrameSize;
int mIterations;
EnvelopeExtractor *mpExtractor1;
EnvelopeExtractor *mpExtractor2;
EnvelopeGenerator *mpGenerator1;
EnvelopeGenerator *mpGenerator2;
WaveGenerator mGenerator;
MonoAudioFileWriter mOutput1;
MonoAudioFileWriter mOutput2;
Controller mController;
// NodeTmpl<Audio,CircularStreamImpl<TData> > mInputNode;
// NodeTmpl<Audio,CircularStreamImpl<TData> > mOutputNode1;
// NodeTmpl<Audio,CircularStreamImpl<TData> > mOutputNode2;
void SendControls(int controls);
bool TestConstruction();
bool TestConfiguration();
bool TestExecution();
bool TestDestruction();
public:
EnvelopeExtractorTest();
bool Do();
};
EnvelopeExtractorTest::EnvelopeExtractorTest()
: mDataLength(100000),
mSampleRate(48000),
mFrameSize(512),
mIterations(100)
{
WaveGeneratorConfig wcfg;
wcfg.SetSampleRate(mSampleRate);
wcfg.SetFrequency(50.0);
mGenerator.Configure(wcfg);
Audio proto;
proto.SetSampleRate(mSampleRate);
MonoAudioFileWriterConfig fcfg;
fcfg.SetSampleRate(mSampleRate);
fcfg.SetTargetFile("test1.wav");
mOutput1.Configure(fcfg);
fcfg.SetTargetFile("test2.wav");
mOutput2.Configure(fcfg);
}
bool EnvelopeExtractorTest::TestConstruction()
{
EnvExtractorConfig cfg;
// You should add more constructions here,
// using different configuration parameters, or
// other constructors the class may provide.
mpExtractor1 = new EnvelopeExtractor();
mpExtractor2 = new EnvelopeExtractor(cfg);
mpGenerator1 = new EnvelopeGenerator();
mpGenerator2 = new EnvelopeGenerator();
return true;
}
bool EnvelopeExtractorTest::TestConfiguration()
{
EnvExtractorConfig cfg,cfg2;
cfg.GetInterpolationPeriod().SetInitValue(2.5);
cfg.GetIntegrationLength().SetInitValue(5.0);
cfg.GetNormalLevel().SetInitValue(2.0);
cfg.SetFrameSize(mFrameSize);
cfg.SetSampleRate(mSampleRate);
cfg.SetInterpolationType(EInterpolation::eSpline);
cfg2 = cfg;
mpExtractor1->Configure(cfg);
mpExtractor2->Configure(cfg);
mpExtractor1->Configure(cfg2);
mpExtractor2->Configure(cfg2);
EnvelopeGeneratorConfig ecfg1,ecfg2;
ecfg1.SetDuration(1.0);
ecfg1.SetFrameEnvelopes(true);
ecfg1.SetSampleRate(mSampleRate);
mpGenerator1->Configure(ecfg1);
ecfg2 = ecfg1;
mpGenerator2->Configure(ecfg2);
return true;
}
void EnvelopeExtractorTest::SendControls(int controls)
{
if (controls & 0x1) {
TData interpolation_period = double(rand())/double(RAND_MAX);
mpExtractor1->cInterpolationPeriod.DoControl(interpolation_period);
mpExtractor2->cInterpolationPeriod.DoControl(interpolation_period);
}
if (controls & 0x2) {
TData integration_length = double(rand())/double(RAND_MAX);
mpExtractor1->cIntegrationLength.DoControl(integration_length);
mpExtractor2->cIntegrationLength.DoControl(integration_length);
integration_length = integration_length + 10.0;
}
if (controls & 0x4) {
TData normal_level = double(rand())/double(RAND_MAX);
mpExtractor1->cNormalLevel.DoControl(normal_level);
mpExtractor2->cNormalLevel.DoControl(normal_level);
}
if (controls & 0x8) {
TData silence_level = double(rand())/double(RAND_MAX);
mpExtractor1->cSilenceLevel.DoControl(silence_level);
mpExtractor2->cSilenceLevel.DoControl(silence_level);
}
}
bool EnvelopeExtractorTest::TestExecution()
{
Envelope envelope1,envelope2;
ConnectPorts(mGenerator, 0, *mpExtractor1, 0);
ConnectPorts(mGenerator, 0, *mpExtractor2, 0);
ConnectPorts(*mpExtractor1, 0, *mpGenerator1, 0);
ConnectPorts(*mpExtractor2, 0, *mpGenerator2, 0);
ConnectPorts(*mpGenerator1, 0, mOutput1, 0);
ConnectPorts(*mpGenerator2, 0, mOutput2, 0);
// mInputNode.Configure(5*mFrameSize);
// mOutputNode1.Configure(5*mFrameSize);
// mOutputNode2.Configure(5*mFrameSize);
mGenerator.Start();
mpExtractor1->Start();
mpExtractor2->Start();
mpGenerator1->Start();
mpGenerator2->Start();
mOutput1.Start();
mOutput2.Start();
for (int i=0; i<mIterations; i++)
{
mGenerator.Do();
mpExtractor1->Do();
mpExtractor2->Do();
mpGenerator1->Do();
mpGenerator2->Do();
mOutput1.Do();
mOutput2.Do();
if ( (i & 0x7) == 0x7)
SendControls(int(4.0*rand()/(RAND_MAX+1.0)));
}
mGenerator.Stop();
mpExtractor1->Stop();
mpExtractor2->Stop();
mpGenerator1->Stop();
mpGenerator2->Stop();
mOutput1.Stop();
mOutput2.Stop();
return true;
}
bool EnvelopeExtractorTest::TestDestruction()
{
delete mpExtractor1;
delete mpExtractor2;
return true;
}
bool EnvelopeExtractorTest::Do()
{
bool res, ok = true;
res = TestConstruction();
if (!res) {
std::cerr << "Construction failed." << std::endl;
ok = false;
}
res = TestConfiguration();
if (!res) {
std::cerr << "Configuration failed." << std::endl;
ok = false;
}
res = TestExecution();
if (!res) {
std::cerr << "Execution failed." << std::endl;
ok = false;
}
res = TestDestruction();
if (!res) {
std::cerr << "Destruction failed." << std::endl;
ok = false;
}
return ok;
}
}
// main() return values:
// 0: Test sucessful.
// non-zero: Test Failed.
int main()
{
try {
CLAMTest::EnvelopeExtractorTest test;
bool result = test.Do();
if (result==false) {
std::cerr << "Failed." << std::endl;
return 1;
}
}
catch (std::exception &e) {
std::cerr << "ERROR: Excepton: " << e.what() << std::endl
<< "Failed." << std::endl;
return 1;
}
std::cerr << "Passed." << std::endl;
return 0;
}
|