diff options
Diffstat (limited to 'src/tracker.c')
-rw-r--r-- | src/tracker.c | 155 |
1 files changed, 76 insertions, 79 deletions
diff --git a/src/tracker.c b/src/tracker.c index 706c8a1..cb93bf8 100644 --- a/src/tracker.c +++ b/src/tracker.c @@ -18,10 +18,8 @@ */ #include <stdlib.h> -#include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" #include "common.h" -#include "uris.h" #define TRACKER_GATE 0 #define TRACKER_HATTACK 1 @@ -32,20 +30,15 @@ #define TRACKER_OUTPUT 6 typedef struct { - float* gate; - float* hattack; - float* hdecay; - float* lattack; - float* ldecay; - float* input; - float* output; - float coeff; - float last_value; - uint32_t hattack_is_cv; - uint32_t hdecay_is_cv; - uint32_t lattack_is_cv; - uint32_t ldecay_is_cv; - URIs uris; + float* gate; + float* hattack; + float* hdecay; + float* lattack; + float* ldecay; + float* input; + float* output; + float coeff; + float last_value; } Tracker; static void @@ -86,39 +79,6 @@ connect_port(LV2_Handle instance, } } -static LV2_Morph_Status -morph_port(LV2_Handle instance, - uint32_t port, - LV2_URID type, - const LV2_Morph_Property*const* properties) -{ - Tracker* plugin = (Tracker*)instance; - - if (type != plugin->uris.lv2_ControlPort && - type != plugin->uris.lv2_CVPort) { - return LV2_MORPH_ERR_BAD_TYPE; - } - - switch (port) { - case TRACKER_HATTACK: - plugin->hattack_is_cv = (type == plugin->uris.lv2_CVPort); - break; - case TRACKER_HDECAY: - plugin->hdecay_is_cv = (type == plugin->uris.lv2_CVPort); - break; - case TRACKER_LATTACK: - plugin->lattack_is_cv = (type == plugin->uris.lv2_CVPort); - break; - case TRACKER_LDECAY: - plugin->ldecay_is_cv = (type == plugin->uris.lv2_CVPort); - break; - default: - return LV2_MORPH_ERR_BAD_PORT; - } - - return LV2_MORPH_SUCCESS; -} - static LV2_Handle instantiate(const LV2_Descriptor* descriptor, double sample_rate, @@ -129,13 +89,6 @@ instantiate(const LV2_Descriptor* descriptor, plugin->coeff = 2.0f * M_PI / (float)sample_rate; - plugin->hattack_is_cv = 0; - plugin->hdecay_is_cv = 0; - plugin->lattack_is_cv = 0; - plugin->ldecay_is_cv = 0; - - map_uris(&plugin->uris, features); - return (LV2_Handle)plugin; } @@ -148,24 +101,24 @@ activate(LV2_Handle instance) } static void -run(LV2_Handle instance, - uint32_t sample_count) +runTracker_gaaadaia_oa(LV2_Handle instance, + uint32_t sample_count) { Tracker* plugin = (Tracker*)instance; /* Gate (array of floats of length sample_count) */ const float* gate = plugin->gate; - /* Gate High Attack Rate (array of floats of length 1 or sample_count) */ + /* Gate High Attack Rate (array of floats of length sample_count) */ const float* hattack = plugin->hattack; - /* Gate High Decay Rate (array of floats of length 1 or sample_count) */ + /* Gate High Decay Rate (array of floats of length sample_count) */ const float* hdecay = plugin->hdecay; - /* Gate Low Attack Rate (array of floats of length 1 or sample_count) */ + /* Gate Low Attack Rate (array of floats of length sample_count) */ const float* lattack = plugin->lattack; - /* Gate Low Decay Rate (array of floats of length 1 or sample_count) */ + /* Gate Low Decay Rate (array of floats of length sample_count) */ const float* ldecay = plugin->ldecay; /* Input (array of floats of length sample_count) */ @@ -178,18 +131,16 @@ run(LV2_Handle instance, float coeff = plugin->coeff; float last_value = plugin->last_value; + float rate; + float in; + for (uint32_t s = 0; s < sample_count; ++s) { - const float in = input[s]; - const float ha = hattack[s * plugin->hattack_is_cv]; - const float hd = hdecay[s * plugin->hdecay_is_cv]; - const float la = lattack[s * plugin->lattack_is_cv]; - const float ld = ldecay[s * plugin->ldecay_is_cv]; + in = input[s]; - float rate; if (gate[s] > 0.0f) { - rate = in > last_value ? ha : hd; + rate = in > last_value ? hattack[s] : hdecay[s]; } else { - rate = in > last_value ? la : ld; + rate = in > last_value ? lattack[s] : ldecay[s]; } rate = f_min(1.0f, rate * coeff); @@ -201,25 +152,71 @@ run(LV2_Handle instance, plugin->last_value = last_value; } -static const void* -extension_data(const char* uri) +static void +runTracker_gaacdcia_oa(LV2_Handle instance, + uint32_t sample_count) { - static const LV2_Morph_Interface morph = { morph_port, NULL }; - if (!strcmp(uri, LV2_MORPH__interface)) { - return &morph; + Tracker* plugin = (Tracker*)instance; + + /* Gate (array of floats of length sample_count) */ + const float* gate = plugin->gate; + + /* Gate High Attack Rate (float value) */ + float hattack = *(plugin->hattack); + + /* Gate High Decay Rate (float value) */ + float hdecay = *(plugin->hdecay); + + /* Gate Low Attack Rate (float value) */ + float lattack = *(plugin->lattack); + + /* Gate Low Decay Rate (float value) */ + float ldecay = *(plugin->ldecay); + + /* Input (array of floats of length sample_count) */ + const float* input = plugin->input; + + /* Output (array of floats of length sample_count) */ + float* output = plugin->output; + + /* Instance Data */ + float coeff = plugin->coeff; + float last_value = plugin->last_value; + + float in; + float rate; + + hattack = f_min(1.0f, hattack * coeff); + hdecay = f_min(1.0f, hdecay * coeff); + lattack = f_min(1.0f, lattack * coeff); + ldecay = f_min(1.0f, ldecay * coeff); + + for (uint32_t s = 0; s < sample_count; ++s) { + in = input[s]; + + if (gate[s] > 0.0f) { + rate = in > last_value ? hattack : hdecay; + } else { + rate = in > last_value ? lattack : ldecay; + } + + last_value = last_value * (1.0f - rate) + in * rate; + + output[s] = last_value; } - return NULL; + + plugin->last_value = last_value; } static const LV2_Descriptor descriptor = { - "http://drobilla.net/plugins/blop/tracker", + "http://drobilla.net/plugins/blip/tracker", instantiate, connect_port, activate, - run, + runTracker_gaacdcia_oa, NULL, cleanup, - extension_data, + NULL, }; LV2_SYMBOL_EXPORT const LV2_Descriptor* |