From fe88998c12016114b771233bab96411526fb9b59 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 14 Nov 2016 09:41:33 +0100 Subject: [PATCH] Saving current state. --- src/Makefile | 58 +++--- src/dexed-ttl.h | 333 +++++++++++++++++++++++++++++++++ src/dexed.cpp | 114 +++++------ src/dexed.h | 58 +++--- src/msfa/ringbuffer.cc | 76 ++++++++ src/msfa/ringbuffer.h | 44 +++++ src/{ => trash}/DXComponents.h | 0 src/{ => trash}/ParamDialog.h | 0 src/{ => trash}/SysexComm.cpp | 0 9 files changed, 561 insertions(+), 122 deletions(-) create mode 100644 src/dexed-ttl.h create mode 100644 src/msfa/ringbuffer.cc create mode 100644 src/msfa/ringbuffer.h rename src/{ => trash}/DXComponents.h (100%) rename src/{ => trash}/ParamDialog.h (100%) rename src/{ => trash}/SysexComm.cpp (100%) diff --git a/src/Makefile b/src/Makefile index 2ecbe93..692baa6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,35 +1,45 @@ -BUNDLE = dexed.lv2 -INSTALL_DIR = /home/pi/zynthian/zynthian-plugins/mod-lv2 -CFLAGS := -fPIC -DPIC -DDEBUG=1 -std=c++11 -I. -I/usr/local/include/lvtk-2 -LDFLAGS := -L/usr/local/lib -llvtk_plugin2 -OBJ = 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 -# SysexComm.o PluginFx.o +#DEBUG=-DDEBUG=1 -DMSFADEBUG=1 +#DEBUG=-DMSFADEBUG=1 +BUNDLE=dexed.lv2 +INSTALL_DIR=/home/pi/zynthian/zynthian-plugins/mod-lv2 +TARGET=dexed.so +OBJ=ringbuffer.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 +CFLAGS=-fPIC -DPIC $(DEBUG) -std=c++11 -I. -I/usr/local/include/lvtk-2 +LDFLAGS=-L/usr/local/lib -llvtk_plugin2 -$(BUNDLE): manifest.ttl Dexed.ttl dexed.so - rm -rf $(BUNDLE) - mkdir $(BUNDLE) - cp $^ $(BUNDLE) +all: $(BUNDLE) Makefile clean: - rm -f *.o *~ *.bak *.gch *.peg dexed-test + rm -f *.o *~ *.bak *.gch dexed-ttl.h *.so + rm -rf $(BUNDLE) install: $(BUNDLE) mkdir -p $(INSTALL_DIR) rm -rf $(INSTALL_DIR)/$(BUNDLE) + rm -rf ${HOME}/.lv2/$(BUNDLE) cp -R $(BUNDLE) $(INSTALL_DIR) -dexed-test: $(OBJ) dexed-test.o - g++ -fPIC -DPIC dexed-test.o $(OBJ) $(LDFLAGS) -o dexed-test +$(BUNDLE): manifest.ttl Dexed.ttl dexed.so + rm -rf $(BUNDLE) + mkdir $(BUNDLE) + cp $^ $(BUNDLE) +# cp -R modgui $(BUNDLE) dexed.so: $(OBJ) dexed.o g++ -shared dexed.o $(OBJ) $(LDFLAGS) -o dexed.so -dexed-test.o: dexed-test.cpp - $(CXX) $(CFLAGS) -Wall -c dexed-test.cpp +#dexed-test: $(OBJ) dexed-test.o +# g++ -fPIC -DPIC dexed-test.o $(OBJ) $(LDFLAGS) -o dexed-test +# +#dexed-test.o: dexed-test.cpp +# $(CXX) $(CFLAGS) -Wall -c dexed-test.cpp -dexed.o: dexed.cpp dexed.peg +dexed.o: dexed.cpp dexed-ttl.h $(CXX) $(CFLAGS) -Wall -c dexed.cpp +ringbuffer.o: msfa/ringbuffer.cc + $(CXX) $(CFLAGS) -Wall -c msfa/ringbuffer.cc + fm_core.o: msfa/fm_core.cc $(CXX) $(CFLAGS) -Wall -c msfa/fm_core.cc @@ -66,18 +76,6 @@ EngineOpl.o: EngineOpl.cpp PluginFx.o: PluginFx.cpp $(CXX) $(CFLAGS) -Wall -c PluginFx.cpp -PluginProcessor.o: PluginProcessor.cpp - $(CXX) $(CFLAGS) -Wall -c PluginProcessor.cpp - -SysexComm.o: SysexComm.cpp - $(CXX) $(CFLAGS) -Wall -c SysexComm.cpp - -#msfa/%.o: msfa/%.cc -# $(CXX) $(CFLAGS) -Wall -c $< -# -#%.o: %.cpp -# $(CXX) $(CFLAGS) -Wall -c $< - -dexed.peg: Dexed.ttl - lv2peg Dexed.ttl dexed.peg +dexed-ttl.h: Dexed.ttl + ttl2c Dexed.ttl dexed-ttl.h diff --git a/src/dexed-ttl.h b/src/dexed-ttl.h new file mode 100644 index 0000000..9701d66 --- /dev/null +++ b/src/dexed-ttl.h @@ -0,0 +1,333 @@ +#ifndef dexed_ttl_h +#define dexed_ttl_h + + +#ifndef PEG_STRUCT +#define PEG_STRUCT +typedef struct { + float min; + float max; + float default_value; + char toggled; + char integer; + char logarithmic; +} peg_data_t; +#endif + +/* */ + +static const char p_uri[] = "https://github.com/dcoredump/dexed"; + +enum p_port_enum { + p_lv2_events_in, + p_lv2_freewheel, + p_lv2_latency, + p_lv2_audio_out_1, + p_cutoff, + p_resonance, + p_output, + p_algorithm, + p_feedback, + p_osc_key_sync, + p_lfo_speed, + p_lfo_delay, + p_lfo_pm_depth, + p_lfo_am_depth, + p_lfo_key_sync, + p_lfo_wave, + p_middle_c, + p_p_mode_sens_, + p_pitch_eg_rate_1, + p_pitch_eg_rate_2, + p_pitch_eg_rate_3, + p_pitch_eg_rate_4, + p_pitch_eg_level_1, + p_pitch_eg_level_2, + p_pitch_eg_level_3, + p_pitch_eg_level_4, + p_op1_eg_rate_1, + p_op1_eg_rate_2, + p_op1_eg_rate_3, + p_op1_eg_rate_4, + p_op1_eg_level_1, + p_op1_eg_level_2, + p_op1_eg_level_3, + p_op1_eg_level_4, + p_op1_output_level, + p_op1_mode, + p_op1_f_coarse, + p_op1_f_fine, + p_op1_osc_detune, + p_op1_break_point, + p_op1_l_scale_depth, + p_op1_r_scale_depth, + p_op1_l_key_scale, + p_op1_r_key_scale, + p_op1_rate_scaling, + p_op1_a_mod_sens_, + p_op1_key_velocity, + p_op2_eg_rate_1, + p_op2_eg_rate_2, + p_op2_eg_rate_3, + p_op2_eg_rate_4, + p_op2_eg_level_1, + p_op2_eg_level_2, + p_op2_eg_level_3, + p_op2_eg_level_4, + p_op2_output_level, + p_op2_mode, + p_op2_f_coarse, + p_op2_f_fine, + p_op2_osc_detune, + p_op2_break_point, + p_op2_l_scale_depth, + p_op2_r_scale_depth, + p_op2_l_key_scale, + p_op2_r_key_scale, + p_op2_rate_scaling, + p_op2_a_mod_sens_, + p_op2_key_velocity, + p_op3_eg_rate_1, + p_op3_eg_rate_2, + p_op3_eg_rate_3, + p_op3_eg_rate_4, + p_op3_eg_level_1, + p_op3_eg_level_2, + p_op3_eg_level_3, + p_op3_eg_level_4, + p_op3_output_level, + p_op3_mode, + p_op3_f_coarse, + p_op3_f_fine, + p_op3_osc_detune, + p_op3_break_point, + p_op3_l_scale_depth, + p_op3_r_scale_depth, + p_op3_l_key_scale, + p_op3_r_key_scale, + p_op3_rate_scaling, + p_op3_a_mod_sens_, + p_op3_key_velocity, + p_op4_eg_rate_1, + p_op4_eg_rate_2, + p_op4_eg_rate_3, + p_op4_eg_rate_4, + p_op4_eg_level_1, + p_op4_eg_level_2, + p_op4_eg_level_3, + p_op4_eg_level_4, + p_op4_output_level, + p_op4_mode, + p_op4_f_coarse, + p_op4_f_fine, + p_op4_osc_detune, + p_op4_break_point, + p_op4_l_scale_depth, + p_op4_r_scale_depth, + p_op4_l_key_scale, + p_op4_r_key_scale, + p_op4_rate_scaling, + p_op4_a_mod_sens_, + p_op4_key_velocity, + p_op5_eg_rate_1, + p_op5_eg_rate_2, + p_op5_eg_rate_3, + p_op5_eg_rate_4, + p_op5_eg_level_1, + p_op5_eg_level_2, + p_op5_eg_level_3, + p_op5_eg_level_4, + p_op5_output_level, + p_op5_mode, + p_op5_f_coarse, + p_op5_f_fine, + p_op5_osc_detune, + p_op5_break_point, + p_op5_l_scale_depth, + p_op5_r_scale_depth, + p_op5_l_key_scale, + p_op5_r_key_scale, + p_op5_rate_scaling, + p_op5_a_mod_sens_, + p_op5_key_velocity, + p_op6_eg_rate_1, + p_op6_eg_rate_2, + p_op6_eg_rate_3, + p_op6_eg_rate_4, + p_op6_eg_level_1, + p_op6_eg_level_2, + p_op6_eg_level_3, + p_op6_eg_level_4, + p_op6_output_level, + p_op6_mode, + p_op6_f_coarse, + p_op6_f_fine, + p_op6_osc_detune, + p_op6_break_point, + p_op6_l_scale_depth, + p_op6_r_scale_depth, + p_op6_l_key_scale, + p_op6_r_key_scale, + p_op6_rate_scaling, + p_op6_a_mod_sens_, + p_op6_key_velocity, + p_n_ports +}; + +static const peg_data_t p_ports[] = { + { -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 }, + { 0, 1, 0, 1, 0, 0 }, + { -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 1, 0 }, + { -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0 }, + { 0, 1, 0, 0, 0, 0 }, + { 0, 2, 1, 0, 0, 0 }, + { 1, 32, 1, 0, 1, 0 }, + { 1, 8, 1, 0, 1, 0 }, + { 1, 1, 0, 1, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 1, 6, 1, 0, 1, 0 }, + { 0, 48, 24, 0, 1, 0 }, + { 1, 8, 1, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { -7, 7, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 0, 0, 1, 0 }, + { 0, 100, 0, 0, 1, 0 }, + { -7, 7, 0, 0, 1, 0 }, + { 0, 100, 0, 0, 1, 0 }, + { 0, 100, 0, 0, 1, 0 }, + { 0, 100, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { -7, 7, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 99, 1, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 7, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { -7, 7, 0, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 39, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { -7, 7, 0, 0, 1, 0 }, + { 0, 99, 39, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 99, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 1, 0, 1, 1, 0 }, + { 0, 31, 1, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { -7, 7, 7, 0, 1, 0 }, + { 0, 99, 39, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 99, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, + { 0, 3, 0, 0, 1, 0 }, + { 0, 7, 0, 0, 1, 0 }, +}; + + +#endif /* dexed_ttl_h */ diff --git a/src/dexed.cpp b/src/dexed.cpp index 94d2d55..c3db851 100644 --- a/src/dexed.cpp +++ b/src/dexed.cpp @@ -2,7 +2,7 @@ #include #include -#include "dexed.peg" +#include "dexed-ttl.h" #include "dexed.h" #include "EngineMkI.h" #include "EngineOpl.h" @@ -10,41 +10,52 @@ #include "msfa/sin.h" #include "msfa/freqlut.h" #include "msfa/controllers.h" +#include "msfa/ringbuffer.h" Dexed::Dexed(double rate) : lvtk::Synth(p_n_ports, p_lv2_events_in) { TRACE("Hi"); + bufsize_=256; + outbuf16_=new int16_t[bufsize_]; + Exp2::init(); Tanh::init(); Sin::init(); - feedback_bitdepth=11; + lastStateSave = 0; + currentNote = -1; + engineType = -1; + monoMode = 0; + normalizeDxVelocity = false; + + memset(&voiceStatus, 0, sizeof(VoiceStatus)); + setEngineType(DEXED_ENGINE_MARKI); - for(uint i=0;i(p_n_ports, p_lv2_even Dexed::~Dexed() { + TRACE("Hi"); + + delete [] outbuf16_; + TRACE("Bye"); } @@ -59,86 +74,45 @@ Dexed::~Dexed() DexedVoice::DexedVoice(double rate) : m_key(lvtk::INVALID_KEY), m_rate(rate) { - voice_number=voice_counter++; - TRACE("Hi %d",voice_number); - voice.dx7_note=new Dx7Note; + TRACE("Hi"); + + TRACE("Bye"); } DexedVoice::~DexedVoice() { + TRACE("Hi"); + TRACE("Bye"); } void DexedVoice::on(unsigned char key, unsigned char velocity) { + TRACE("Hi"); + m_key = key; - voice.midi_note=data[144] - 24; - voice.keydown=true; - voice.sustained=false; - lfo.keydown(); - if(voice.live==false) - { - voice.dx7_note->init(data, key, velocity, feedback_bitdepth); - voice.live=true; - } - if(data[136]) - voice.dx7_note->oscSync(); - TRACE("%d key-down: %d %d",voice_number,key,velocity); + TRACE("Bye"); } void DexedVoice::off(unsigned char velocity) { - voice.dx7_note->keyup(); - voice.keydown=false; - voice.live=false; + TRACE("Hi"); + m_key = lvtk::INVALID_KEY; - TRACE("%d key-up: %d",voice_number,velocity); + + TRACE("Bye"); } unsigned char DexedVoice::get_key(void) const { - return m_key; -} + TRACE("Hi"); -void DexedVoice::render(uint32_t from, uint32_t to) -{ - int32_t s; - uint32_t render_loop_counter=from; + return m_key; - 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 (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)[render_loop_counter]+=fs; - TRACE("out: %2.5f",fs); - } - } - } TRACE("Bye"); } -/* void DexedVoice::post_process(uint32_t from, uint32_t to) -{ - TRACE("Hi"); - for (uint32_t i = from; i < to; ++i) - { - p(p_lv2_audio_out_1)[i] *= *p(p_output); - } - TRACE("Bye"); -} */ - #ifdef DEBUG void dexed_trace(const char *source, const char *fmt, ...) { char output[4096]; diff --git a/src/dexed.h b/src/dexed.h index 5c96346..b878120 100644 --- a/src/dexed.h +++ b/src/dexed.h @@ -26,6 +26,7 @@ #include "msfa/lfo.h" #include "msfa/synth.h" #include "msfa/fm_core.h" +#include "msfa/ringbuffer.h" #include "PluginFx.h" #include "EngineMkI.h" #include "EngineOpl.h" @@ -44,6 +45,12 @@ enum DexedEngineResolution { DEXED_ENGINE_OPL }; +#ifdef DEBUG + #define TRACE(fmt, ...) _trace(__PRETTY_FUNCTION__,fmt,##__VA_ARGS__) +#else + #define TRACE(fmt, ...) +#endif + //============================================================================== class DexedVoice : public lvtk::Voice @@ -54,14 +61,10 @@ class DexedVoice : public lvtk::Voice void on(unsigned char key, unsigned char velocity); void off(unsigned char velocity); unsigned char get_key(void) const; - void render(uint32_t from, uint32_t to); - void post_process(uint32_t from, uint32_t to); protected: unsigned char m_key; double m_rate; - ProcessorVoice voice; - char voice_number; }; //============================================================================== @@ -71,28 +74,39 @@ class Dexed : public lvtk::Synth public: Dexed(double rate); ~Dexed(); + int getEngineType(); + void setEngineType(int rs); + bool isMonoMode(); + void setMonoMode(bool mode); + void setParameter (int index, int newValue); + + uint8_t data[161]; + Controllers controllers; + VoiceStatus voiceStatus; protected: - // dexed internal + static const int MAX_ACTIVE_NOTES = 16; + ProcessorVoice voices[MAX_ACTIVE_NOTES]; + int currentNote; + bool sustain; + bool monoMode; + bool refreshVoice; + bool normalizeDxVelocity; + uint32_t engineType; + int feedback_bitdepth; + long lastStateSave; + PluginFx fx; + Lfo lfo; + FmCore engineMsfa; + EngineMkI engineMkI; + EngineOpl engineOpl; + int16_t* outbuf16_; + uint32_t bufsize_; }; // GLOBALS -char voice_counter=0; -EngineMkI engineMkI; -uint8_t feedback_bitdepth; -Lfo lfo; -Controllers controllers; - -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 +RingBuffer ring_buffer_; +//static const float scaler = 0.00003051757813; +static const float scaler = 0.00003; #endif // PLUGINPROCESSOR_H_INCLUDED diff --git a/src/msfa/ringbuffer.cc b/src/msfa/ringbuffer.cc new file mode 100644 index 0000000..5a40377 --- /dev/null +++ b/src/msfa/ringbuffer.cc @@ -0,0 +1,76 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "synth.h" +#include "ringbuffer.h" + +RingBuffer::RingBuffer() { + rd_ix_ = 0; + wr_ix_ = 0; +} + +int RingBuffer::BytesAvailable() { + return (wr_ix_ - rd_ix_) & (kBufSize - 1); +} + +int RingBuffer::WriteBytesAvailable() { + return (rd_ix_ - wr_ix_ - 1) & (kBufSize - 1); +} + +int RingBuffer::Read(int size, uint8_t *bytes) { + int rd_ix = rd_ix_; + SynthMemoryBarrier(); // read barrier, make sure data is committed before ix + int fragment_size = min(size, kBufSize - rd_ix); + memcpy(bytes, buf_ + rd_ix, fragment_size); + if (size > fragment_size) { + memcpy(bytes + fragment_size, buf_, size - fragment_size); + } + SynthMemoryBarrier(); // full barrier, make sure read commits before updating + rd_ix_ = (rd_ix + size) & (kBufSize - 1); + return size; +} + +int RingBuffer::Write(const uint8_t *bytes, int size) { + int remaining = size; + while (remaining > 0) { + int rd_ix = rd_ix_; + int wr_ix = wr_ix_; + int space_available = (rd_ix - wr_ix - 1) & (kBufSize - 1); + if (space_available == 0) { + struct timespec sleepTime; + sleepTime.tv_sec = 0; + sleepTime.tv_nsec = 1000000; + nanosleep(&sleepTime, NULL); + } else { + int wr_size = min(remaining, space_available); + int fragment_size = min(wr_size, kBufSize - wr_ix); + memcpy(buf_ + wr_ix, bytes, fragment_size); + if (wr_size > fragment_size) { + memcpy(buf_, bytes + fragment_size, wr_size - fragment_size); + } + SynthMemoryBarrier(); // write barrier, make sure data commits + wr_ix_ = (wr_ix + wr_size) & (kBufSize - 1); + remaining -= wr_size; + bytes += wr_size; + } + } + // JJK : defined as returning int + return 0; +} + diff --git a/src/msfa/ringbuffer.h b/src/msfa/ringbuffer.h new file mode 100644 index 0000000..c8c3e72 --- /dev/null +++ b/src/msfa/ringbuffer.h @@ -0,0 +1,44 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYNTH_RINGBUFFER_H_ +#define SYNTH_RINGBUFFER_H_ + +class RingBuffer { + public: + RingBuffer(); + + // Returns number of bytes available for reading. + int BytesAvailable(); + + // Returns number of bytes that can be written without blocking. + int WriteBytesAvailable(); + + // Reads bytes. It is the caller's responsibility to make sure that + // size <= a previous value of BytesAvailable(). + int Read(int size, uint8_t *bytes); + + // Writes bytes into the buffer. If the buffer is full, the method will + // block until space is available. + int Write(const uint8_t *bytes, int size); + private: + static const int kBufSize = 8192; + uint8_t buf_[kBufSize]; + volatile unsigned int rd_ix_; + volatile unsigned int wr_ix_; +}; + +#endif // SYNTH_RINGBUFFER_H_ diff --git a/src/DXComponents.h b/src/trash/DXComponents.h similarity index 100% rename from src/DXComponents.h rename to src/trash/DXComponents.h diff --git a/src/ParamDialog.h b/src/trash/ParamDialog.h similarity index 100% rename from src/ParamDialog.h rename to src/trash/ParamDialog.h diff --git a/src/SysexComm.cpp b/src/trash/SysexComm.cpp similarity index 100% rename from src/SysexComm.cpp rename to src/trash/SysexComm.cpp