From 57aa7c472b6de760140a39e938842773f5c6c03c Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 16 Oct 2016 07:01:18 +0000 Subject: [PATCH] Simple tests... SEGV is still present. --- src/dexed-test.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++++ src/dexed-test.sh | 6 +++ src/dexed.cpp | 13 ++++-- 3 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 src/dexed-test.cpp create mode 100644 src/dexed-test.sh diff --git a/src/dexed-test.cpp b/src/dexed-test.cpp new file mode 100644 index 0000000..93a8dde --- /dev/null +++ b/src/dexed-test.cpp @@ -0,0 +1,108 @@ +#include "EngineMkI.h" +#include "EngineOpl.h" +#include "msfa/exp2.h" +#include "msfa/sin.h" +#include "msfa/freqlut.h" +#include "msfa/controllers.h" +#include "msfa/dx7note.h" +#include "msfa/lfo.h" +#include "msfa/synth.h" +#include "msfa/fm_core.h" + +#include +#include + +template float normalize(const T x) { + const float valMin = std::numeric_limits::min(); + const float valMax = std::numeric_limits::max(); + return 2 * (x - valMin) / (valMax - valMin) - 1; // note: 0 does not become 0. +} + +struct ProcessorVoice { + int midi_note; + bool keydown; + bool sustained; + bool live; + Dx7Note *dx7_note; +}; + +// GLOBALS +FmCore engineMsfa; +EngineMkI engineMkI; +EngineOpl engineOpl; + +Lfo lfo; +Controllers controllers; +const int rate=44100; +const uint8_t init_voice[] = + { 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, + 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, + 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, + 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, + 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, + 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 99, 0, 1, 0, 7, + 99, 99, 99, 99, 50, 50, 50, 50, 0, 0, 1, 35, 0, 0, 0, 1, 0, 3, 24, + 73, 78, 73, 84, 32, 86, 79, 73, 67, 69 }; +uint8_t data[156]; // program data +ProcessorVoice voice; +uint8_t feedback_bitdepth=11; + +int main(int argc, char **argv) +{ + Exp2::init(); + Tanh::init(); + Sin::init(); + Freqlut::init(rate); + Lfo::init(rate); + PitchEnv::init(rate); + Env::init_sr(rate); + + uint32_t i; + + for(i=0;iinit(data, key, velocity, feedback_bitdepth); + voice.live=true; + } + if(data[136]) + voice.dx7_note->oscSync(); + + int32_t s; + for(i=0;i<256;++i) + { + if(voice.live==true) + { + voice.dx7_note->compute(&s, lfo.getsample(), lfo.getdelay(), &controllers); + float fs=normalize(s); + printf("%f %d %d\n",fs, lfo.getsample(), lfo.getdelay()); + } + } +} + diff --git a/src/dexed-test.sh b/src/dexed-test.sh new file mode 100644 index 0000000..92d6616 --- /dev/null +++ b/src/dexed-test.sh @@ -0,0 +1,6 @@ +set -x +make +g++ -std=c++11 -c dexed-test.cpp +g++ -std=c++11 dexed-test.o fm_core.o env.o lfo.o dx7note.o sin.o pitchenv.o fm_op_kernel.o freqlut.o exp2.o EngineMkI.o EngineOpl.o -lm -o dexed-test +./dexed-test + diff --git a/src/dexed.cpp b/src/dexed.cpp index 373f76f..94d2d55 100644 --- a/src/dexed.cpp +++ b/src/dexed.cpp @@ -104,19 +104,24 @@ unsigned char DexedVoice::get_key(void) const void DexedVoice::render(uint32_t from, uint32_t to) { int32_t s; + uint32_t render_loop_counter=from; TRACE("Hi"); TRACE("%d from: %d to: %d",voice_number,from,to); +TRACE("1:%d",render_loop_counter); if (m_key != lvtk::INVALID_KEY) { - for (uint32_t i = from; i < to; ++i) + for (render_loop_counter = from; render_loop_counter < to; ++render_loop_counter) { +TRACE("2:%d",render_loop_counter); if(voice.live==true) { +TRACE("3:%d",render_loop_counter); voice.dx7_note->compute(&s, lfo.getsample(), lfo.getdelay(), &controllers); +TRACE("4:%d",render_loop_counter); float fs=(float)s/INT32_MAX; - p(p_lv2_audio_out_1)[i]+=fs; + p(p_lv2_audio_out_1)[render_loop_counter]+=fs; TRACE("out: %2.5f",fs); } } @@ -124,7 +129,7 @@ void DexedVoice::render(uint32_t from, uint32_t to) TRACE("Bye"); } -void DexedVoice::post_process(uint32_t from, uint32_t to) +/* void DexedVoice::post_process(uint32_t from, uint32_t to) { TRACE("Hi"); for (uint32_t i = from; i < to; ++i) @@ -132,7 +137,7 @@ void DexedVoice::post_process(uint32_t from, uint32_t to) p(p_lv2_audio_out_1)[i] *= *p(p_output); } TRACE("Bye"); -} +} */ #ifdef DEBUG void dexed_trace(const char *source, const char *fmt, ...) {