zynaddsubfx

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

commit 6883c6b40296752abb19d23508c95381d7039e5d
parent d72c95d247165020e59975311510dd434ff900de
Author: Harald Hvaal <[email protected]>
Date:   Tue, 21 Jul 2009 16:13:17 +0900

Integrate cxxtest into cmake. Implement a test for adnote
Squashed commit of the following:

commit 5f4bd5ea3a438449eb1ba4fdb84d84c5ce9b1413
Merge: f47e1a1... 8ed16ff...
Author: Harald Hvaal <[email protected]>
Date:   Tue Jul 21 08:56:05 2009 +0900

    Merge branch 'cxxTesting' of ssh://[email protected]/gitroot/zynaddsubfx into cxxTesting

commit 8ed16ff6440d72dff059b41e9a65e460c026bb2d
Author: fundamental <[email protected]>
Date:   Mon Jul 20 19:20:35 2009 -0400

    Fixed linker errors with CTest

commit f14902e22d437c76bdd66bdc75b517ed112c038f
Merge: 3820540... b44d7e0...
Author: fundamental <[email protected]>
Date:   Mon Jul 20 18:30:53 2009 -0400

    Merge branch 'experimental' into cxxTesting

    Conflicts:
    	src/Synth/CMakeLists.txt

commit f47e1a1f49f7ba789473291e7d947f9a578464c2
Author: Harald Hvaal <[email protected]>
Date:   Mon Jul 20 23:19:27 2009 +0900

    expanding the adnotetest to work

commit 382054046d9a6a37e14f70b8675b7e6de247439d
Author: Harald Hvaal <[email protected]>
Date:   Sun Jul 19 12:41:27 2009 +0900

    Adding cxx testing. still a few linker errors. help me out here, mark?

Diffstat:
MCMakeLists.txt | 1+
Msrc/CMakeLists.txt | 53++++++++++++++++++++++++++++++++++++++++++-----------
Asrc/Synth/ADnote.cxx | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Synth/CMakeLists.txt | 3+++
Asrc/Tests/CMakeLists.txt | 3+++
Msrc/Tests/EchoTest.h | 2+-
6 files changed, 162 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -2,5 +2,6 @@ cmake_minimum_required(VERSION 2.6) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") project(zynaddsubfx) +enable_testing() #Currently the only directory that uses cmake add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -113,16 +113,56 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) +#macro for tests +macro(unit_test NAME CXX_FILE FILES) + set(PATH_FILES "") + foreach(part ${FILES}) + set(PATH_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${part}" ${PATH_FILES}) + endforeach(part ${FILES}) + set(CXX_FILE_REAL "${CMAKE_CURRENT_SOURCE_DIR}/${CXX_FILE}") + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cxx" + COMMAND cxxtestgen.py --error-printer -o "${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cxx" ${CXX_FILE_REAL} + DEPENDS "${FILE}" + ) + set(CXXTEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cxx") + add_executable("${NAME}" "${CXXTEST_OUTPUT}" ${PATH_FILES}) + target_link_libraries("${NAME}" ${CXXTEST_LINK_LIBS} + ${NONGUI_LIBRARIES} + ${GUI_LIBRARIES} + ${zlib_LIBRARIES} + ${fftw_LIBRARIES} + ${MXML_LIBRARIES} + ) + add_test("${NAME}" "${EXECUTABLE_OUTPUT_PATH}/${NAME}") +endmacro(unit_test) + +set(NONGUI_LIBRARIES + zynaddsubfx_input + zynaddsubfx_output + zynaddsubfx_misc + zynaddsubfx_synth + zynaddsubfx_seq + zynaddsubfx_effect + zynaddsubfx_params + zynaddsubfx_dsp + zynaddsubfx_samples + zynaddsubfx_controls + ) + +set(CXXTEST_LINK_LIBS ${NONGUI_LIBRARIES}) + add_subdirectory(Misc) add_subdirectory(Input) -add_subdirectory(Output) add_subdirectory(Controls) add_subdirectory(Synth) +add_subdirectory(Output) add_subdirectory(Seq) add_subdirectory(Effects) add_subdirectory(Params) add_subdirectory(DSP) add_subdirectory(Samples) +add_subdirectory(Tests) set(zynaddsubfx_SRCS main.cpp @@ -133,16 +173,7 @@ add_executable(zynaddsubfx ) target_link_libraries(zynaddsubfx - zynaddsubfx_input - zynaddsubfx_output - zynaddsubfx_misc - zynaddsubfx_synth - zynaddsubfx_seq - zynaddsubfx_effect - zynaddsubfx_params - zynaddsubfx_dsp - zynaddsubfx_samples - zynaddsubfx_controls + ${NONGUI_LIBRARIES} ${GUI_LIBRARIES} ${zlib_LIBRARIES} ${fftw_LIBRARIES} diff --git a/src/Synth/ADnote.cxx b/src/Synth/ADnote.cxx @@ -0,0 +1,112 @@ +#include <cxxtest/TestSuite.h> +#include <iostream> +#include <fstream> +#include "../Misc/Master.h" +#include "../Misc/Util.h" +#include "../Synth/ADnote.h" +#include "../Params/Presets.h" +#include "../globals.h" + +class AdNoteTest : public CxxTest::TestSuite +{ +public: + + ADnote *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; + + OscilGen::tmpsmps=new REALTYPE[OSCIL_SIZE]; + newFFTFREQS(&OscilGen::outoscilFFTfreqs,OSCIL_SIZE/2); + + + //phew, glad to get thouse out of my way. took me a lot of sweat and gdb to get this far... + + //prepare the default settings + ADnoteParameters *defaultPreset = new ADnoteParameters(new FFTwrapper(OSCIL_SIZE)); + 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 ADnote(defaultPreset, controller, freq, 120, 0, testnote, false); + + } + + void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh() + { + master = new Master(); + } + + void tearDown() { + delete note; + deleteFFTFREQS(&OscilGen::outoscilFFTfreqs); + } + + void testDefaults() { + + TS_ASSERT(note->ready); + int sampleCount = 0; + +//#define WRITE_OUTPUT + + +#ifdef WRITE_OUTPUT + ofstream file("adnoteout", 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.123737, 0.000001); + + note->relasekey(); + note->noteout(outL, outR); + sampleCount += SOUND_BUFFER_SIZE; + + TS_ASSERT_DELTA(outL[255], 0.14147, 0.00001); + + 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); + + } +}; + diff --git a/src/Synth/CMakeLists.txt b/src/Synth/CMakeLists.txt @@ -13,3 +13,6 @@ add_library(zynaddsubfx_synth STATIC ) target_link_libraries(zynaddsubfx_synth) + +unit_test(adnote_test ADnote.cxx "") + diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt @@ -0,0 +1,3 @@ +#unit_test(ControllerTest ControllerTest.h "") +#unit_test(EchoTest EchoTest.h "") +#unit_test(SampleTest SampleTest.h "") diff --git a/src/Tests/EchoTest.h b/src/Tests/EchoTest.h @@ -23,7 +23,7 @@ #include <cmath> #include "../Effects/Echo.h" #include "../globals.h" - +//int SOUND_BUFFER_SIZE=256; class EchoTest : public CxxTest::TestSuite { public: