zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 2922cb4e88c3e13a990ca408a171b2f183e954d6
parent 2a2957b6fcd57fc94979fc4b3cdd33edc3d5cce1
Author: fundamental <[email protected]>
Date:   Thu,  8 Oct 2009 22:00:29 -0400

SUBnote: Added basic test/profile

Diffstat:
MChangeLog | 1+
Msrc/Tests/CMakeLists.txt | 1+
Asrc/Tests/SubNoteTest.h | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -953,3 +953,4 @@ 08 Oct 2009 (Mark McCurry) - Started to see if memset/memcpy offer performance benifits when widely used + - Added basic SUBnote test diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt @@ -4,3 +4,4 @@ unit_test(SampleTest SampleTest.h ../Samples/AuSample.h) unit_test(MicrotonalTest MicrotonalTest.h ../Misc/Microtonal.h) unit_test(XMLwrapperTest XMLwrapperTest.h ../Misc/XMLwrapper.h) unit_test(ADnoteTest AdNoteTest.h ../Synth/ADnote.h) +unit_test(SUBnoteTest SubNoteTest.h ../Synth/SUBnote.h) diff --git a/src/Tests/SubNoteTest.h b/src/Tests/SubNoteTest.h @@ -0,0 +1,150 @@ +//Based Upon AdNoteTest.h +#include <cxxtest/TestSuite.h> +#include <iostream> +#include <fstream> +#include <ctime> +#include <string> +#include "../Misc/Master.h" +#include "../Misc/Util.h" +#include "../Synth/SUBnote.h" +#include "../Params/Presets.h" +#include "../globals.h" + +using namespace std; + +class SubNoteTest : public CxxTest::TestSuite +{ +public: + + SUBnote *note; + Master *master; + Controller *controller; + unsigned char testnote; + + + float *outR,*outL; + + void setUp() { + + //First the sensible settings and variables that have to be set: + SOUND_BUFFER_SIZE = 256; + + outL=new float[SOUND_BUFFER_SIZE]; + for (int i=0;i<SOUND_BUFFER_SIZE;++i) + *(outL+i)=0; + outR=new float[SOUND_BUFFER_SIZE]; + for (int i=0;i<SOUND_BUFFER_SIZE;++i) + *(outR+i)=0; + + //next the bad global variables that for some reason have not been properly placed in some + //initialization routine, but rather exist as cryptic oneliners in main.cpp: + denormalkillbuf= new REALTYPE[SOUND_BUFFER_SIZE]; + for (int i=0;i<SOUND_BUFFER_SIZE;i++) denormalkillbuf[i]=0; + + //prepare the default settings + SUBnoteParameters *defaultPreset = new SUBnoteParameters(); + XMLwrapper *wrap = new XMLwrapper(); + wrap->loadXMLfile(string(SOURCE_DIR) + string("/Tests/guitar-adnote.xmz")); + TS_ASSERT(wrap->enterbranch("MASTER")); + TS_ASSERT(wrap->enterbranch("PART", 1)); + TS_ASSERT(wrap->enterbranch("INSTRUMENT")); + TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT")); + TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0)); + TS_ASSERT(wrap->enterbranch("SUB_SYNTH_PARAMETERS")); + defaultPreset->getfromXML(wrap); + //defaultPreset->defaults(); + + controller = new Controller(); + + //lets go with.... 50! as a nice note + testnote = 50; + REALTYPE freq = 440.0*pow(2.0,(testnote-69.0)/12.0); + + note = new SUBnote(defaultPreset, controller, freq, 120, 0, testnote, false); + + } + + void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh() + { + master = new Master(); + } + + void tearDown() { + delete note; + } + + void testDefaults() { + //Note: if these tests fail it is due to the relationship between + //global.h::RND and SUBnote.cpp + + TS_ASSERT(note->ready); + int sampleCount = 0; + +//#define WRITE_OUTPUT + +#ifdef WRITE_OUTPUT + ofstream file("subnoteout", ios::out); +#endif + note->noteout(outL, outR); +#ifdef WRITE_OUTPUT + for (int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + file << outL[i] << std::endl; + } +#endif + sampleCount += SOUND_BUFFER_SIZE; + + TS_ASSERT_DELTA(outL[255], 0.0000, 0.0001); + + note->relasekey(); + + + note->noteout(outL, outR); + sampleCount += SOUND_BUFFER_SIZE; + TS_ASSERT_DELTA(outL[255], 0.0022, 0.0001); + + note->noteout(outL, outR); + sampleCount += SOUND_BUFFER_SIZE; + TS_ASSERT_DELTA(outL[255], -0.0020, 0.0001); + + note->noteout(outL, outR); + sampleCount += SOUND_BUFFER_SIZE; + TS_ASSERT_DELTA(outL[255], 0.0010, 0.0001); + + note->noteout(outL, outR); + sampleCount += SOUND_BUFFER_SIZE; + TS_ASSERT_DELTA(outL[255], 0.0005, 0.0001); + + while (!note->finished()) { + note->noteout(outL, outR); +#ifdef WRITE_OUTPUT + for (int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + file << outL[i] << std::endl; + } +#endif + sampleCount += SOUND_BUFFER_SIZE; + } +#ifdef WRITE_OUTPUT + file.close(); +#endif + + TS_ASSERT_EQUALS(sampleCount, 2304); + + } + +#define OUTPUT_PROFILE +#ifdef OUTPUT_PROFILE + void testSpeed() { + + const int samps = 15000; + + int t_on = clock(); // timer before calling func + for(int i=0; i<samps; ++i) + note->noteout(outL, outR); + int t_off = clock(); // timer when func returns + + printf ("SubNoteTest: %f seconds for %d Samples to be generated.\n", + (static_cast<float>(t_off - t_on))/CLOCKS_PER_SEC, samps); + } +#endif +}; +