zynaddsubfx

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

MemoryStressTest.cpp (3367B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   AdNoteTest.h - CxxTest for Synth/ADnote
      5   Copyright (C) 2009-2011 Mark McCurry
      6   Copyright (C) 2009 Harald Hvaal
      7   Authors: Mark McCurry, Harald Hvaal
      8 
      9   This program is free software; you can redistribute it and/or
     10   modify it under the terms of the GNU General Public License
     11   as published by the Free Software Foundation; either version 2
     12   of the License, or (at your option) any later version.
     13 */
     14 
     15 
     16 #include "test-suite.h"
     17 #include <iostream>
     18 #include <fstream>
     19 #include <ctime>
     20 #include <string>
     21 #include "../Misc/Master.h"
     22 #include "../Misc/Util.h"
     23 #include "../Misc/Allocator.h"
     24 #include "../Synth/ADnote.h"
     25 #include "../Params/Presets.h"
     26 #include "../DSP/FFTwrapper.h"
     27 #include "../globals.h"
     28 using namespace zyn;
     29 
     30 SYNTH_T *synth;
     31 
     32 class MemoryStressTest
     33 {
     34     public:
     35         AbsTime      *time;
     36         FFTwrapper   *fft;
     37         ADnoteParameters *defaultPreset;
     38         Controller   *controller;
     39         Alloc         memory;
     40 
     41         void setUp() {
     42             //First the sensible settings and variables that have to be set:
     43             synth = new SYNTH_T;
     44             synth->buffersize = 256;
     45             //synth->alias();
     46             time  = new AbsTime(*synth);
     47 
     48             fft = new FFTwrapper(synth->oscilsize);
     49             //prepare the default settings
     50             defaultPreset = new ADnoteParameters(*synth, fft, time);
     51 
     52             //Assert defaults
     53             TS_ASSERT(!defaultPreset->VoicePar[1].Enabled);
     54 
     55             std::string instrument_filename = std::string(SOURCE_DIR) + "/guitar-adnote.xmz";
     56             std::cout << instrument_filename << std::endl;
     57 
     58             XMLwrapper wrap;
     59             wrap.loadXMLfile(instrument_filename);
     60             TS_ASSERT(wrap.enterbranch("MASTER"));
     61             TS_ASSERT(wrap.enterbranch("PART", 0));
     62             TS_ASSERT(wrap.enterbranch("INSTRUMENT"));
     63             TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT"));
     64             TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT_ITEM", 0));
     65             TS_ASSERT(wrap.enterbranch("ADD_SYNTH_PARAMETERS"));
     66             defaultPreset->getfromXML(wrap);
     67 
     68             //verify xml was loaded
     69             TS_ASSERT(defaultPreset->VoicePar[1].Enabled);
     70 
     71             controller = new Controller(*synth, time);
     72 
     73         }
     74 
     75         void tearDown() {
     76             delete controller;
     77             delete defaultPreset;
     78             delete fft;
     79             FFT_cleanup();
     80             delete time;
     81             delete synth;
     82         }
     83 
     84         void testManySimultaneousNotes() {
     85 
     86             unsigned char testnote = 42;
     87             SynthParams pars{memory, *controller, *synth, *time, 120, 0, testnote / 12.0f, false, prng()};
     88 
     89             std::vector<ADnote*> notes;
     90 
     91             for ( size_t note_idx = 0; note_idx < 1000; ++ note_idx ) {
     92                 try {
     93                     notes.push_back(new ADnote(defaultPreset, pars));
     94                 } catch (std::exception & e) {
     95 #if defined(DEBUG)
     96                     std::cerr << "couldn't push note #" << note_idx << std::endl;
     97 #endif
     98                 }
     99             }
    100 
    101             // If we made it that far, we managed to create many ADnotewithout sigsev
    102 
    103             for (auto note_ptr: notes) {
    104                 delete note_ptr;
    105             }
    106 
    107 
    108         }
    109 
    110 };
    111 
    112 int main()
    113 {
    114     MemoryStressTest test;
    115     RUN_TEST(testManySimultaneousNotes);
    116     return test_summary();
    117 }