UnitTest.h File Reference

Go to the source code of this file.

Defines

#define TEST_HEADER
#define TEST_ERROR_HEADER
#define SUCCESS   " SUCCESS!"

Functions

void Buffer_UnitTest ()
void BufferResample_UnitTest ()
void DelayLine_UnitTest ()
void FFTransform_UnitTest ()
void FilterBandPassFIR_UnitTest ()
void FilterBandPassIIR_UnitTest ()
void FilterBandRejectFIR_UnitTest ()
void FilterBandRejectIIR_UnitTest ()
void FilterCombLowPassFeedback_UnitTest ()
void FilterDelay_UnitTest ()
void FilterHighPassFIR_UnitTest ()
void FilterHighPassIIR_UnitTest ()
void FilterLeastSquaresFIR_UnitTest ()
void FilterLowPassFIR_UnitTest ()
void FilterLowPassIIR_UnitTest ()
void FilterParametricEqualizer_UnitTest ()
void Generator_UnitTest ()
void Sine_UnitTest ()
void Triangle_UnitTest ()
void Wavefile_UnitTest ()

Define Documentation

#define TEST_HEADER
Value:
endl << THIS_FILE << ":"; cout.width(4); cout << __LINE__ \
    << ": "; cout.width(0); cout

Definition at line 34 of file UnitTest.h.

#define TEST_ERROR_HEADER
Value:
" FAILURE!" << endl << THIS_FILE << ":"; cerr.width(4); cerr << __LINE__ \
    << ": ***Error!  "; cerr.width(0); cerr

Definition at line 38 of file UnitTest.h.

#define SUCCESS   " SUCCESS!"

Function Documentation

void Buffer_UnitTest (  ) 

Definition at line 48 of file Buffer_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Buffer::cbegin(), Nsound::Generator::drawLine(), GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getAbs(), Nsound::Buffer::getLength(), Nsound::Buffer::getMax(), Nsound::Buffer::getMin(), Nsound::Buffer::plot(), Nsound::Buffer::circular_iterator::reset(), Nsound::Buffer::reverse(), Nsound::Buffer::smooth(), Nsound::Buffer::subbuffer(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, testBufferAdd(), and THIS_FILE.

Referenced by main().

00049 {
00050     cout << endl << THIS_FILE;
00051 
00052     Wavefile::setDefaultSampleSize(48);
00053 
00055     cout << TEST_HEADER << "Testing Buffer::operator<<(float64) ...";
00056 
00057     Buffer b1(29);
00058 
00059     for(float64 i = 0.0; i < 100.0; i += 1.1)
00060     {
00061         b1 << i;
00062     }
00063 
00064     uint32 index = 0;
00065     for(float64 i = 0.0; i < 100.0; i += 1.1)
00066     {
00067         if( ::fabs(b1[index++] - i) > GAMMA)
00068         {
00069             cerr << TEST_ERROR_HEADER
00070                  << "Output did not match expected values!"
00071                  << endl;
00072 
00073             exit(1);
00074         }
00075     }
00076 
00077     cout << SUCCESS;
00078 
00080     cout << TEST_HEADER << "Testing Buffer::Buffer(const Buffer &) ...";
00081 
00082     Buffer b2(b1);
00083 
00084     if(b1 != b2 || b2 != b1)
00085     {
00086         cerr << TEST_ERROR_HEADER
00087              << "Output did not match expected values!"
00088              << endl;
00089 
00090         Buffer diff(b1 - b2);
00091         diff.plot("data - gold");
00092         b1.plot("b1");
00093         b2.plot("b2");
00094 
00095         Plotter::show();
00096 
00097         exit(1);
00098     }
00099 
00100     cout << SUCCESS;
00101 
00103     cout << TEST_HEADER << "Testing Buffer::operator=(const Buffer &) ...";
00104 
00105     Buffer b3;
00106 
00107     b3 = b1;
00108 
00109     if(b3 != b1 || b1 != b3)
00110     {
00111         cerr << TEST_ERROR_HEADER
00112              << "Output did not match expected values!"
00113              << endl;
00114 
00115         Buffer diff(b3 - b1);
00116         diff.plot("data - gold");
00117         b3.plot("b3");
00118         b1.plot("b1");
00119 
00120         Plotter::show();
00121 
00122         exit(1);
00123     }
00124 
00125     cout << SUCCESS;
00126 
00128     cout << TEST_HEADER << "Testing Buffer::operator<<(const Buffer &) ...";
00129 
00130     Buffer b4(b3);
00131 
00132     b4 << b1;
00133     b3 << b1;
00134 
00135     if(!(b4 == b3) || !(b3 == b4))
00136     {
00137         cerr << TEST_ERROR_HEADER
00138              << "Output did not match expected values!"
00139              << endl;
00140 
00141         Buffer diff(b4 - b3);
00142         diff.plot("data - gold");
00143         b4.plot("b4");
00144         b3.plot("b3");
00145 
00146         Plotter::show();
00147 
00148         exit(1);
00149     }
00150 
00151     cout << SUCCESS;
00152 
00154     cout << TEST_HEADER << "Testing Buffer::operator[](uint32) ...";
00155 
00156     uint32 size = b4.getLength();
00157 
00158     for(uint32 i = 0; i < size; ++i)
00159     {
00160         if(::fabs(b4[i] - b3[i]) > GAMMA)
00161         {
00162             cerr << TEST_ERROR_HEADER
00163                  << "Output did not match expected values!"
00164                  << endl;
00165 
00166             Buffer diff(b4 - b3);
00167             diff.plot("data - gold");
00168             b4.plot("b4");
00169             b3.plot("b3");
00170 
00171             Plotter::show();
00172 
00173             exit(1);
00174         }
00175     }
00176 
00177     cout << SUCCESS;
00178 
00180     cout << TEST_HEADER << "Testing Buffer::operator+,-,*,/ ...";
00181 
00182     b4 = b3;
00183 
00184     if(1 + b4 * 2 != 2 * b3 + 1)
00185     {
00186         cerr << TEST_ERROR_HEADER
00187              << "Output did not match expected values!"
00188              << endl;
00189 
00190         exit(1);
00191     }
00192 
00193     if(1 - b4 / 2 != -1 * b3 / 2 + 1)
00194     {
00195         cerr << TEST_ERROR_HEADER
00196              << "Output did not match expected values!"
00197              << endl;
00198 
00199         exit(1);
00200     }
00201 
00202     if(2.0 / b4 != 4.0 * (0.5 / b4))
00203     {
00204         cerr << TEST_ERROR_HEADER
00205              << "Output did not match expected values!"
00206              << endl;
00207 
00208         exit(1);
00209     }
00210 
00211     b3 = -1.0 * b4;
00212 
00213     b4 += b3;
00214 
00215     uint32 n_samples = b4.getLength();
00216     for(uint32 i = 0; i < n_samples; ++i)
00217     {
00218         if(b4[i] != 0.0)
00219         {
00220             cerr << TEST_ERROR_HEADER
00221                  << "b4 += b3 _SHOULD_ be all zeros!"
00222                  << endl;
00223             exit(1);
00224         }
00225     }
00226 
00227     cout << SUCCESS;
00228 
00230     cout << TEST_HEADER << "Testing Buffer::abs() ...";
00231 
00232     b4 = Buffer();
00233 
00234     if(b4.getLength() != 0)
00235     {
00236         cerr << TEST_ERROR_HEADER
00237              << "b4.getLength() != 0"
00238              << endl;
00239         exit(1);
00240     }
00241 
00242     float64 neg = -1.0;
00243     float64 sum = 1.0;
00244     for(uint32 i = 0; i < 100; ++i)
00245     {
00246         sum *= neg;
00247         b4 << sum;
00248     }
00249 
00250     b4.abs();
00251 
00252     float64 m = b4.getMin();
00253     if(m < 0.0)
00254     {
00255         cerr << TEST_ERROR_HEADER
00256              << "b4.abs() is broken"
00257              << endl;
00258         exit(1);
00259     }
00260 
00261     cout << SUCCESS;
00262 
00264     cout << TEST_HEADER << "Testing Buffer::reverse() ...";
00265 
00266     b4 = Buffer();
00267 
00268     if(b4.getLength() != 0)
00269     {
00270         cerr << TEST_ERROR_HEADER
00271              << "b4.getLength() != 0"
00272              << endl;
00273         exit(1);
00274     }
00275 
00276     for(float64 f = 0.0; f < 100.0; f += 1.0)
00277     {
00278         b4 << f;
00279     }
00280 
00281     b4.reverse();
00282 
00283     index = 0;
00284     for(float64 f = 99.0; f >= 0.0; f -= 1.0)
00285     {
00286         if(::fabs(b4[index++] - f) > GAMMA)
00287         {
00288             cerr << TEST_ERROR_HEADER
00289                  << "b4.reverse() borken"
00290                  << endl;
00291 
00292             b4.plot("b4");
00293 
00294             Plotter::show();
00295             exit(1);
00296         }
00297     }
00298 
00299     cout << SUCCESS;
00300 
00302     cout << TEST_HEADER << "Testing Buffer::subbuffer() ...";
00303 
00304     b3 = Buffer();
00305 
00306     uint32 chunk = 100;
00307 
00308     for(uint32 i = 0; i < chunk * 2 + 1; ++i)
00309     {
00310         b3 << i;
00311     }
00312 
00313     uint32 test_size = 99;
00314 
00315     Buffer subbuf = b3.subbuffer(0, test_size);
00316 
00317     if (subbuf.getLength() != test_size)
00318     {
00319         cerr << TEST_ERROR_HEADER
00320              << "subbuf.getLength() = "
00321              << subbuf.getLength()
00322              << " != "
00323              << test_size
00324              << endl;
00325         exit(1);
00326     }
00327 
00328     test_size = chunk;
00329 
00330     subbuf = b3.subbuffer(0,test_size);
00331 
00332     if (subbuf.getLength() != test_size)
00333     {
00334         cerr << TEST_ERROR_HEADER
00335              << "subbuf.getLength() = "
00336              << subbuf.getLength()
00337              << " != "
00338              << test_size
00339              << endl;
00340         exit(1);
00341     }
00342 
00343     test_size = b3.getLength() + 1;
00344 
00345     subbuf = b3.subbuffer(0, test_size);
00346 
00347     if (subbuf.getLength() != b3.getLength())
00348     {
00349         cerr << TEST_ERROR_HEADER
00350              << "subbuf.getLength() = "
00351              << subbuf.getLength()
00352              << " != "
00353              << b3.getLength()
00354              << endl;
00355         exit(1);
00356     }
00357 
00358     test_size = chunk + 10;
00359 
00360     for(uint32 i = 0; i < 10; ++i)
00361     {
00362         subbuf = b3.subbuffer(i, test_size);
00363 
00364         if (subbuf.getLength() != test_size)
00365         {
00366             cerr << TEST_ERROR_HEADER
00367                  << "subbuf.getLength() = "
00368                  << subbuf.getLength()
00369                  << " != "
00370                  << test_size
00371                  << endl;
00372             exit(1);
00373         }
00374     }
00375 
00376     subbuf = b3.subbuffer(0,10);
00377 
00378     for(uint32 i = 0; i < 10; ++i)
00379     {
00380         if(static_cast<uint32>(subbuf[i]) != i)
00381         {
00382             cerr << TEST_ERROR_HEADER
00383                  << "b3.subbuffer() error!"
00384                  << endl;
00385             exit(1);
00386         }
00387     }
00388 
00389     // Try with offset
00390 
00391     subbuf = b3.subbuffer(3,3);
00392 
00393     for(uint32 i = 0; i < 3; ++i)
00394     {
00395         if(static_cast<uint32>(subbuf[i]) != i + 3)
00396         {
00397             cerr << TEST_ERROR_HEADER
00398                  << "b3.subbuffer() error!"
00399                  << endl;
00400             exit(1);
00401         }
00402     }
00403 
00404     // Try using default value for n_samples
00405 
00406     subbuf = b3.subbuffer(3);
00407 
00408     if(subbuf.getLength() != b3.getLength() - 3)
00409     {
00410         cerr << TEST_ERROR_HEADER
00411              << "subbuf.getLength() = "
00412              << subbuf.getLength()
00413              << " != "
00414              << b3.getLength() - 3
00415              << endl;
00416         exit(1);
00417     }
00418 
00419     // Try using default value for n_samples
00420 
00421     subbuf = b3.subbuffer(0);
00422 
00423     if(subbuf.getLength() != b3.getLength())
00424     {
00425         cerr << TEST_ERROR_HEADER
00426              << "subbuf.getLength() _SHOULD_ be 10, found "
00427              << subbuf.getLength()
00428              << endl;
00429         exit(1);
00430     }
00431 
00432     for(uint32 i = 0; i < 10; ++i)
00433     {
00434         if(static_cast<uint32>(subbuf[i]) != i)
00435         {
00436             cerr << TEST_ERROR_HEADER
00437                  << "b3.subbuffer() error!"
00438                  << endl;
00439             exit(1);
00440         }
00441     }
00442 
00443     subbuf = b3.subbuffer(5,5);
00444 
00445     if(subbuf.getLength() != 5)
00446     {
00447         cerr << TEST_ERROR_HEADER
00448              << "subbuf.getLength() = "
00449              << subbuf.getLength()
00450              << " != 5"
00451              << endl;
00452         exit(1);
00453     }
00454 
00455     for(uint32 i = 0; i < 5; ++i)
00456     {
00457         if(static_cast<uint32>(subbuf[i]) != i + 5)
00458         {
00459             cerr << TEST_ERROR_HEADER
00460                  << "subbuf["
00461                  << i
00462                  << "] = "
00463                  << subbuf[i]
00464                  << " != "
00465                  << i + 5
00466                  << endl;
00467             exit(1);
00468         }
00469     }
00470 
00471     cout << SUCCESS;
00472 
00474     cout << TEST_HEADER << "Testing Buffer::smooth() ...";
00475 
00476     Sine sine(100);
00477 
00478     b4 << "gold/Filter_noise.wav";
00479 
00480     uint32 b4_length = b4.getLength();
00481     float64 b4_max = b4.getMax();
00482 
00483     b4.smooth(1, 16);
00484 
00485     if(b4.getLength() != b4_length)
00486     {
00487         cerr << TEST_ERROR_HEADER
00488              << "b4.smooth() error!"
00489              << endl;
00490         exit(1);
00491     }
00492 
00493     if(b4.getMax() > b4_max)
00494     {
00495         cerr << TEST_ERROR_HEADER
00496              << "b4.smooth() error!"
00497              << endl;
00498         exit(1);
00499     }
00500 
00501     cout << SUCCESS;
00502 
00504     cout << TEST_HEADER << "Testing Buffer::pow() ...";
00505 
00506     b4 = 2 * Buffer::ones(5);
00507 
00508     b4 ^= 2.0;
00509 
00510     for(uint32 i = 0; i < 5; ++i)
00511     {
00512         if(b4[i] != 4.0)
00513         {
00514             cerr << TEST_ERROR_HEADER
00515                  << "Buffer::pow() error!"
00516                  << "  4.0 != " << b4[i]
00517                  << endl;
00518             exit(1);
00519         }
00520     }
00521 
00522     b4 ^= 0.50;
00523 
00524     for(uint32 i = 0; i < 5; ++i)
00525     {
00526         if(b4[i] != 2.0)
00527         {
00528             cerr << TEST_ERROR_HEADER
00529                  << "Buffer::pow() error!"
00530                  << "  2.0 != " << b4[i]
00531                  << endl;
00532             exit(1);
00533         }
00534     }
00535 
00536     b4 = (b4 ^ 2.0) + (b4 ^ 2.0);
00537 
00538     for(uint32 i = 0; i < 5; ++i)
00539     {
00540         if(b4[i] != 8.0)
00541         {
00542             cerr << TEST_ERROR_HEADER
00543                  << "Buffer::pow() error!"
00544                  << "  8.0 != " << b4[i]
00545                  << endl;
00546             exit(1);
00547         }
00548     }
00549 
00550     cout << SUCCESS;
00551 
00553     cout << TEST_HEADER << "Testing Buffer operators with different length ...";
00554 
00555     Buffer b5(100);
00556     b5 = sine.drawLine(1.0, 2.0, 2.0);
00557 
00558     Buffer b6(100);
00559     b6 = sine.drawLine(2.0, 3.0, 3.0);
00560 
00561     Buffer result = b5 * b6;
00562 
00563     if(result.getLength() != b5.getLength())
00564     {
00565         cerr << TEST_ERROR_HEADER
00566              << "result.getLength() != b5.getLength(), "
00567              << result.getLength()
00568              << " != "
00569              << b5.getLength()
00570              << endl;
00571         exit(1);
00572     }
00573 
00574     for(uint32 i = 0; i < result.getLength(); ++i)
00575     {
00576         if(result[i] != 6.0)
00577         {
00578             cerr << TEST_ERROR_HEADER
00579                  << "result["
00580                  << i
00581                  << "] != 6.0"
00582                  << endl;
00583             exit(1);
00584         }
00585     }
00586 
00587     result = b6 * b5;
00588 
00589     if(result.getLength() != b6.getLength())
00590     {
00591         cerr << TEST_ERROR_HEADER
00592              << "result.getLength() != b6.getLength(), "
00593              << result.getLength()
00594              << " != "
00595              << b6.getLength()
00596              << endl;
00597         exit(1);
00598     }
00599 
00600     for(uint32 i = 0; i < b5.getLength(); ++i)
00601     {
00602         if(result[i] != 6.0)
00603         {
00604             cerr << TEST_ERROR_HEADER
00605                  << "result["
00606                  << i
00607                  << "] != 6.0"
00608                  << endl;
00609             exit(1);
00610         }
00611     }
00612 
00613     for(uint32 i = b5.getLength(); i < result.getLength(); ++i)
00614     {
00615         if(result[i] != 3.0)
00616         {
00617             cerr << TEST_ERROR_HEADER
00618                  << "result["
00619                  << i
00620                  << "] != 3.0"
00621                  << endl;
00622             exit(1);
00623         }
00624     }
00625 
00626     cout << SUCCESS;
00627 
00629     cout << TEST_HEADER << "Testing Buffer::add() ...";
00630 
00631     testBufferAdd();
00632 
00633     cout << SUCCESS;
00634 
00636     cout << TEST_HEADER << "Testing Buffer::circular_iterator ...";
00637 
00638     b5 = sine.drawLine(1.0, 1.0, 100.0);
00639 
00640     Buffer::circular_iterator itor = b5.cbegin();
00641 
00642     for(uint32 i = 0; i < b5.getLength(); ++i)
00643     {
00644         ++itor;
00645     }
00646 
00647     if(itor != b5.cbegin())
00648     {
00649         cerr << TEST_ERROR_HEADER
00650              << "circular_iterator::operator++ is broken!"
00651              << endl;
00652         exit(1);
00653     }
00654 
00655     itor.reset();
00656 
00657     for(uint32 i = 0; i < b5.getLength(); ++i)
00658     {
00659         --itor;
00660     }
00661 
00662     if(itor != b5.cbegin())
00663     {
00664         cerr << TEST_ERROR_HEADER
00665              << "circular_iterator::operator-- is broken!"
00666              << endl;
00667         exit(1);
00668     }
00669 
00670     itor.reset();
00671 
00672     for(uint32 i = 0; i < 3; ++i)
00673     {
00674         ++itor;
00675     }
00676 
00677     if(itor != (b5.cbegin() + 3))
00678     {
00679         cerr << TEST_ERROR_HEADER
00680              << "circular_iterator::operator++ is broken!"
00681              << endl;
00682         exit(1);
00683     }
00684 
00685     itor.reset();
00686 
00687     for(uint32 i = 0; i < 3; ++i)
00688     {
00689         --itor;
00690     }
00691 
00692     if(itor != (b5.cbegin() - 3))
00693     {
00694         cerr << TEST_ERROR_HEADER
00695              << "circular_iterator::operator-- is broken!"
00696              << endl;
00697         exit(1);
00698     }
00699 
00700     cout << SUCCESS;
00701 
00703     cout << TEST_HEADER << "Testing Buffer advanced operators ...";
00704 
00705     Buffer b7 = sine.generate(1.0, 2.0);
00706 
00707     Buffer data = b7;
00708 
00709     data(data > 0.5) = 0.5;
00710     data(data < -0.5) = -0.5;
00711 
00712 //~    // Create gold file
00713 //~    data >> "gold/Buffer_out1.wav";
00714 
00715     // Read in gold
00716     Buffer gold("gold/Buffer_out1.wav");
00717 
00718     Buffer diff(gold - data);
00719 
00720     if(diff.getAbs().getMax() > GAMMA)
00721     {
00722         cerr << TEST_ERROR_HEADER
00723              << "Output did not match expected values!"
00724              << endl;
00725 
00726         diff.plot("gold - data");
00727         data.plot("data");
00728         gold.plot("gold");
00729 
00730         Plotter::show();
00731 
00732         exit(1);
00733     }
00734 
00735     data = b7;
00736 
00737     BooleanVector bv1 = data > 0.5;
00738     BooleanVector bv2 = data < -0.5;
00739 
00740     data(bv1) *= 0.1;
00741     data(bv2) *= 0.1;
00742 
00743     data(bv1) += 0.45;
00744     data(bv2) -= 0.45;
00745 
00746 //~    // Create gold file
00747 //~    data >> "gold/Buffer_out2.wav";
00748 
00749     // Read in gold
00750     gold = Buffer("gold/Buffer_out2.wav");
00751 
00752     diff = gold - data;
00753 
00754     if(diff.getAbs().getMax() > GAMMA)
00755     {
00756         cerr << TEST_ERROR_HEADER
00757              << "Output did not match expected values!"
00758              << endl;
00759 
00760         diff.plot("gold - data");
00761         data.plot("data");
00762         gold.plot("gold");
00763 
00764         Plotter::show();
00765 
00766         exit(1);
00767     }
00768 
00769     cout << SUCCESS << endl;
00770 }

void BufferResample_UnitTest (  ) 

Definition at line 52 of file BufferResample_UnitTest.cc.

References GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getAbs(), Nsound::Buffer::getLength(), Nsound::Buffer::getMax(), Nsound::Buffer::getResample(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00053 {
00054     cout << endl << THIS_FILE;
00055 
00056     Wavefile::setDefaultSampleSize(64);
00057     Wavefile::setIEEEFloat(true);
00058 
00059     static const uint32 LM[4] = { 2,3,5,7 };
00060 
00061     Sine   sin(150);
00062 
00063     Buffer input = sin.generate(1.0, 3.0);
00064 
00065     cout << TEST_HEADER << "Testing Buffer:getResample(L,M) ...";
00066 
00067     Buffer data;
00068     Buffer gold;
00069     Buffer diff;
00070 
00071     std::stringstream ss;
00072 
00073     for(uint32 i  = 1; i <= 4; ++i)
00074     {
00075 
00076         std::string gold_filename;
00077 
00078         ss.str("");
00079         ss << "gold/BufferResample_out_" << i << "_" << LM[i-1] << ".wav";
00080 
00081         data = input.getResample(i, LM[i-1]);
00082 
00083         // Create gold file
00084 //~        data >> ss.str().c_str();
00085 
00086         gold = Buffer(ss.str().c_str());
00087 
00088         diff = data - gold;
00089 
00090         if(gold.getLength() != data.getLength() ||
00091            diff.getAbs().getMax() > GAMMA)
00092         {
00093             cerr << TEST_ERROR_HEADER
00094                  << "Output did not match gold file!"
00095                  << endl;
00096 
00097             diff.plot("data - gold");
00098             data.plot("data");
00099             gold.plot("gold");
00100 
00101             Plotter::show();
00102 
00103             exit(1);
00104         }
00105 
00106         // Reverse L & M
00107         ss.str("");
00108         ss << "gold/BufferResample_out_" << LM[i-1] << "_" << i << ".wav";
00109 
00110         data = input.getResample(LM[i-1], i);
00111 
00112         // Create gold file
00113 //~        data >> ss.str().c_str();
00114 
00115         gold = Buffer(ss.str().c_str());
00116 
00117         diff = data - gold;
00118 
00119         if(gold.getLength() != data.getLength() ||
00120            diff.getAbs().getMax() > GAMMA)
00121         {
00122             cerr << TEST_ERROR_HEADER
00123                  << "Output did not match gold file!"
00124                  << endl;
00125 
00126             diff.plot("data - gold");
00127             data.plot("data");
00128             gold.plot("gold");
00129 
00130             Plotter::show();
00131 
00132             exit(1);
00133         }
00134 
00135     }
00136 
00137     cout << SUCCESS << endl;
00138 }

void DelayLine_UnitTest (  ) 

Definition at line 52 of file DelayLine_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getMax(), Nsound::Buffer::plot(), Nsound::DelayLine::read(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, THIS_FILE, and Nsound::DelayLine::write().

Referenced by main().

00053 {
00054     cout << endl << THIS_FILE;
00055 
00056     Wavefile::setDefaultSampleSize(64);
00057     Wavefile::setIEEEFloat(true);
00058 
00059     DelayLine dl(1.0, 10.0);
00060     Sine sine(100.0);
00061 
00062     Buffer input;
00063     Buffer data;
00064     Buffer gold;
00065     Buffer diff;
00066 
00068     cout << TEST_HEADER << "Testing DelayLine::write() & read() ...";
00069 
00070     input = sine.generate(1.0, 2.0) * sine.drawLine(1.0, 1.0, 0.0);
00071 
00072     for(uint32 i = 0; i < 100; ++i)
00073     {
00074         dl.write(input[i]);
00075         data << dl.read();
00076     }
00077 
00078     // Create Gold files
00079 //~    data >> "gold/DelayLine_out1.wav";
00080 
00081     gold = Buffer("gold/DelayLine_out1.wav");
00082 
00083     diff = data - gold;
00084     diff.abs();
00085 
00086     if(diff.getMax() > GAMMA)
00087     {
00088         cerr << TEST_ERROR_HEADER
00089              << "Output did not match gold file!"
00090              << endl;
00091 
00092         diff.plot("data - gold");
00093         data.plot("data");
00094         gold.plot("gold");
00095 
00096         Plotter::show();
00097 
00098         exit(1);
00099     }
00100 
00101     cout << SUCCESS << endl;
00102 }

void FFTransform_UnitTest (  ) 

Definition at line 53 of file FFTransform_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::buzz(), Nsound::FFTransform::fft(), GAMMA, Nsound::Buffer::getAbs(), Nsound::FFTChunk::getImaginary(), Nsound::Buffer::getLength(), Nsound::Buffer::getMax(), Nsound::FFTChunk::getReal(), Nsound::FFTransform::ifft(), Nsound::Buffer::plot(), Nsound::FFTChunk::setCartesian(), Nsound::FFTChunk::setPolar(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00054 {
00055     cout << endl << THIS_FILE;
00056 
00057     Wavefile::setDefaultSampleSize(64);
00058     Wavefile::setIEEEFloat(true);
00059 
00060     Cosine cos(512);
00061 
00062     Buffer input = cos.buzz(1.0, 8.0, 2.0, 0.0);
00063 
00064     FFTransform fft(512);
00065 
00066     FFTChunkVector vec;
00067 
00068     Buffer gold;
00069 
00071     cout << TEST_HEADER << "Testing FFTransform::fft(), ifft() ..." << flush;
00072 
00073     vec = fft.fft(input, 128, 0);
00074 
00075     if(vec.size() != 512 / 128)
00076     {
00077         cerr << TEST_ERROR_HEADER
00078              << "Output did not match!"
00079              << endl
00080              << "vec.size() = " << vec.size() << " != " << 512 / 128
00081              << endl;
00082 
00083         exit(1);
00084     }
00085 
00086     Buffer data = fft.ifft(vec);
00087 
00088 //~    input.plot("input");
00089 //~    data.plot("fft,ifft");
00090 
00091     if(data.getLength() != input.getLength())
00092     {
00093         cerr << TEST_ERROR_HEADER
00094              << "Output did not match!"
00095              << endl
00096              << "result.getLength() = " << data.getLength() << " != "
00097              << input.getLength()
00098              << endl;
00099 
00100         exit(1);
00101     }
00102 
00103     // Create gold file
00104 //~    data >> "gold/FFTransform_out1.wav";
00105 
00106     gold = Buffer("gold/FFTransform_out1.wav");
00107 
00108     Buffer diff = data - gold;
00109 
00110     if(diff.getAbs().getMax() > GAMMA)
00111     {
00112         cerr << TEST_ERROR_HEADER
00113              << "Output did not match gold file!"
00114              << endl;
00115 
00116         diff.plot("input - gold");
00117         data.plot("data");
00118         gold.plot("gold");
00119 
00120         Plotter::show();
00121         exit(1);
00122     }
00123 
00124     cout << SUCCESS;
00125 
00127     cout << TEST_HEADER << "Testing FFTChunk::getReal(), getImaginary() ..." << flush;
00128 
00129     vec = fft.fft(input, 128, 0);
00130 
00131     Buffer real = vec[0].getReal();
00132     Buffer img  = vec[0].getImaginary();
00133 
00134     // Create gold files.
00135 //~    real >> "gold/FFTransform_out2.wav";
00136 //~    img  >> "gold/FFTransform_out3.wav";
00137 
00138     gold = Buffer("gold/FFTransform_out2.wav");
00139 
00140     diff = real - gold;
00141     diff.abs();
00142     if(diff.getMax() > GAMMA)
00143     {
00144         cerr << TEST_ERROR_HEADER
00145              << "Output did not match gold file!"
00146              << endl;
00147 
00148         diff.plot("real - gold");
00149         real.plot("real");
00150         gold.plot("gold");
00151 
00152         Plotter::show();
00153         exit(1);
00154     }
00155 
00156     gold = Buffer("gold/FFTransform_out3.wav");
00157 
00158     diff = img - gold;
00159     diff.abs();
00160 
00161     if(diff.getMax() > GAMMA)
00162     {
00163         cerr << TEST_ERROR_HEADER
00164              << "Output did not match gold file!"
00165              << endl;
00166 
00167         diff.plot("img - gold");
00168         img.plot("img");
00169         gold.plot("gold");
00170 
00171         Plotter::show();
00172         exit(1);
00173     }
00174 
00175     cout << SUCCESS;
00176 
00178     cout << TEST_HEADER << "Testing FFTChunk::getMagnitude(), getPhase() ..." << flush;
00179 
00180     vec = fft.fft(input, 128, 0);
00181 
00182     Buffer mag   = vec[0].getMagnitude();
00183     Buffer phase = vec[0].getPhase();
00184 
00185     // Create gold files.
00186 //~    mag >> "gold/FFTransform_out4.wav";
00187 //~    phase >> "gold/FFTransform_out5.wav";
00188 
00189     gold = Buffer("gold/FFTransform_out4.wav");
00190 
00191     diff = mag - gold;
00192 
00193     if(diff.getAbs().getMax() > GAMMA)
00194     {
00195         cerr << TEST_ERROR_HEADER
00196              << "Output did not match gold file!"
00197              << endl;
00198 
00199         diff.plot("data - gold");
00200         mag.plot("data");
00201         gold.plot("gold");
00202 
00203         Plotter::show();
00204         exit(1);
00205     }
00206 
00207     gold = Buffer("gold/FFTransform_out5.wav");
00208 
00209     diff = phase - gold;
00210 
00211     diff(diff > 2.0 * M_PI - 0.01) = 0.0;
00212     diff(diff < 2.0 * M_PI - 0.01) = 0.0;
00213 
00214     if(diff.getAbs().getMax() > GAMMA)
00215     {
00216         cerr << TEST_ERROR_HEADER
00217              << "Output did not match gold file!"
00218              << endl;
00219 
00220         diff.plot("phase - gold");
00221         phase.plot("phase");
00222         gold.plot("gold");
00223 
00224         Plotter::show();
00225         exit(1);
00226     }
00227 
00228     cout << SUCCESS;
00229 
00231     cout << TEST_HEADER << "Testing FFTChunk::toCartesian(), toPolar() ..." << flush;
00232 
00233     vec[0].toPolar();
00234 
00235     mag   = vec[0].getMagnitude();
00236     phase = vec[0].getPhase();
00237 
00238     gold = Buffer("gold/FFTransform_out4.wav");
00239 
00240     diff = mag - gold;
00241 
00242     if(diff.getAbs().getMax() > GAMMA)
00243     {
00244         cerr << TEST_ERROR_HEADER
00245              << "Output did not match gold file!"
00246              << endl;
00247 
00248         diff.plot("data - gold");
00249         mag.plot("data");
00250         gold.plot("gold");
00251 
00252         Plotter::show();
00253         exit(1);
00254     }
00255 
00256     gold = Buffer("gold/FFTransform_out5.wav");
00257 
00258     diff = phase - gold;
00259     diff.abs();
00260     if(diff.getMax() > 2*M_PI)
00261     {
00262         cerr << TEST_ERROR_HEADER
00263              << "Output did not match gold file!"
00264              << endl;
00265 
00266         diff.plot("phase - gold");
00267         phase.plot("phase");
00268         gold.plot("gold");
00269 
00270         Plotter::show();
00271         exit(1);
00272     }
00273 
00274     cout << SUCCESS;
00275 
00277     cout << TEST_HEADER << "Testing FFTChunk::setCartesian(), setPolar() ..." << flush;
00278 
00279     vec = fft.fft(input, 512, 0);
00280 
00281     mag = vec[0].getMagnitude();
00282     phase = vec[0].getPhase();
00283 
00284     FFTChunk orig(vec[0]);
00285     FFTChunk chunk(512, 512);
00286 
00287     chunk.setPolar(mag, phase);
00288 
00289     vec[0] = chunk;
00290 
00291     data = fft.ifft(vec);
00292 
00293     diff = data - input;
00294 
00295     if(diff.getAbs().getMax() > 0.005)
00296     {
00297         cerr << TEST_ERROR_HEADER
00298              << "Output did not match gold file!"
00299              << endl;
00300 
00301         diff.plot("data - gold");
00302         data.plot("data");
00303         input.plot("gold");
00304 
00305         Plotter::show();
00306         exit(1);
00307     }
00308 
00309     chunk.setCartesian(orig.getReal(), orig.getImaginary());
00310 
00311     vec[0] = chunk;
00312 
00313     data = fft.ifft(vec);
00314 
00315     diff = data - input;
00316 
00317     if(diff.getAbs().getMax() > 2*GAMMA)
00318     {
00319         cerr << TEST_ERROR_HEADER
00320              << "Output did not match gold file!"
00321              << endl;
00322 
00323         diff.plot("data - gold");
00324         data.plot("data");
00325         input.plot("gold");
00326 
00327         Plotter::show();
00328         exit(1);
00329     }
00330 
00331     cout << SUCCESS;
00332 
00334     cout << TEST_HEADER << "Testing FFTChunk::getFrequencyAxis() ..." << flush;
00335 
00336     data = vec[0].getFrequencyAxis();
00337 
00338 //~    // Create gold files.
00339 //~    data >> "gold/FFTransform_out6.wav";
00340 
00341     gold = Buffer("gold/FFTransform_out6.wav");
00342 
00343     diff = data - gold;
00344 
00345     if(diff.getAbs().getMax() > 1e-16)
00346     {
00347         cerr << TEST_ERROR_HEADER
00348              << "Output did not match gold file!"
00349              << endl;
00350 
00351         diff.plot("data - gold");
00352         data.plot("data");
00353         gold.plot("gold");
00354 
00355         Plotter::show();
00356         exit(1);
00357     }
00358 
00359     cout << SUCCESS << endl;
00360 }

void FilterBandPassFIR_UnitTest (  ) 

Definition at line 51 of file FilterBandPassFIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterBandPassFIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterBandPassFIR f(100.0, 64, 15.0, 20.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterBandPassFIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076     data.normalize();
00077 
00078     // Create the gold file
00079 //~    data >> "gold/FilterBandPassFIR_out1.wav";
00080 
00081     Buffer gold("gold/FilterBandPassFIR_out1.wav");
00082 
00083     Buffer diff = data - gold;
00084 
00085     if(diff.getAbs().getMax() > GAMMA)
00086     {
00087         cerr << TEST_ERROR_HEADER
00088              << "Output did not match gold file!"
00089              << endl;
00090 
00091         diff.plot("data - gold");
00092         data.plot("data");
00093         gold.plot("gold");
00094 
00095         Plotter::show();
00096 
00097         exit(1);
00098     }
00099 
00100     cout << SUCCESS;
00101 
00103     cout << TEST_HEADER << "Testing FilterBandPassFIR::filter(input, freqs, freqs) ...";
00104 
00105     Buffer freqs_low  = sine.drawLine(1.0, 6.0,  50.0);
00106     Buffer freqs_high = sine.drawLine(1.0, 12.0, 50.0);
00107 
00108     data = f.filter(0.9 * noise, freqs_low, freqs_high);
00109     data.normalize();
00110 
00111     // Create the gold file
00112 //~    data >> "gold/FilterBandPassFIR_out2.wav";
00113 
00114     gold = Buffer("gold/FilterBandPassFIR_out2.wav");
00115 
00116     diff = data - gold;
00117 
00118     if(diff.getAbs().getMax() > GAMMA)
00119     {
00120         cerr << TEST_ERROR_HEADER
00121              << "Output did not match gold file!"
00122              << endl;
00123 
00124         diff.plot("data - gold");
00125         data.plot("data");
00126         gold.plot("gold");
00127 
00128         Plotter::show();
00129 
00130         exit(1);
00131     }
00132 
00133     cout << SUCCESS;
00134 
00136     // Repeated to test that reset() is being called.
00137     cout << TEST_HEADER << "Testing FilterBandPassFIR::filter(input) ...";
00138 
00139     data = f.filter(noise);
00140     data.normalize();
00141 
00142     gold = Buffer("gold/FilterBandPassFIR_out1.wav");
00143 
00144     diff = data - gold;
00145 
00146     if(diff.getAbs().getMax() > GAMMA)
00147     {
00148         cerr << TEST_ERROR_HEADER
00149              << "Output did not match gold file!"
00150              << endl;
00151 
00152         diff.plot("data - gold");
00153         data.plot("data");
00154         gold.plot("gold");
00155 
00156         Plotter::show();
00157 
00158         exit(1);
00159     }
00160 
00161     cout << SUCCESS;
00162 
00164     // Repeated to test that reset() is being called.
00165     cout << TEST_HEADER << "Testing FilterBandPassFIR::filter(input, freqs, freqs) ...";
00166 
00167     data = f.filter(0.9 * noise, freqs_low, freqs_high);
00168     data.normalize();
00169 
00170     gold = Buffer("gold/FilterBandPassFIR_out2.wav");
00171 
00172     diff = data - gold;
00173 
00174     if(diff.getAbs().getMax() > GAMMA)
00175     {
00176         cerr << TEST_ERROR_HEADER
00177              << "Output did not match gold file!"
00178              << endl;
00179 
00180         diff.plot("data - gold");
00181         data.plot("data");
00182         gold.plot("gold");
00183 
00184         Plotter::show();
00185 
00186         exit(1);
00187     }
00188 
00189     cout << SUCCESS;
00190 
00192     cout << TEST_HEADER << "Testing FilterBandPassFIR::filter(input, f, f) ...";
00193 
00194     data = f.filter(noise, 15.0, 20.0);
00195     data.normalize();
00196 
00197     gold = Buffer("gold/FilterBandPassFIR_out1.wav");
00198 
00199     diff = data - gold;
00200 
00201     if(diff.getAbs().getMax() > GAMMA)
00202     {
00203         cerr << TEST_ERROR_HEADER
00204              << "Output did not match gold file!"
00205              << endl;
00206 
00207         diff.plot("data - gold");
00208         data.plot("data");
00209         gold.plot("gold");
00210 
00211         Plotter::show();
00212 
00213         exit(1);
00214     }
00215 
00216     cout << SUCCESS << endl;
00217 
00218 }

void FilterBandPassIIR_UnitTest (  ) 

Definition at line 51 of file FilterBandPassIIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterBandPassIIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterBandPassIIR f(100.0, 4, 15.0, 20.0, 0.01);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterBandPassIIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076     data.normalize();
00077 
00078     // Create the gold file
00079 //~    data >> "gold/FilterBandPassIIR_out1.wav";
00080 
00081     Buffer gold("gold/FilterBandPassIIR_out1.wav");
00082 
00083     Buffer diff = data - gold;
00084 
00085     if(diff.getAbs().getMax() > GAMMA)
00086     {
00087         cerr << TEST_ERROR_HEADER
00088              << "Output did not match gold file!"
00089              << endl;
00090 
00091         diff.plot("data - gold");
00092         data.plot("data");
00093         gold.plot("gold");
00094 
00095         Plotter::show();
00096 
00097         exit(1);
00098     }
00099 
00100     cout << SUCCESS;
00101 
00103     cout << TEST_HEADER << "Testing FilterBandPassIIR::filter(input, freqs, freqs) ...";
00104 
00105     Buffer freqs_low  = sine.drawLine(1.0, 6.0,  50.0);
00106     Buffer freqs_high = sine.drawLine(1.0, 12.0, 50.0);
00107 
00108     data = f.filter(noise, freqs_low, freqs_high);
00109     data.normalize();
00110 
00111     // Create the gold file
00112 //~    data >> "gold/FilterBandPassIIR_out2.wav";
00113 
00114     gold = Buffer("gold/FilterBandPassIIR_out2.wav");
00115 
00116     diff = data - gold;
00117 
00118     if(diff.getAbs().getMax() > GAMMA)
00119     {
00120         cerr << TEST_ERROR_HEADER
00121              << "Output did not match gold file!"
00122              << endl;
00123 
00124         diff.plot("data - gold");
00125         data.plot("data");
00126         gold.plot("gold");
00127 
00128         Plotter::show();
00129 
00130         exit(1);
00131     }
00132 
00133     cout << SUCCESS;
00134 
00136     // Repeat to test that reset() is being called.
00137     cout << TEST_HEADER << "Testing FilterBandPassIIR::filter(input) ...";
00138 
00139     data = f.filter(noise);
00140     data.normalize();
00141 
00142     gold = Buffer("gold/FilterBandPassIIR_out1.wav");
00143 
00144     diff = data - gold;
00145 
00146     if(diff.getAbs().getMax() > GAMMA)
00147     {
00148         cerr << TEST_ERROR_HEADER
00149              << "Output did not match gold file!"
00150              << endl;
00151 
00152         diff.plot("data - gold");
00153         data.plot("data");
00154         gold.plot("gold");
00155 
00156         Plotter::show();
00157 
00158         exit(1);
00159     }
00160 
00161     cout << SUCCESS;
00162 
00164     // Repeat to test that reset() is being called.
00165     cout << TEST_HEADER << "Testing FilterBandPassIIR::filter(input, freqs, freqs) ...";
00166 
00167     data = f.filter(noise, freqs_low, freqs_high);
00168     data.normalize();
00169 
00170     gold = Buffer("gold/FilterBandPassIIR_out2.wav");
00171 
00172     diff = data - gold;
00173 
00174     if(diff.getAbs().getMax() > GAMMA)
00175     {
00176         cerr << TEST_ERROR_HEADER
00177              << "Output did not match gold file!"
00178              << endl;
00179 
00180         diff.plot("data - gold");
00181         data.plot("data");
00182         gold.plot("gold");
00183 
00184         Plotter::show();
00185 
00186         exit(1);
00187     }
00188 
00189     cout << SUCCESS;
00190 
00192     cout << TEST_HEADER << "Testing FilterBandPassIIR::filter(input, f, f) ...";
00193 
00194     data = f.filter(noise, 15.0, 20.0);
00195     data.normalize();
00196 
00197     gold = Buffer("gold/FilterBandPassIIR_out1.wav");
00198 
00199     diff = data - gold;
00200 
00201     if(diff.getAbs().getMax() > GAMMA)
00202     {
00203         cerr << TEST_ERROR_HEADER
00204              << "Output did not match gold file!"
00205              << endl;
00206 
00207         diff.plot("data - gold");
00208         data.plot("data");
00209         gold.plot("gold");
00210 
00211         Plotter::show();
00212 
00213         exit(1);
00214     }
00215 
00216     cout << SUCCESS << endl;
00217 
00218 }

void FilterBandRejectFIR_UnitTest (  ) 

Definition at line 51 of file FilterBandRejectFIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterBandRejectFIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterBandRejectFIR f(100.0, 64, 15.0, 20.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterBandRejectFIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076     data.normalize();
00077 
00078     // Create the gold file
00079 //~    data >> "gold/FilterBandRejectFIR_out1.wav";
00080 
00081     Buffer gold;
00082 
00083     gold << "gold/FilterBandRejectFIR_out1.wav";
00084 
00085     Buffer diff = data - gold;
00086 
00087     if(diff.getAbs().getMax() > GAMMA)
00088     {
00089         cerr << TEST_ERROR_HEADER
00090              << "Output did not match gold file!"
00091              << endl;
00092 
00093         diff.plot("data - gold");
00094         data.plot("data");
00095         gold.plot("gold");
00096 
00097         Plotter::show();
00098 
00099         exit(1);
00100     }
00101 
00102     cout << SUCCESS;
00103 
00105     cout << TEST_HEADER << "Testing FilterBandRejectFIR::filter(input, freqs, freqs) ...";
00106 
00107     Buffer freqs_low  = sine.drawLine(1.0, 6.0,  50.0);
00108     Buffer freqs_high = sine.drawLine(1.0, 12.0, 50.0);
00109 
00110     data = f.filter(noise, freqs_low, freqs_high);
00111     data.normalize();
00112 
00113     // Create the gold file
00114 //~    data >> "gold/FilterBandRejectFIR_out2.wav";
00115 
00116     gold = Buffer();
00117 
00118     gold << "gold/FilterBandRejectFIR_out2.wav";
00119 
00120     diff = data - gold;
00121 
00122     if(diff.getAbs().getMax() > GAMMA)
00123     {
00124         cerr << TEST_ERROR_HEADER
00125              << "Output did not match gold file!"
00126              << endl;
00127 
00128         diff.plot("data - gold");
00129         data.plot("data");
00130         gold.plot("gold");
00131 
00132         Plotter::show();
00133 
00134         exit(1);
00135     }
00136 
00137     cout << SUCCESS;
00138 
00140     // Repeated to test that reset() is being called.
00141     cout << TEST_HEADER << "Testing FilterBandRejectFIR::filter(input) ...";
00142 
00143     data = f.filter(noise);
00144     data.normalize();
00145 
00146     gold = Buffer();
00147     gold << "gold/FilterBandRejectFIR_out1.wav";
00148 
00149     diff = data - gold;
00150 
00151     if(diff.getAbs().getMax() > GAMMA)
00152     {
00153         cerr << TEST_ERROR_HEADER
00154              << "Output did not match gold file!"
00155              << endl;
00156 
00157         diff.plot("data - gold");
00158         data.plot("data");
00159         gold.plot("gold");
00160 
00161         Plotter::show();
00162 
00163         exit(1);
00164     }
00165 
00166     cout << SUCCESS;
00167 
00169     // Repeated to test that reset() is being called.
00170     cout << TEST_HEADER << "Testing FilterBandRejectFIR::filter(input, freqs, freqs) ...";
00171 
00172     data = f.filter(noise, freqs_low, freqs_high);
00173     data.normalize();
00174 
00175     gold = Buffer();
00176     gold << "gold/FilterBandRejectFIR_out2.wav";
00177 
00178     diff = data - gold;
00179 
00180     if(diff.getAbs().getMax() > GAMMA)
00181     {
00182         cerr << TEST_ERROR_HEADER
00183              << "Output did not match gold file!"
00184              << endl;
00185 
00186         diff.plot("data - gold");
00187         data.plot("data");
00188         gold.plot("gold");
00189 
00190         Plotter::show();
00191 
00192         exit(1);
00193     }
00194 
00195     cout << SUCCESS;
00196 
00198     cout << TEST_HEADER << "Testing FilterBandRejectFIR::filter(input, f, f) ...";
00199 
00200     data = f.filter(noise, 15.0, 20.0);
00201     data.normalize();
00202 
00203     gold = Buffer("gold/FilterBandRejectFIR_out1.wav");
00204 
00205     diff = data - gold;
00206 
00207     if(diff.getAbs().getMax() > GAMMA)
00208     {
00209         cerr << TEST_ERROR_HEADER
00210              << "Output did not match gold file!"
00211              << endl;
00212 
00213         diff.plot("data - gold");
00214         data.plot("data");
00215         gold.plot("gold");
00216 
00217         Plotter::show();
00218 
00219         exit(1);
00220     }
00221 
00222     cout << SUCCESS << endl;
00223 
00224 }

void FilterBandRejectIIR_UnitTest (  ) 

Definition at line 51 of file FilterBandRejectIIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterBandRejectIIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterBandRejectIIR f(100.0, 4, 15.0, 20.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterBandRejectIIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076 
00077     data.normalize();
00078 
00079     // Create the gold file
00080 //~    data >> "gold/FilterBandRejectIIR_out1.wav";
00081 
00082     Buffer gold;
00083 
00084     gold << "gold/FilterBandRejectIIR_out1.wav";
00085 
00086     Buffer diff = data - gold;
00087 
00088     if(diff.getAbs().getMax() > GAMMA)
00089     {
00090         cerr << TEST_ERROR_HEADER
00091              << "Output did not match gold file!"
00092              << endl;
00093 
00094         diff.plot("data - gold");
00095         data.plot("data");
00096         gold.plot("gold");
00097 
00098         Plotter::show();
00099 
00100         exit(1);
00101     }
00102 
00103     cout << SUCCESS;
00104 
00106     cout << TEST_HEADER << "Testing FilterBandRejectIIR::filter(input, freqs, freqs) ...";
00107 
00108     Buffer freqs_low  = sine.drawLine(1.0, 6.0,  50.0);
00109     Buffer freqs_high = sine.drawLine(1.0, 12.0, 50.0);
00110 
00111     data = f.filter(noise, freqs_low, freqs_high);
00112     data.normalize();
00113 
00114     // Create the gold file
00115 //~    data >> "gold/FilterBandRejectIIR_out2.wav";
00116 
00117     gold = Buffer();
00118 
00119     gold << "gold/FilterBandRejectIIR_out2.wav";
00120 
00121     diff = data - gold;
00122 
00123     if(diff.getAbs().getMax() > GAMMA)
00124     {
00125         cerr << TEST_ERROR_HEADER
00126              << "Output did not match gold file!"
00127              << endl;
00128 
00129         diff.plot("data - gold");
00130         data.plot("data");
00131         gold.plot("gold");
00132 
00133         Plotter::show();
00134 
00135         exit(1);
00136     }
00137 
00138     cout << SUCCESS;
00139 
00141     // Repeat to test that reset() is being called
00142     cout << TEST_HEADER << "Testing FilterBandRejectIIR::filter(input) ...";
00143 
00144     data = f.filter(noise);
00145     data.normalize();
00146 
00147     gold = Buffer();
00148     gold << "gold/FilterBandRejectIIR_out1.wav";
00149 
00150     diff = data - gold;
00151 
00152     if(diff.getAbs().getMax() > GAMMA)
00153     {
00154         cerr << TEST_ERROR_HEADER
00155              << "Output did not match gold file!"
00156              << endl;
00157 
00158         diff.plot("data - gold");
00159         data.plot("data");
00160         gold.plot("gold");
00161 
00162         Plotter::show();
00163 
00164         exit(1);
00165     }
00166 
00167     cout << SUCCESS;
00168 
00170     // Repeat to test that reset() is being called
00171     cout << TEST_HEADER << "Testing FilterBandRejectIIR::filter(input, freqs, freqs) ...";
00172 
00173     data = f.filter(noise, freqs_low, freqs_high);
00174     data.normalize();
00175 
00176     gold = Buffer();
00177     gold << "gold/FilterBandRejectIIR_out2.wav";
00178 
00179     diff = data - gold;
00180 
00181     if(diff.getAbs().getMax() > GAMMA)
00182     {
00183         cerr << TEST_ERROR_HEADER
00184              << "Output did not match gold file!"
00185              << endl;
00186 
00187         diff.plot("data - gold");
00188         data.plot("data");
00189         gold.plot("gold");
00190 
00191         Plotter::show();
00192 
00193         exit(1);
00194     }
00195 
00196     cout << SUCCESS;
00197 
00199     cout << TEST_HEADER << "Testing FilterBandRejectIIR::filter(input, f, f) ...";
00200 
00201     data = f.filter(noise, 15.0, 20.0);
00202     data.normalize();
00203 
00204     gold = Buffer();
00205     gold << "gold/FilterBandRejectIIR_out1.wav";
00206 
00207     diff = data - gold;
00208 
00209     if(diff.getAbs().getMax() > GAMMA)
00210     {
00211         cerr << TEST_ERROR_HEADER
00212              << "Output did not match gold file!"
00213              << endl;
00214 
00215         diff.plot("data - gold");
00216         data.plot("data");
00217         gold.plot("gold");
00218 
00219         Plotter::show();
00220 
00221         exit(1);
00222     }
00223 
00224     cout << SUCCESS << endl;
00225 
00226 }

void FilterCombLowPassFeedback_UnitTest (  ) 

Definition at line 51 of file FilterCombLowPassFeedback_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), Nsound::FilterCombLowPassFeedback::filter(), GAMMA, Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterCombLowPassFeedback f(100.0, 0.1, 0.66, 12.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064     noise << "gold/Filter_noise.wav";
00065 
00067     cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input) ...";
00068 
00069     Buffer data;
00070 
00071     data = f.filter(noise);
00072     data.normalize();
00073 
00074     // Create the gold file
00075 //~    data >> "gold/FilterCombLowPassFeedback_out1.wav";
00076 
00077     Buffer gold;
00078 
00079     gold << "gold/FilterCombLowPassFeedback_out1.wav";
00080 
00081     Buffer diff = data - gold;
00082 
00083     Buffer abs_diff(diff);
00084     abs_diff.abs();
00085 
00086     if(abs_diff.getMax() > GAMMA)
00087     {
00088         cerr << TEST_ERROR_HEADER
00089              << "Output did not match gold file!"
00090              << endl;
00091 
00092         diff.plot("data - gold");
00093         data.plot("data");
00094         gold.plot("gold");
00095 
00096         Plotter::show();
00097 
00098         exit(1);
00099     }
00100 
00101     cout << SUCCESS;
00102 
00104     cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input, freqs) ...";
00105 
00106     Buffer freqs = sine.drawLine(1.0, 6.0, 50.0);
00107 
00108     data = f.filter(noise, freqs);
00109     data.normalize();
00110 
00111     // Create the gold file
00112 //~    data >> "gold/FilterCombLowPassFeedback_out2.wav";
00113 
00114     gold = Buffer();
00115 
00116     gold << "gold/FilterCombLowPassFeedback_out2.wav";
00117 
00118     diff = data - gold;
00119 
00120     abs_diff = diff;
00121     abs_diff.abs();
00122 
00123     if(abs_diff.getMax() > GAMMA)
00124     {
00125         cerr << TEST_ERROR_HEADER
00126              << "Output did not match gold file!"
00127              << endl;
00128 
00129         diff.plot("data - gold");
00130         data.plot("data");
00131         gold.plot("gold");
00132 
00133         Plotter::show();
00134 
00135         exit(1);
00136     }
00137 
00138 //~    cout << SUCCESS;
00139 
00140 
00141     cout << SUCCESS << endl;
00142 
00143 }

void FilterDelay_UnitTest (  ) 

Definition at line 52 of file FilterDelay_UnitTest.cc.

References Nsound::FilterDelay::filter(), GAMMA, Nsound::Generator::generate(), Nsound::AudioStream::getAbs(), Nsound::AudioStream::getMax(), Nsound::AudioStream::plot(), Nsound::Generator::silence(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00053 {
00054     cout << endl << THIS_FILE;
00055 
00056     Wavefile::setDefaultSampleSize(48);
00057 
00058     FilterDelay f(100.0, 3.0);
00059 
00060     Sine sine(100);
00061 
00062     AudioStream input(100, 1);
00063 
00064     input << sine.generate(0.25, 4.0)
00065           << sine.silence(0.75);
00066 
00068     cout << TEST_HEADER << "Testing FilterDelay::filter(input) ...";
00069 
00070     AudioStream data = f.filter(input, 0.333);
00071 
00072     // Create the gold file
00073 //~    data >> "gold/FilterDelay_out1.wav";
00074 
00075     AudioStream gold;
00076 
00077     gold << "gold/FilterDelay_out1.wav";
00078 
00079     AudioStream diff = data - gold;
00080 
00081     if(diff.getAbs().getMax() > GAMMA)
00082     {
00083         cerr << TEST_ERROR_HEADER
00084              << "Output did not match gold file!"
00085              << endl;
00086 
00087         diff.plot("data - gold");
00088         data.plot("data");
00089         gold.plot("gold");
00090 
00091         Plotter::show();
00092 
00093         exit(1);
00094     }
00095 
00097 
00098     data = f.filter(input, 0.666);
00099 
00100     // Create the gold file
00101 //~    data >> "gold/FilterDelay_out2.wav";
00102 
00103     gold = AudioStream("gold/FilterDelay_out2.wav");
00104 
00105     diff = data - gold;
00106 
00107     if(diff.getAbs().getMax() > GAMMA)
00108     {
00109         cerr << TEST_ERROR_HEADER
00110              << "Output did not match gold file!"
00111              << endl;
00112 
00113         diff.plot("data - gold");
00114         data.plot("data");
00115         gold.plot("gold");
00116 
00117         Plotter::show();
00118 
00119         exit(1);
00120     }
00121 
00123 
00124     FilterDelay f2(1.0, 5.0);
00125 
00126     input = AudioStream(1,1);
00127 
00128     input << 1.0 << 0.0 << 0.0 << 0.0 << 0.0
00129           << 0.0 << 0.0 << 0.0 << 0.0 << 0.0;
00130 
00131     data = f2.filter(input, 60.0);
00132 
00133     // Create the gold file
00134 //~    data >> "gold/FilterDelay_out3.wav";
00135 
00136     gold = AudioStream("gold/FilterDelay_out3.wav");
00137 
00138     diff = data - gold;
00139 
00140     if(diff.getAbs().getMax() > GAMMA)
00141     {
00142         cerr << TEST_ERROR_HEADER
00143              << "Output did not match gold file!"
00144              << endl;
00145 
00146         diff.plot("data - gold");
00147         data.plot("data");
00148         gold.plot("gold");
00149 
00150         Plotter::show();
00151 
00152         exit(1);
00153     }
00154 
00155 
00156     cout << SUCCESS << endl;
00157 }

void FilterHighPassFIR_UnitTest (  ) 

Definition at line 51 of file FilterHighPassFIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterHighPassFIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterHighPassFIR f(100.0, 16, 40.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064     // Create some noise.
00065 //~    noise = sine.whiteNoise(1.0);
00066 //~    noise >> "gold/Filter_noise.wav";
00067 
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterHighPassFIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076     data.normalize();
00077 
00078     // Create the gold file
00079 //~    data >> "gold/FilterHighPassFIR_out1.wav";
00080 
00081     Buffer gold("gold/FilterHighPassFIR_out1.wav");
00082 
00083     Buffer diff = data - gold;
00084 
00085     if(diff.getAbs().getMax() > GAMMA)
00086     {
00087         cerr << TEST_ERROR_HEADER
00088              << "Output did not match gold file!"
00089              << endl;
00090 
00091         diff.plot("data - gold");
00092         data.plot("data");
00093         gold.plot("gold/FilterHighPassFIR_out1.wav");
00094 
00095         Plotter::show();
00096 
00097         exit(1);
00098     }
00099 
00100     cout << SUCCESS;
00101 
00103     cout << TEST_HEADER << "Testing FilterHighPassFIR::filter(input, freqs) ...";
00104 
00105     Buffer freqs = sine.drawLine(1.0, 50.0, 6.0);
00106 
00107     data = f.filter(noise, freqs);
00108     data.normalize();
00109 
00110     // Create the gold file
00111 //~    data >> "gold/FilterHighPassFIR_out2.wav";
00112 
00113     gold = Buffer("gold/FilterHighPassFIR_out2.wav");
00114 
00115     diff = data - gold;
00116 
00117     if(diff.getAbs().getMax() > GAMMA)
00118     {
00119         cerr << TEST_ERROR_HEADER
00120              << "Output did not match gold file!"
00121              << endl;
00122 
00123         diff.plot("data - gold");
00124         data.plot("data");
00125         gold.plot("gold/FilterHighPassFIR_out2.wav");
00126 
00127         Plotter::show();
00128 
00129         exit(1);
00130     }
00131 
00132     cout << SUCCESS;
00133 
00135     // Repeated to test that reset() is being called.
00136     cout << TEST_HEADER << "Testing FilterHighPassFIR::filter(input) ...";
00137 
00138     data = f.filter(noise);
00139     data.normalize();
00140 
00141     gold = Buffer("gold/FilterHighPassFIR_out1.wav");
00142 
00143     diff = data - gold;
00144 
00145     if(diff.getAbs().getMax() > GAMMA)
00146     {
00147         cerr << TEST_ERROR_HEADER
00148              << "Output did not match gold file!"
00149              << endl;
00150 
00151         diff.plot("data - gold");
00152         data.plot("data");
00153         gold.plot("gold/FilterHighPassFIR_out1.wav");
00154 
00155         Plotter::show();
00156 
00157         exit(1);
00158     }
00159 
00160     cout << SUCCESS;
00161 
00163     // Repeated to test that reset() is being called.
00164     cout << TEST_HEADER << "Testing FilterHighPassFIR::filter(input, freqs) ...";
00165 
00166     data = f.filter(noise, freqs);
00167     data.normalize();
00168 
00169     gold = Buffer("gold/FilterHighPassFIR_out2.wav");
00170 
00171     diff = data - gold;
00172 
00173     if(diff.getAbs().getMax() > GAMMA)
00174     {
00175         cerr << TEST_ERROR_HEADER
00176              << "Output did not match gold file!"
00177              << endl;
00178 
00179         diff.plot("data - gold");
00180         data.plot("data");
00181         gold.plot("gold/FilterHighPassFIR_out2.wav");
00182 
00183         Plotter::show();
00184 
00185         exit(1);
00186     }
00187 
00188     cout << SUCCESS;
00189 
00191     cout << TEST_HEADER << "Testing FilterHighPassFIR::filter(input, f) ...";
00192 
00193     data = f.filter(noise, 40.0);
00194     data.normalize();
00195 
00196     // Create the gold file
00197 //~    data >> "gold/FilterHighPassFIR_out1.wav";
00198 
00199     gold = Buffer("gold/FilterHighPassFIR_out1.wav");
00200 
00201     diff = data - gold;
00202 
00203     if(diff.getAbs().getMax() > GAMMA)
00204     {
00205         cerr << TEST_ERROR_HEADER
00206              << "Output did not match gold file!"
00207              << endl;
00208 
00209         diff.plot("data - gold");
00210         data.plot("data");
00211         gold.plot("gold");
00212 
00213         Plotter::show();
00214 
00215         exit(1);
00216     }
00217 
00218     cout << SUCCESS << endl;
00219 
00220 }

void FilterHighPassIIR_UnitTest (  ) 

Definition at line 51 of file FilterHighPassIIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterHighPassIIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterHighPassIIR f(100.0, 4, 40.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064     // Create some noise.
00065 //~    noise = sine.whiteNoise(1.0);
00066 //~    noise >> "gold/Filter_noise.wav";
00067 
00068     noise << "gold/Filter_noise.wav";
00069 
00071     cout << TEST_HEADER << "Testing FilterHighPassIIR::filter(input) ...";
00072 
00073     Buffer data;
00074 
00075     data = f.filter(noise);
00076     data.normalize();
00077 
00078     // Create the gold file
00079 //~    data >> "gold/FilterHighPassIIR_out1.wav";
00080 
00081     Buffer gold("gold/FilterHighPassIIR_out1.wav");
00082 
00083     Buffer diff = data - gold;
00084 
00085     if(diff.getAbs().getMax() > GAMMA)
00086     {
00087         cerr << TEST_ERROR_HEADER
00088              << "Output did not match gold file!"
00089              << endl;
00090 
00091         diff.plot("data - gold");
00092         data.plot("data");
00093         gold.plot("gold/FilterHighPassIIR_out1.wav");
00094 
00095         Plotter::show();
00096 
00097         exit(1);
00098     }
00099 
00100     cout << SUCCESS;
00101 
00103     cout << TEST_HEADER << "Testing FilterHighPassIIR::filter(input, freqs) ...";
00104 
00105     Buffer freqs = sine.drawLine(1.0, 50.0, 6.0);
00106 
00107     data = f.filter(noise, freqs);
00108     data.normalize();
00109 
00110 
00111     // Create the gold file
00112 //~    data >> "gold/FilterHighPassIIR_out2.wav";
00113 
00114     gold = Buffer("gold/FilterHighPassIIR_out2.wav");
00115 
00116     diff = data - gold;
00117 
00118     if(diff.getAbs().getMax() > GAMMA)
00119     {
00120         cerr << TEST_ERROR_HEADER
00121              << "Output did not match gold file!"
00122              << endl;
00123 
00124         diff.plot("data - gold");
00125         data.plot("data");
00126         gold.plot("gold/FilterHighPassIIR_out2.wav");
00127 
00128         Plotter::show();
00129 
00130         exit(1);
00131     }
00132 
00133     cout << SUCCESS;
00134 
00136     // Repeat to test that reset() is being called.
00137     cout << TEST_HEADER << "Testing FilterHighPassIIR::filter(input) ...";
00138 
00139     data = f.filter(noise);
00140     data.normalize();
00141 
00142     gold = Buffer("gold/FilterHighPassIIR_out1.wav");
00143 
00144     diff = data - gold;
00145 
00146     if(diff.getAbs().getMax() > GAMMA)
00147     {
00148         cerr << TEST_ERROR_HEADER
00149              << "Output did not match gold file!"
00150              << endl;
00151 
00152         diff.plot("data - gold");
00153         data.plot("data");
00154         gold.plot("gold/FilterHighPassIIR_out1.wav");
00155 
00156         Plotter::show();
00157 
00158         exit(1);
00159     }
00160 
00161     cout << SUCCESS;
00162 
00164     // Repeat to test that reset() is being called.
00165     cout << TEST_HEADER << "Testing FilterHighPassIIR::filter(input, freqs) ...";
00166 
00167     data = f.filter(noise, freqs);
00168     data.normalize();
00169 
00170     gold = Buffer("gold/FilterHighPassIIR_out2.wav");
00171 
00172     diff = data - gold;
00173 
00174     if(diff.getAbs().getMax() > GAMMA)
00175     {
00176         cerr << TEST_ERROR_HEADER
00177              << "Output did not match gold file!"
00178              << endl;
00179 
00180         diff.plot("data - gold");
00181         data.plot("data");
00182         gold.plot("gold/FilterHighPassIIR_out2.wav");
00183 
00184         Plotter::show();
00185 
00186         exit(1);
00187     }
00188 
00189     cout << SUCCESS;
00190 
00192     cout << TEST_HEADER << "Testing FilterHighPassIIR::filter(input, f) ...";
00193 
00194     data = f.filter(noise, 40.0);
00195     data.normalize();
00196 
00197     gold = Buffer("gold/FilterHighPassIIR_out1.wav");
00198 
00199     diff = data - gold;
00200 
00201     if(diff.getAbs().getMax() > GAMMA)
00202     {
00203         cerr << TEST_ERROR_HEADER
00204              << "Output did not match gold file!"
00205              << endl;
00206 
00207         diff.plot("data - gold");
00208         data.plot("data");
00209         gold.plot("gold/FilterHighPassIIR_out1.wav");
00210 
00211         Plotter::show();
00212 
00213         exit(1);
00214     }
00215 
00216     cout << SUCCESS << endl;
00217 
00218 }

void FilterLeastSquaresFIR_UnitTest (  ) 

Definition at line 54 of file FilterLeastSquaresFIR_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::FilterLeastSquaresFIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getdB(), Nsound::Filter::getFrequencyResponse(), Nsound::Buffer::getMax(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::Buffer::plot(), Nsound::RECTANGULAR, Nsound::FilterLeastSquaresFIR::setWindow(), sr, SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00055 {
00056     cout << endl << THIS_FILE;
00057 
00058     Wavefile::setDefaultSampleSize(64);
00059     Wavefile::setIEEEFloat(true);
00060 
00061     float64 sr = 1000.0;
00062 
00063     // Create a low pass least squares FIR filter
00064 
00065     Buffer freqs;
00066     Buffer amplitude;
00067 
00068     freqs     << 0.0 << 100.0 << 100.0 << 500.0;
00069     amplitude << 1.0 << 1.0   << 0.0   << 0.0;
00070 
00071     FilterLeastSquaresFIR f(sr, 1025, freqs, amplitude);
00072 
00073     Buffer noise("gold/Filter_noise.wav");
00074 
00076     cout << TEST_HEADER << "Testing FilterLeastSquaresFIR::filter(input) ...";
00077 
00078     Buffer data;
00079 
00080     data  = f.filter(noise);
00081 
00082     // Create the gold file
00083     //~    data >> "gold/FilterLeastSquaresFIR_out1.wav";
00084 
00085     Buffer gold("gold/FilterLeastSquaresFIR_out1.wav");
00086 
00087     Buffer diff = data - gold;
00088 
00089     diff.abs();
00090 
00091     if(diff.getMax() > GAMMA)
00092     {
00093         cerr << TEST_ERROR_HEADER
00094              << "Output did not match gold file!"
00095              << endl
00096              << flush;
00097 
00098         diff.plot("data - gold");
00099         data.plot("data");
00100         gold.plot("gold");
00101 
00102         Plotter::show();
00103 
00104         exit(1);
00105     }
00106 
00107     cout << SUCCESS;
00108 
00110     // Repeated to test that reset() is being called.
00111     cout << TEST_HEADER << "Testing FilterLeastSquaresFIR::filter(input) ..."
00112          << flush;
00113 
00114     data = f.filter(noise);
00115 
00116     diff = data - gold;
00117     diff.abs();
00118 
00119     if(diff.getMax() > GAMMA)
00120     {
00121         cerr << TEST_ERROR_HEADER
00122              << "Output did not match gold file!"
00123              << endl;
00124 
00125         diff.plot("data - gold");
00126         data.plot("data");
00127         gold.plot("gold");
00128 
00129         Plotter::show();
00130 
00131         exit(1);
00132     }
00133 
00134     cout << SUCCESS;
00135 
00137     // Create a high pass least squares FIR filter
00138 
00139     freqs = Buffer(4);
00140     amplitude = Buffer(4);
00141 
00142     freqs     << 0.0 << 100.0 << 100.0 << 500.0;
00143     amplitude << 0.0 << 0.0   << 1.0   << 1.0;
00144 
00145     f.makeKernel(freqs, amplitude);
00146 
00148     cout << TEST_HEADER << "Testing FilterLeastSquaresFIR::filter(input) ...";
00149 
00150     data = f.filter(0.9 * noise);
00151 
00152     // Create the gold file
00153     //~    data >> "gold/FilterLeastSquaresFIR_out2.wav";
00154 
00155     gold = Buffer("gold/FilterLeastSquaresFIR_out2.wav");
00156 
00157     diff = data - gold;
00158     diff.abs();
00159 
00160     if(diff.getMax() > GAMMA)
00161     {
00162         cerr << TEST_ERROR_HEADER
00163              << "Output did not match gold file!"
00164              << endl;
00165 
00166         diff.plot("data - gold");
00167         data.plot("data");
00168         gold.plot("gold");
00169 
00170         Plotter::show();
00171 
00172         exit(1);
00173     }
00174 
00175     cout << SUCCESS;
00176 
00178     // Repeated to test that reset() is being called.
00179     cout << TEST_HEADER << "Testing FilterLeastSquaresFIR::filter(input) ...";
00180 
00181     data = f.filter(0.9 * noise);
00182 
00183     diff = data - gold;
00184     diff.abs();
00185 
00186     if(diff.getMax() > GAMMA)
00187     {
00188         cerr << TEST_ERROR_HEADER
00189              << "Output did not match gold file!"
00190              << endl;
00191 
00192         diff.plot("data - gold");
00193         data.plot("data");
00194         gold.plot("gold");
00195 
00196         Plotter::show();
00197 
00198         exit(1);
00199     }
00200 
00201     cout << SUCCESS;
00202 
00204     // Repeated to test that reset() is being called.
00205     cout << TEST_HEADER << "Testing FilterLeastSquaresFIR::setWindow() ...";
00206 
00207     freqs     = Buffer(4);
00208     amplitude = Buffer(4);
00209 
00210     freqs     << 0.0 << 30.0 << 30.0 << 500.0;
00211     amplitude << 1.0 << 1.0   << 0.0   << 0.0;
00212 
00213     f = FilterLeastSquaresFIR(sr, 32, freqs, amplitude);
00214 
00215     f.setWindow(RECTANGULAR);
00216 
00217     data = f.getFrequencyResponse().getdB();
00218 
00219 //~    // Create gold file
00220 //~    cout << "SAVING GOLD FILE: gold/FilterLeastSquaresFIR_out3.wav" << endl;
00221 //~    data >> "gold/FilterLeastSquaresFIR_out3.wav";
00222 
00223     gold = Buffer("gold/FilterLeastSquaresFIR_out3.wav");
00224 
00225     diff = data - gold;
00226 
00227     float64 max_diff = diff.getAbs().getMax();
00228 
00229     if(max_diff > 1e-9) // gamma is changed here
00230     {
00231         cerr << TEST_ERROR_HEADER
00232              << "Output did not match gold file!"
00233              << endl;
00234 
00235         diff.plot("data - gold");
00236         data.plot("data");
00237         gold.plot("gold");
00238 
00239         Plotter::show();
00240 
00241         exit(1);
00242     }
00243 
00244     cout << SUCCESS << endl;
00245 }

void FilterLowPassFIR_UnitTest (  ) 

Definition at line 51 of file FilterLowPassFIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterLowPassFIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterLowPassFIR f(1000.0, 64, 120.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068 
00070     cout << TEST_HEADER << "Testing FilterLowPassFIR::filter(input) ...";
00071 
00072     Buffer data;
00073 
00074     data = f.filter(noise);
00075 
00076     // Create the gold file
00077 //~    data >> "gold/FilterLowPassFIR_out1.wav";
00078 
00079     Buffer gold("gold/FilterLowPassFIR_out1.wav");
00080 
00081     Buffer diff = data - gold;
00082 
00083     if(diff.getAbs().getMax() > GAMMA)
00084     {
00085         cerr << TEST_ERROR_HEADER
00086              << "Output did not match gold file!"
00087              << endl;
00088 
00089         diff.plot("data - gold");
00090         data.plot("data");
00091         gold.plot("gold");
00092 
00093         Plotter::show();
00094 
00095         exit(1);
00096     }
00097 
00098     cout << SUCCESS;
00099 
00100 
00101 
00103     cout << TEST_HEADER << "Testing FilterLowPassFIR::filter(input, freqs) ...";
00104 
00105     Buffer freqs = sine.drawLine(1.0, 6.0, 50.0);
00106 
00107     data = f.filter(0.9 * noise, freqs);
00108 
00109     // Create the gold file
00110 //~    data >> "gold/FilterLowPassFIR_out2.wav";
00111 
00112     gold = Buffer("gold/FilterLowPassFIR_out2.wav");
00113 
00114     diff = data - gold;
00115 
00116     if(diff.getAbs().getMax() > GAMMA)
00117     {
00118         cerr << TEST_ERROR_HEADER
00119              << "Output did not match gold file!"
00120              << endl;
00121 
00122         diff.plot("data - gold");
00123         data.plot("data");
00124         gold.plot("gold");
00125 
00126         Plotter::show();
00127 
00128         exit(1);
00129     }
00130 
00131     cout << SUCCESS;
00132 
00134     // Repeated to test that reset() is being called.
00135     cout << TEST_HEADER << "Testing FilterLowPassFIR::filter(input) ...";
00136 
00137     data = f.filter(noise);
00138 
00139     gold = Buffer("gold/FilterLowPassFIR_out1.wav");
00140 
00141     diff = data - gold;
00142 
00143     if(diff.getAbs().getMax() > GAMMA)
00144     {
00145         cerr << TEST_ERROR_HEADER
00146              << "Output did not match gold file!"
00147              << endl;
00148 
00149         diff.plot("data - gold");
00150         data.plot("data");
00151         gold.plot("gold");
00152 
00153         Plotter::show();
00154 
00155         exit(1);
00156     }
00157 
00158     cout << SUCCESS;
00159 
00161     // Repeated to test that reset() is being called.
00162     cout << TEST_HEADER << "Testing FilterLowPassFIR::filter(input, freqs) ...";
00163 
00164     data = f.filter(0.9 * noise, freqs);
00165 
00166     gold = Buffer("gold/FilterLowPassFIR_out2.wav");
00167 
00168     diff = data - gold;
00169 
00170     if(diff.getAbs().getMax() > GAMMA)
00171     {
00172         cerr << TEST_ERROR_HEADER
00173              << "Output did not match gold file!"
00174              << endl;
00175 
00176         diff.plot("data - gold");
00177         data.plot("data");
00178         gold.plot("gold");
00179 
00180         Plotter::show();
00181 
00182         exit(1);
00183     }
00184 
00185     cout << SUCCESS;
00186 
00188     cout << TEST_HEADER << "Testing FilterLowPassFIR::filter(input, f) ...";
00189 
00190     data = f.filter(noise, 120.0);
00191 
00192     // Create the gold file
00193 //~    data >> "gold/FilterLowPassFIR_out1.wav";
00194 
00195     gold = Buffer("gold/FilterLowPassFIR_out1.wav");
00196 
00197     diff = data - gold;
00198 
00199     if(diff.getAbs().getMax() > GAMMA)
00200     {
00201         cerr << TEST_ERROR_HEADER
00202              << "Output did not match gold file!"
00203              << endl;
00204 
00205         diff.plot("data - gold");
00206         data.plot("data");
00207         gold.plot("gold");
00208 
00209         Plotter::show();
00210 
00211         exit(1);
00212     }
00213 
00214 
00215     cout << SUCCESS << endl;
00216 
00217 }

void FilterLowPassIIR_UnitTest (  ) 

Definition at line 51 of file FilterLowPassIIR_UnitTest.cc.

References Nsound::Generator::drawLine(), Nsound::FilterLowPassIIR::filter(), GAMMA, Nsound::Buffer::getAbs(), Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     FilterLowPassIIR f(1000.0, 4, 120.0);
00058 
00059     // Create some noise!
00060     Sine sine(100);
00061 
00062     Buffer noise;
00063 
00064 //~    noise = sine.whiteNoise(1.0);
00065 //~    noise >> "gold/Filter_noise.wav";
00066 
00067     noise << "gold/Filter_noise.wav";
00068 
00070     cout << TEST_HEADER << "Testing FilterLowPassIIR::filter(input) ...";
00071 
00072     Buffer data;
00073 
00074     data = f.filter(noise);
00075     data.normalize();
00076 
00077     // Create the gold file
00078 //~    data >> "gold/FilterLowPassIIR_out1.wav";
00079 
00080     Buffer gold("gold/FilterLowPassIIR_out1.wav");
00081 
00082     Buffer diff = data - gold;
00083 
00084     if(diff.getAbs().getMax() > GAMMA)
00085     {
00086         cerr << TEST_ERROR_HEADER
00087              << "Output did not match gold file!"
00088              << endl;
00089 
00090         diff.plot("data - gold");
00091         data.plot("data");
00092         gold.plot("gold");
00093 
00094         Plotter::show();
00095 
00096         exit(1);
00097     }
00098 
00099     cout << SUCCESS;
00100 
00102     cout << TEST_HEADER << "Testing FilterLowPassIIR::filter(input, freqs) ...";
00103 
00104     Buffer freqs = sine.drawLine(1.0, 6.0, 50.0);
00105 
00106     data = f.filter(noise, freqs);
00107     data.normalize();
00108 
00109     // Create the gold file
00110 //~    data >> "gold/FilterLowPassIIR_out2.wav";
00111 
00112     gold = Buffer("gold/FilterLowPassIIR_out2.wav");
00113 
00114     diff = data - gold;
00115 
00116     if(diff.getAbs().getMax() > GAMMA)
00117     {
00118         cerr << TEST_ERROR_HEADER
00119              << "Output did not match gold file!"
00120              << endl;
00121 
00122         diff.plot("data - gold");
00123         data.plot("data");
00124         gold.plot("gold");
00125 
00126         Plotter::show();
00127 
00128         exit(1);
00129     }
00130 
00131     cout << SUCCESS;
00132 
00134     // Repeat to test that reset() is being called.
00135     cout << TEST_HEADER << "Testing FilterLowPassIIR::filter(input) ...";
00136 
00137     data = f.filter(noise);
00138     data.normalize();
00139 
00140     gold = Buffer("gold/FilterLowPassIIR_out1.wav");
00141 
00142     diff = data - gold;
00143 
00144     if(diff.getAbs().getMax() > GAMMA)
00145     {
00146         cerr << TEST_ERROR_HEADER
00147              << "Output did not match gold file!"
00148              << endl;
00149 
00150         diff.plot("data - gold");
00151         data.plot("data");
00152         gold.plot("gold");
00153 
00154         Plotter::show();
00155 
00156         exit(1);
00157     }
00158 
00159     cout << SUCCESS;
00160 
00162     // Repeat to test that reset() is being called.
00163     cout << TEST_HEADER << "Testing FilterLowPassIIR::filter(input, freqs) ...";
00164 
00165     data = f.filter(noise, freqs);
00166     data.normalize();
00167 
00168     gold = Buffer("gold/FilterLowPassIIR_out2.wav");
00169 
00170     diff = data - gold;
00171 
00172     if(diff.getAbs().getMax() > GAMMA)
00173     {
00174         cerr << TEST_ERROR_HEADER
00175              << "Output did not match gold file!"
00176              << endl;
00177 
00178         diff.plot("data - gold");
00179         data.plot("data");
00180         gold.plot("gold");
00181 
00182         Plotter::show();
00183 
00184         exit(1);
00185     }
00186 
00187     cout << SUCCESS;
00188 
00190     cout << TEST_HEADER << "Testing FilterLowPassIIR::filter(input, f) ...";
00191 
00192     data = f.filter(noise, 120.0);
00193     data.normalize();
00194 
00195     gold = Buffer("gold/FilterLowPassIIR_out1.wav");
00196 
00197     diff = data - gold;
00198 
00199     if(diff.getAbs().getMax() > GAMMA)
00200     {
00201         cerr << TEST_ERROR_HEADER
00202              << "Output did not match gold file!"
00203              << endl;
00204 
00205         diff.plot("data - gold");
00206         data.plot("data");
00207         gold.plot("gold");
00208 
00209         Plotter::show();
00210 
00211         exit(1);
00212     }
00213 
00214     cout << SUCCESS << endl;
00215 }

void FilterParametricEqualizer_UnitTest (  ) 

Definition at line 52 of file FilterParametricEqualizer_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), Nsound::FilterParametricEqualizer::filter(), GAMMA, Nsound::Buffer::getMax(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00053 {
00054     cout << endl << THIS_FILE;
00055 
00056     Wavefile::setDefaultSampleSize(64);
00057     Wavefile::setIEEEFloat(true);
00058 
00059     Sine sine(100);
00060 
00061     FilterParametricEqualizer peaking(
00062         FilterParametricEqualizer::PEAKING,
00063         100,
00064         12,
00065         0.2,
00066         4.0);
00067 
00068     FilterParametricEqualizer low(
00069         FilterParametricEqualizer::LOW_SHELF,
00070         100,
00071         12,
00072         0.2,
00073         4.0);
00074 
00075     FilterParametricEqualizer high(
00076         FilterParametricEqualizer::HIGH_SHELF,
00077         100,
00078         12,
00079         0.2,
00080         4.0);
00081 
00082     Buffer freqs = sine.drawLine(5.0, 24, 6);
00083 
00084     static const std::string titles[3] =
00085     {
00086         "Testing Peaking filter ...",
00087         "Testing Low Shelf filter ...",
00088         "Testing High Shelf filter ..."
00089     };
00090 
00091     static const std::string types[3] =
00092     {
00093         "peaking",
00094         "low",
00095         "high"
00096     };
00097 
00098     static const std::string gold_filenames[3] =
00099     {
00100         "gold/FilterParametricEqualizer_out_peaking.wav",
00101         "gold/FilterParametricEqualizer_out_low.wav",
00102         "gold/FilterParametricEqualizer_out_high.wav"
00103     };
00104 
00105     FilterParametricEqualizer * filters[3] =
00106     {
00107         &peaking,
00108         &low,
00109         &high
00110     };
00111 
00112     Buffer noise;
00113     Buffer data;
00114     Buffer gold;
00115     Buffer diff;
00116 
00117     noise << "gold/Filter_noise.wav";
00118     noise << "gold/Filter_noise.wav";
00119 
00120     for(int i = 0; i < 3; ++i)
00121     {
00122         cout << TEST_HEADER << titles[i];
00123 
00124         data = filters[i]->filter(noise, freqs);
00125 
00126         // Create gold file
00127 //~        data >> gold_filenames[i].c_str();
00128 
00129         gold = Buffer(gold_filenames[i]);
00130 
00131         diff = data - gold;
00132         diff.abs();
00133 
00134         if(diff.getMax() > GAMMA)
00135         {
00136             cerr << TEST_ERROR_HEADER
00137                  << "Output did not match gold file!"
00138                  << endl;
00139 
00140             diff.plot("data - gold");
00141             data.plot("data");
00142             gold.plot("gold");
00143 
00144             Plotter::show();
00145 
00146             exit(1);
00147         }
00148 
00149         cout << SUCCESS;
00150 
00151     }
00152 
00153     cout << endl;
00154 }

void Generator_UnitTest (  ) 

Definition at line 52 of file Generator_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::buzz(), Nsound::Generator::drawLine(), Nsound::Generator::drawSine(), Nsound::Generator::drawSine2(), GAMMA, Nsound::Buffer::getMax(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00053 {
00054     cout << endl << THIS_FILE;
00055 
00056     Wavefile::setDefaultSampleSize(32);
00057     Wavefile::setIEEEFloat(true);
00058 
00059     Generator gen(100);
00060     Cosine cos(100);
00061 
00063     // Test 7 Hz wave
00064     cout << TEST_HEADER << "Testing Generator::drawLine(1.0, 1.0, 0.0) ...";
00065 
00066     Buffer data = gen.drawLine(1.0, 1.0, 0.0);
00067 
00068     // Create the gold file
00069 //~    data >> "gold/Generator_line1.wav";
00070 
00071     Buffer gold;
00072 
00073     gold << "gold/Generator_line1.wav";
00074 
00075     Buffer diff = data - gold;
00076 
00077     Buffer abs_diff(diff);
00078     abs_diff.abs();
00079 
00080     if(abs_diff.getMax() > GAMMA)
00081     {
00082         cerr << TEST_ERROR_HEADER
00083              << "Output did not match gold file!"
00084              << endl;
00085 
00086         data.plot("data");
00087         gold.plot("gold");
00088         diff.plot("data - gold");
00089         Plotter::show();
00090 
00091         exit(1);
00092     }
00093 
00094     cout << SUCCESS;
00095 
00097     // Test 3.5 Hz wave
00098     cout << TEST_HEADER << "Testing Generator::drawLine(1.26, -0.26, 0.26) ...";
00099 
00100     data = gen.drawLine(1.26, -0.26, 0.26);
00101 
00102     // Create the gold file
00103 //~    data >> "gold/Generator_line2.wav";
00104 
00105     gold = Buffer();
00106 
00107     gold << "gold/Generator_line2.wav";
00108 
00109     diff = data - gold;
00110 
00111     abs_diff = diff;
00112     abs_diff.abs();
00113 
00114     if(abs_diff.getMax() > GAMMA)
00115     {
00116         cerr << TEST_ERROR_HEADER
00117              << "Output did not match gold file!"
00118              << endl;
00119 
00120         data.plot("data");
00121         gold.plot("gold");
00122         diff.plot("data - gold");
00123         Plotter::show();
00124 
00125         exit(1);
00126     }
00127 
00128     cout << SUCCESS;
00129 
00130 
00132     // Test 3.5 Hz wave
00133     cout << TEST_HEADER << "Testing Generator::buzz(1.0, 4.0, 3, 0.0) ...";
00134 
00135     data = cos.buzz(1.0, 4.0, 3, 0.0);
00136 
00137     // Create the gold file
00138 //~    data >> "gold/Generator_buzz1.wav";
00139 
00140     gold = Buffer();
00141 
00142     gold << "gold/Generator_buzz1.wav";
00143 
00144     diff = data - gold;
00145 
00146     abs_diff = diff;
00147     abs_diff.abs();
00148 
00149     if(abs_diff.getMax() > GAMMA)
00150     {
00151         cerr << TEST_ERROR_HEADER
00152              << "Output did not match gold file!"
00153              << endl;
00154 
00155         data.plot("data");
00156         gold.plot("gold");
00157         diff.plot("data - gold");
00158         Plotter::show();
00159 
00160         exit(1);
00161     }
00162 
00163     cout << SUCCESS;
00164 
00165 
00167     // Test 3.5 Hz wave
00168     cout << TEST_HEADER << "Testing Generator::buzz(1.0, 4.0, 3, 0.5) ...";
00169 
00170     data = cos.buzz(1.0, 4.0, 3, 0.5);
00171 
00172     // Create the gold file
00173 //~    data >> "gold/Generator_buzz2.wav";
00174 
00175     gold = Buffer();
00176 
00177     gold << "gold/Generator_buzz2.wav";
00178 
00179     diff = data - gold;
00180 
00181     abs_diff = diff;
00182     abs_diff.abs();
00183 
00184     if(abs_diff.getMax() > GAMMA)
00185     {
00186         cerr << TEST_ERROR_HEADER
00187              << "Output did not match gold file!"
00188              << endl;
00189 
00190         data.plot("data");
00191         gold.plot("gold");
00192         diff.plot("data - gold");
00193         Plotter::show();
00194 
00195         exit(1);
00196     }
00197 
00198     cout << SUCCESS;
00199 
00201     // Test 3.5 Hz wave
00202     cout << TEST_HEADER << "Testing Generator::buzz(1.0, 4.0, 4, 0.5) ...";
00203 
00204     data = cos.buzz(1.0, 4.0, 4, 0.5);
00205 
00206     // Create the gold file
00207 //~    data >> "gold/Generator_buzz3.wav";
00208 
00209     gold = Buffer();
00210 
00211     gold << "gold/Generator_buzz3.wav";
00212 
00213     diff = data - gold;
00214 
00215     abs_diff = diff;
00216     abs_diff.abs();
00217 
00218     if(abs_diff.getMax() > GAMMA)
00219     {
00220         cerr << TEST_ERROR_HEADER
00221              << "Output did not match gold file!"
00222              << endl;
00223 
00224         data.plot("data");
00225         gold.plot("gold");
00226         diff.plot("data - gold");
00227         Plotter::show();
00228 
00229         exit(1);
00230     }
00231 
00232     cout << SUCCESS;
00233 
00235     // Test drawSine
00236     cout << TEST_HEADER << "Testing Generator::drawSine(1.0, 10.0) ...";
00237 
00238     gen = Generator(600.0);
00239 
00240     data = Buffer();
00241     data << gen.drawSine(1.0, 10.0);
00242 
00243     // Create the gold file
00244 //~    data >> "gold/Generator_sine1.wav";
00245 
00246     gold = Buffer("gold/Generator_sine1.wav");
00247 
00248     diff = data - gold;
00249 
00250     abs_diff = diff;
00251     abs_diff.abs();
00252 
00253     if(abs_diff.getMax() > GAMMA)
00254     {
00255         cerr << TEST_ERROR_HEADER
00256              << "Output did not match gold file!"
00257              << endl;
00258 
00259         data.plot("data");
00260         gold.plot("gold");
00261         diff.plot("data - gold");
00262         Plotter::show();
00263 
00264         exit(1);
00265     }
00266 
00267     cout << SUCCESS;
00268 
00270     // Test drawSine
00271     cout << TEST_HEADER << "Testing Generator::drawSine(1.0, freqs) ...";
00272 
00273     data = Buffer();
00274 
00275     Buffer freqs(gen.drawLine(1.0, 1.0, 10.0));
00276 
00277     data << gen.drawSine(1.0, freqs);
00278 
00279     // Create the gold file
00280 //~    data >> "gold/Generator_sine2.wav";
00281 
00282     gold = Buffer("gold/Generator_sine2.wav");
00283 
00284     diff = data - gold;
00285 
00286     abs_diff = diff;
00287     abs_diff.abs();
00288 
00289     if(abs_diff.getMax() > GAMMA)
00290     {
00291         cerr << TEST_ERROR_HEADER
00292              << "Output did not match gold file!"
00293              << endl;
00294 
00295         data.plot("data");
00296         gold.plot("gold");
00297         diff.plot("data - gold");
00298         Plotter::show();
00299 
00300         exit(1);
00301     }
00302 
00303     cout << SUCCESS;
00304 
00306     // Test drawSine
00307     cout << TEST_HEADER << "Testing Generator::drawSine2(1.0, 3.0, 0.5) ...";
00308 
00309     data = Buffer();
00310 
00311     data << gen.drawSine2(1.0, 3.0, 0.5);
00312 
00313     // Create the gold file
00314 //~    data >> "gold/Generator_sine3.wav";
00315 
00316     gold = Buffer("gold/Generator_sine3.wav");
00317 
00318     diff = data - gold;
00319 
00320     abs_diff = diff;
00321     abs_diff.abs();
00322 
00323     if(abs_diff.getMax() > GAMMA)
00324     {
00325         cerr << TEST_ERROR_HEADER
00326              << "Output did not match gold file!"
00327              << endl;
00328 
00329         data.plot("data");
00330         gold.plot("gold");
00331         diff.plot("data - gold");
00332         Plotter::show();
00333 
00334         exit(1);
00335     }
00336 
00337     cout << SUCCESS;
00338 
00340     // Test drawSine
00341     cout << TEST_HEADER << "Testing Generator::drawSine2(1.0, 3.0, phase) ...";
00342 
00343     data = Buffer();
00344 
00345     Buffer phase;
00346     phase << gen.drawLine(1.0, 0.0, 1.0);
00347 
00348     data << gen.drawSine2(1.0, 3.0, phase);
00349 
00350     // Create the gold file
00351 //~    data >> "gold/Generator_sine4.wav";
00352 
00353     gold = Buffer("gold/Generator_sine4.wav");
00354 
00355     diff = data - gold;
00356 
00357     abs_diff = diff;
00358     abs_diff.abs();
00359 
00360     if(abs_diff.getMax() > GAMMA)
00361     {
00362         cerr << TEST_ERROR_HEADER
00363              << "Output did not match gold file!"
00364              << endl;
00365 
00366         data.plot("data");
00367         gold.plot("gold");
00368         diff.plot("data - gold");
00369         Plotter::show();
00370 
00371         exit(1);
00372     }
00373 
00374     cout << SUCCESS;
00375 
00377     // Test drawSine
00378     cout << TEST_HEADER << "Testing Generator::drawSine2(1.0, freqs, 0.5) ...";
00379 
00380     data = Buffer();
00381     freqs = Buffer();
00382 
00383     freqs << gen.drawLine(1.0, 0.0, 10.0);
00384 
00385     data << gen.drawSine2(1.0, freqs, 0.5);
00386 
00387     // Create the gold file
00388 //~    data >> "gold/Generator_sine5.wav";
00389 
00390     gold = Buffer("gold/Generator_sine5.wav");
00391 
00392     diff = data - gold;
00393 
00394     abs_diff = diff;
00395     abs_diff.abs();
00396 
00397     if(abs_diff.getMax() > GAMMA)
00398     {
00399         cerr << TEST_ERROR_HEADER
00400              << "Output did not match gold file!"
00401              << endl;
00402 
00403         data.plot("data");
00404         gold.plot("gold");
00405         diff.plot("data - gold");
00406         Plotter::show();
00407 
00408         exit(1);
00409     }
00410 
00411     cout << SUCCESS;
00412 
00414     // Test drawSine
00415     cout << TEST_HEADER << "Testing Generator::drawSine2(1.0, freqs, phase) ...";
00416 
00417     data = Buffer();
00418 
00419     data << gen.drawSine2(1.0, freqs, phase);
00420 
00421     // Create the gold file
00422 //~    data >> "gold/Generator_sine6.wav";
00423 
00424     gold = Buffer("gold/Generator_sine6.wav");
00425 
00426     diff = data - gold;
00427 
00428     abs_diff = diff;
00429     abs_diff.abs();
00430 
00431     if(abs_diff.getMax() > GAMMA)
00432     {
00433         cerr << TEST_ERROR_HEADER
00434              << "Output did not match gold file!"
00435              << endl;
00436 
00437         data.plot("data");
00438         gold.plot("gold");
00439         diff.plot("data - gold");
00440         Plotter::show();
00441 
00442         exit(1);
00443     }
00444 
00445     cout << SUCCESS << endl;
00446 
00447     Plotter::show();
00448 }

void Sine_UnitTest (  ) 

Definition at line 51 of file Sine_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), GAMMA, Nsound::Generator::generate(), Nsound::Generator::generate2(), Nsound::Buffer::getMax(), Nsound::Buffer::plot(), Nsound::Generator::setChorus(), Nsound::Generator::setSeed(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(64);
00056     Wavefile::setIEEEFloat(true);
00057 
00058     Sine sine(600);
00059 
00060     Buffer freqs;
00061     Buffer phase;
00062 
00063     freqs << sine.drawLine(1.0, 0.0, 10.0);
00064     phase << sine.drawLine(1.0, 0.0, 1.0);
00065 
00067     cout << TEST_HEADER << "Testing Sine::generate(1.0, 3.0) ...";
00068 
00069     Buffer data = sine.generate(1.0, 3.0);
00070 
00071     // Create the gold file
00072 //~    data >> "gold/Sine_1.wav";
00073 
00074     Buffer gold;
00075 
00076     gold << "gold/Sine_1.wav";
00077 
00078     Buffer diff = data - gold;
00079 
00080     Buffer abs_diff(diff);
00081     abs_diff.abs();
00082 
00083     if(abs_diff.getMax() > GAMMA)
00084     {
00085         cerr << TEST_ERROR_HEADER
00086              << "Output did not match gold file!"
00087              << endl;
00088 
00089         diff.plot("data - gold");
00090         data.plot("data");
00091         gold.plot("gold");
00092 
00093         Plotter::show();
00094 
00095         exit(1);
00096     }
00097 
00098     cout << SUCCESS;
00099 
00101     // Test 3.5 Hz wave
00102     cout << TEST_HEADER << "Testing Sine::generate(1.0, freqs) ...";
00103 
00104     data = sine.generate(1.0, freqs);
00105 
00106     // Create the gold file
00107 //~    data >> "gold/Sine_2.wav";
00108 
00109     gold = Buffer();
00110 
00111     gold << "gold/Sine_2.wav";
00112 
00113     diff = data - gold;
00114 
00115     abs_diff = diff;
00116     abs_diff.abs();
00117 
00118     if(abs_diff.getMax() > GAMMA)
00119     {
00120         cerr << TEST_ERROR_HEADER
00121              << "Output did not match gold file!"
00122              << endl;
00123 
00124         diff.plot("data - gold");
00125         data.plot("data");
00126         gold.plot("gold");
00127 
00128         Plotter::show();
00129 
00130         exit(1);
00131     }
00132 
00133     cout << SUCCESS;
00134 
00136     // Test dynamic
00137     cout << TEST_HEADER << "Testing Sine::generate2(1.0, 3.0, 0.5) ...";
00138 
00139     data = sine.generate2(1.0, 3.0, 0.5);
00140 
00141     // Create the gold file
00142 //~    data >> "gold/Sine_3.wav";
00143 
00144     gold = Buffer();
00145 
00146     gold << "gold/Sine_3.wav";
00147 
00148     diff = data - gold;
00149 
00150     abs_diff = diff;
00151     abs_diff.abs();
00152 
00153     if(abs_diff.getMax() > GAMMA)
00154     {
00155         cerr << TEST_ERROR_HEADER
00156              << "Output did not match gold file!"
00157              << endl;
00158 
00159         diff.plot("data - gold");
00160         data.plot("data");
00161         gold.plot("gold");
00162 
00163         Plotter::show();
00164 
00165         exit(1);
00166     }
00167 
00168     cout << SUCCESS;
00169 
00171     // Test dynamic
00172     cout << TEST_HEADER << "Testing Sine::generate2(1.0, 3.0, phase) ...";
00173 
00174     data = sine.generate2(1.0, 3.0, phase);
00175 
00176     // Create the gold file
00177 //~    data >> "gold/Sine_4.wav";
00178 
00179     gold = Buffer();
00180 
00181     gold << "gold/Sine_4.wav";
00182 
00183     diff = data - gold;
00184 
00185     abs_diff = diff;
00186     abs_diff.abs();
00187 
00188     if(abs_diff.getMax() > GAMMA)
00189     {
00190         cerr << TEST_ERROR_HEADER
00191              << "Output did not match gold file!"
00192              << endl;
00193 
00194         diff.plot("data - gold");
00195         data.plot("data");
00196         gold.plot("gold");
00197 
00198         Plotter::show();
00199 
00200         exit(1);
00201     }
00202 
00203     cout << SUCCESS;
00204 
00206     // Test dynamic
00207     cout << TEST_HEADER << "Testing Sine::generate2(1.0, freqs, 0.5) ...";
00208 
00209     data = sine.generate2(1.0, freqs, 0.5);
00210 
00211     // Create the gold file
00212 //~    data >> "gold/Sine_5.wav";
00213 
00214     gold = Buffer();
00215 
00216     gold << "gold/Sine_5.wav";
00217 
00218     diff = data - gold;
00219 
00220     abs_diff = diff;
00221     abs_diff.abs();
00222 
00223     if(abs_diff.getMax() > GAMMA)
00224     {
00225         cerr << TEST_ERROR_HEADER
00226              << "Output did not match gold file!"
00227              << endl;
00228 
00229         diff.plot("data - gold");
00230         data.plot("data");
00231         gold.plot("gold");
00232 
00233         Plotter::show();
00234 
00235         exit(1);
00236     }
00237 
00238     cout << SUCCESS;
00239 
00241     // Test dynamic
00242     cout << TEST_HEADER << "Testing Sine::generate2(1.0, freqs, phase) ...";
00243 
00244     data = sine.generate2(1.0, freqs, phase);
00245 
00246     // Create the gold file
00247 //~    data >> "gold/Sine_6.wav";
00248 
00249     gold = Buffer();
00250 
00251     gold << "gold/Sine_6.wav";
00252 
00253     diff = data - gold;
00254 
00255     abs_diff = diff;
00256     abs_diff.abs();
00257 
00258     if(abs_diff.getMax() > GAMMA)
00259     {
00260         cerr << TEST_ERROR_HEADER
00261              << "Output did not match gold file!"
00262              << endl;
00263 
00264         diff.plot("data - gold");
00265         data.plot("data");
00266         gold.plot("gold");
00267 
00268         Plotter::show();
00269 
00270         exit(1);
00271     }
00272 
00273     cout << SUCCESS;
00274 
00276     // Test dynamic
00277     cout << TEST_HEADER << "Testing Sine::setChorus(5,0.10) ...";
00278 
00279     sine.setSeed(6846513); // Some random seed I typed in.
00280 
00281     sine.setChorus(5, 0.10);
00282 
00283     data = sine.generate2(1.0, 2*freqs, phase);
00284 
00285     // Create the gold file
00286 //~    data >> "gold/Sine_7.wav";
00287 
00288     gold = Buffer();
00289 
00290     gold << "gold/Sine_7.wav";
00291 
00292     diff = data - gold;
00293 
00294     abs_diff = diff;
00295     abs_diff.abs();
00296 
00297     if(abs_diff.getMax() > GAMMA)
00298     {
00299         cerr << TEST_ERROR_HEADER
00300              << "Output did not match gold file!"
00301              << endl;
00302 
00303         diff.plot("data - gold");
00304         data.plot("data");
00305         gold.plot("gold");
00306 
00307         Plotter::show();
00308 
00309         exit(1);
00310     }
00311 
00312     cout << SUCCESS << endl;
00313 }

void Triangle_UnitTest (  ) 

Definition at line 51 of file Triangle_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getMax(), Nsound::Buffer::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(64);
00056     Wavefile::setIEEEFloat(true);
00057 
00058     Triangle tri(100);
00059 
00060     Buffer data;
00061     Buffer gold;
00062     Buffer diff;
00063 
00065     // Test 7 Hz wave
00066     cout << TEST_HEADER << "Testing Triangle::generate(1.01, 2.0) ...";
00067 
00068     data = tri.generate(1.01, 2.0);
00069 
00070     // Create the gold file
00071 //~    data >> "gold/Triangle_2Hz.wav";
00072 
00073     gold = Buffer("gold/Triangle_2Hz.wav");
00074 
00075     diff = data - gold;
00076 
00077     diff.abs();
00078 
00079     if(diff.getMax() > GAMMA)
00080     {
00081         cerr << TEST_ERROR_HEADER
00082              << "Output did not match gold file!"
00083              << endl;
00084 
00085         diff.plot("data - gold");
00086         data.plot("data");
00087         gold.plot("gold");
00088 
00089         Plotter::show();
00090 
00091         exit(1);
00092     }
00093 
00094     cout << SUCCESS;
00095 
00097     // Test 3.5 Hz wave
00098     cout << TEST_HEADER << "Testing Triangle::generate(1.01, 1.0) ...";
00099 
00100     data = tri.generate(1.01, 1.0);
00101 
00102     // Create the gold file
00103 //~    data >> "gold/Triangle_1.0Hz.wav";
00104 
00105     gold = Buffer("gold/Triangle_1.0Hz.wav");
00106 
00107     diff = data - gold;
00108 
00109     diff.abs();
00110 
00111     if(diff.getMax() > GAMMA)
00112     {
00113         cerr << TEST_ERROR_HEADER
00114              << "Output did not match gold file!"
00115              << endl;
00116 
00117         diff.plot("data - gold");
00118         data.plot("data");
00119         gold.plot("gold");
00120 
00121         Plotter::show();
00122 
00123         exit(1);
00124     }
00125 
00126     cout << SUCCESS;
00127 
00129     // Test dynamic
00130     cout << TEST_HEADER << "Testing Triangle::generate(1.01, frequencies) ...";
00131 
00132     Buffer freqs = tri.drawLine(1.01, 1.0, 5.0);
00133 
00134     data = tri.generate(1.01, freqs);
00135 
00136     // Create the gold file
00137 //~    data >> "gold/Triangle_1_to_5Hz.wav";
00138 
00139     gold = Buffer("gold/Triangle_1_to_5Hz.wav");
00140 
00141     diff = data - gold;
00142 
00143     diff.abs();
00144 
00145     if(diff.getMax() > GAMMA)
00146     {
00147         cerr << TEST_ERROR_HEADER
00148              << "Output did not match gold file!"
00149              << endl;
00150 
00151         diff.plot("data - gold");
00152         data.plot("data");
00153         gold.plot("gold");
00154 
00155         Plotter::show();
00156 
00157         exit(1);
00158     }
00159 
00160     Plotter::show();
00161 
00162     cout << SUCCESS << endl;
00163 }

void Wavefile_UnitTest (  ) 

Definition at line 51 of file Wavefile_UnitTest.cc.

References Nsound::AudioStream::abs(), GAMMA, Nsound::Generator::generate(), Nsound::AudioStream::plot(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

00052 {
00053     cout << endl << THIS_FILE;
00054 
00055     Wavefile::setDefaultSampleSize(48);
00056 
00057     Sine sin(100);
00058 
00059     AudioStream data1(100, 3);
00060 
00061     data1 << sin.generate(1.0, 13.0);
00062 
00063     data1[1] *= 0.666666666666666;
00064     data1[2] *= 0.333333333333333;
00065 
00067     // Write out 10 channel 13 Hz wave.
00068     cout << TEST_HEADER << "Testing Wavefile::write(48-bit), read(48-bit) ..." << flush;
00069 
00070     data1 >> "test_wavefile.wav";
00071 
00072     AudioStream data(100, 3);
00073 
00074     data << "test_wavefile.wav";
00075 
00076     AudioStream gold(100, 3);
00077 
00078     // Create gold file
00079 //~    data >> "gold/Wavefile_out1.wav";
00080 
00081     gold << "gold/Wavefile_out1.wav";
00082 
00083     AudioStream diff = data - gold;
00084 
00085     AudioStream abs_diff(diff);
00086     abs_diff.abs();
00087 
00088     for(int32 i = 0; i < 3; ++i)
00089     {
00090         if(abs_diff[i].getMax() > GAMMA)
00091         {
00092             cerr << TEST_ERROR_HEADER
00093                  << "Output did not match gold file!"
00094                  << endl;
00095 
00096             diff[i].plot("data - gold");
00097             data[i].plot("data");
00098             gold[i].plot("gold");
00099 
00100             Plotter::show();
00101 
00102             exit(1);
00103         }
00104     }
00105 
00106     cout << SUCCESS;
00107 
00109     // Write out 10 channel 13 Hz wave again but with 24 bits per sample
00110     cout << TEST_HEADER << "Testing Wavefile::write(24-bit), read(24-bit) ..." << flush;
00111 
00112     Wavefile::setDefaultSampleSize(24);
00113 
00114     data1 >> "test_wavefile2.wav";
00115 
00116     data = AudioStream(100, 3);
00117     data << "test_wavefile2.wav";
00118 
00119     // Create gold file
00120 //~    data >> "gold/Wavefile_out2.wav";
00121 
00122     gold = AudioStream(100, 3);
00123     gold << "gold/Wavefile_out2.wav";
00124 
00125     diff = data - gold;
00126 
00127     abs_diff = diff;
00128     abs_diff.abs();
00129 
00130     for(int32 i = 0; i < 1; ++i)
00131     {
00132         if(abs_diff[i].getMax() > 0.5 * GAMMA)
00133         {
00134             cerr << TEST_ERROR_HEADER
00135                  << "Output did not match gold file!"
00136                  << endl;
00137 
00138             diff[i].plot("data - gold");
00139             data[i].plot("data");
00140             gold[i].plot("gold");
00141 
00142             Plotter::show();
00143 
00144             exit(1);
00145         }
00146     }
00147 
00148     cout << SUCCESS << endl;
00149 }

Generated on Sun Apr 15 20:10:48 2012 for nsound by  doxygen 1.6.3