zynaddsubfx

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

commit 02daa9fe38fdb5054c899420a9f23650dd05c4c0
parent 376a5f16b05921d4bd2f46bd77e0af9a162f2ded
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Tue, 21 Oct 2014 11:31:40 -0400

Fix Buffer Overrun

Fixes Undefined Behavior Generated In PADnoteParameters wavetable generation

Diffstat:
Msrc/Params/PADnoteParameters.cpp | 8++++----
Msrc/Tests/PadNoteTest.h | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/src/Params/PADnoteParameters.cpp b/src/Params/PADnoteParameters.cpp @@ -582,9 +582,9 @@ void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum, int profilesize, float bwadjust) { - float harmonics[synth->oscilsize / 2]; + float harmonics[synth->oscilsize]; memset(spectrum, 0, sizeof(float) * size); - memset(harmonics, 0, sizeof(float) * (synth->oscilsize / 2)); + memset(harmonics, 0, sizeof(float) * synth->oscilsize); //get the harmonic structure from the oscillator (I am using the frequency amplitudes, only) oscilgen->get(harmonics, basefreq, false); @@ -656,9 +656,9 @@ void PADnoteParameters::generatespectrum_otherModes(float *spectrum, int size, float basefreq) { - float harmonics[synth->oscilsize / 2]; + float harmonics[synth->oscilsize]; memset(spectrum, 0, sizeof(float) * size); - memset(harmonics, 0, sizeof(float) * (synth->oscilsize / 2)); + memset(harmonics, 0, sizeof(float) * synth->oscilsize); //get the harmonic structure from the oscillator (I am using the frequency amplitudes, only) oscilgen->get(harmonics, basefreq, false); diff --git a/src/Tests/PadNoteTest.h b/src/Tests/PadNoteTest.h @@ -84,18 +84,18 @@ class PadNoteTest:public CxxTest::TestSuite //Assert defaults ///TS_ASSERT(!defaultPreset->VoicePar[1].Enabled); - XMLwrapper *wrap = new XMLwrapper(); + XMLwrapper wrap; cout << string(SOURCE_DIR) + string("/guitar-adnote.xmz") << endl; - wrap->loadXMLfile(string(SOURCE_DIR) + wrap.loadXMLfile(string(SOURCE_DIR) + string("/guitar-adnote.xmz")); - TS_ASSERT(wrap->enterbranch("MASTER")); - TS_ASSERT(wrap->enterbranch("PART", 2)); - TS_ASSERT(wrap->enterbranch("INSTRUMENT")); - TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT")); - TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0)); - TS_ASSERT(wrap->enterbranch("PAD_SYNTH_PARAMETERS")); - pars->getfromXML(wrap); + TS_ASSERT(wrap.enterbranch("MASTER")); + TS_ASSERT(wrap.enterbranch("PART", 2)); + TS_ASSERT(wrap.enterbranch("INSTRUMENT")); + TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT")); + TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT_ITEM", 0)); + TS_ASSERT(wrap.enterbranch("PAD_SYNTH_PARAMETERS")); + pars->getfromXML(&wrap); //defaultPreset->defaults(); @@ -114,14 +114,6 @@ class PadNoteTest:public CxxTest::TestSuite SynthParams pars_{memory, *controller, freq, 120, 0, testnote, false}; note = new PADnote(pars, pars_); - - //delete defaultPreset; - delete wrap; - } - - void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh() - { - master = new Master(); } void tearDown() { @@ -131,8 +123,18 @@ class PadNoteTest:public CxxTest::TestSuite delete [] outL; delete [] outR; delete [] denormalkillbuf; + delete pars; FFT_cleanup(); delete synth; + + note = NULL; + controller = NULL; + fft = NULL; + outL = NULL; + outR = NULL; + denormalkillbuf = NULL; + pars = NULL; + synth = NULL; } @@ -193,7 +195,17 @@ class PadNoteTest:public CxxTest::TestSuite TS_ASSERT_EQUALS(sampleCount, 2304); } - void testSetup() { + void testInitialization() { + TS_ASSERT_EQUALS(pars->Pmode, 0); + + TS_ASSERT_EQUALS(pars->PVolume, 90); + TS_ASSERT(pars->oscilgen); + TS_ASSERT(pars->resonance); + + TS_ASSERT_DELTA(note->NoteGlobalPar.Volume, 2.597527f, 0.001f); + TS_ASSERT_DELTA(note->NoteGlobalPar.Panning, 0.500000f, 0.01f); + + for(int i=0; i<7; ++i) TS_ASSERT(pars->sample[i].smp); for(int i=7; i<PAD_MAX_SAMPLES; ++i) @@ -220,12 +232,46 @@ class PadNoteTest:public CxxTest::TestSuite TS_ASSERT_DELTA(pars->sample[0].smp[18], -0.058690f, 0.0005f); TS_ASSERT_DELTA(pars->sample[0].smp[19], -0.090954f, 0.0005f); - TS_ASSERT_EQUALS(pars->PVolume, 90); - TS_ASSERT(pars->oscilgen); - TS_ASSERT(pars->resonance); - TS_ASSERT_DELTA(note->NoteGlobalPar.Volume, 2.597527f, 0.001f); - TS_ASSERT_DELTA(note->NoteGlobalPar.Panning, 0.500000f, 0.01f); + //Verify Harmonic Input + float harmonics[synth->oscilsize]; + memset(harmonics, 0, sizeof(float) * synth->oscilsize); + + pars->oscilgen->get(harmonics, 440.0f, false); + + TS_ASSERT_DELTA(harmonics[0] ,0.683947, 0.0005f); + TS_ASSERT_DELTA(harmonics[1] ,0.128246, 0.0005f); + TS_ASSERT_DELTA(harmonics[2] ,0.003238, 0.0005f); + TS_ASSERT_DELTA(harmonics[3] ,0.280945, 0.0005f); + TS_ASSERT_DELTA(harmonics[4] ,0.263548, 0.0005f); + TS_ASSERT_DELTA(harmonics[5] ,0.357070, 0.0005f); + TS_ASSERT_DELTA(harmonics[6] ,0.096287, 0.0005f); + TS_ASSERT_DELTA(harmonics[7] ,0.128685, 0.0005f); + TS_ASSERT_DELTA(harmonics[8] ,0.003238, 0.0005f); + TS_ASSERT_DELTA(harmonics[9] ,0.149376, 0.0005f); + TS_ASSERT_DELTA(harmonics[10],0.063892, 0.0005f); + TS_ASSERT_DELTA(harmonics[11],0.296716, 0.0005f); + TS_ASSERT_DELTA(harmonics[12],0.051057, 0.0005f); + TS_ASSERT_DELTA(harmonics[13],0.066310, 0.0005f); + TS_ASSERT_DELTA(harmonics[14],0.004006, 0.0005f); + TS_ASSERT_DELTA(harmonics[15],0.038662, 0.0005f); + + float sum = 0; + for(int i=0; i<synth->oscilsize/2; ++i) + sum += harmonics[i]; + TS_ASSERT_DELTA(sum, 5.863001, 0.0005f); + + TS_ASSERT_DELTA(pars->getNhr(0), 0.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(1), 1.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(2), 2.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(3), 3.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(4), 4.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(5), 5.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(6), 6.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(7), 7.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(8), 8.000000, 0.0005f); + TS_ASSERT_DELTA(pars->getNhr(9), 9.000000, 0.0005f); + } #define OUTPUT_PROFILE