diff options
Diffstat (limited to 'src/sync_pulse.c')
-rw-r--r-- | src/sync_pulse.c | 116 |
1 files changed, 60 insertions, 56 deletions
diff --git a/src/sync_pulse.c b/src/sync_pulse.c index 14d9c8d..96f90c7 100644 --- a/src/sync_pulse.c +++ b/src/sync_pulse.c @@ -19,9 +19,7 @@ */ #include <stdlib.h> -#include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" -#include "uris.h" #include "common.h" #define SYNCPULSE_FREQUENCY 0 @@ -30,15 +28,12 @@ #define SYNCPULSE_OUTPUT 3 typedef struct { - float* frequency; - float* pulsewidth; - float* gate; - float* output; - float srate; - float phase; - uint32_t frequency_is_cv; - uint32_t pulsewidth_is_cv; - URIs uris; + float* frequency; + float* pulsewidth; + float* gate; + float* output; + float srate; + float phase; } SyncPulse; static void @@ -70,33 +65,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) -{ - SyncPulse* plugin = (SyncPulse*)instance; - - if (type != plugin->uris.lv2_ControlPort && - type != plugin->uris.lv2_CVPort) { - return LV2_MORPH_ERR_BAD_TYPE; - } - - switch (port) { - case SYNCPULSE_FREQUENCY: - plugin->frequency_is_cv = (type == plugin->uris.lv2_CVPort); - break; - case SYNCPULSE_PULSEWIDTH: - plugin->pulsewidth_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, @@ -105,10 +73,7 @@ instantiate(const LV2_Descriptor* descriptor, { SyncPulse* plugin = (SyncPulse*)malloc(sizeof(SyncPulse)); - plugin->srate = (float)sample_rate; - plugin->frequency_is_cv = 0; - plugin->pulsewidth_is_cv = 0; - map_uris(&plugin->uris, features); + plugin->srate = (float)sample_rate; return (LV2_Handle)plugin; } @@ -122,8 +87,8 @@ activate(LV2_Handle instance) } static void -run(LV2_Handle instance, - uint32_t sample_count) +runSyncPulse_fapaga_oa(LV2_Handle instance, + uint32_t sample_count) { SyncPulse* plugin = (SyncPulse*)instance; @@ -143,11 +108,13 @@ run(LV2_Handle instance, float phase = plugin->phase; float srate = plugin->srate; + float freq; + float pwidth; + for (uint32_t s = 0; s < sample_count; ++s) { if (gate[s] > 0.0f) { - const float freq = frequency[s * plugin->frequency_is_cv]; - const float pw = pulsewidth[s * plugin->pulsewidth_is_cv]; - const float pwidth = f_clip(pw, 0.0f, 1.0f) * srate; + freq = frequency[s]; + pwidth = f_clip(pulsewidth[s], 0.0f, 1.0f) * srate; if (phase < pwidth) { output[s] = 1.0f; @@ -170,25 +137,62 @@ run(LV2_Handle instance, plugin->phase = phase; } -static const void* -extension_data(const char* uri) +static void +runSyncPulse_fcpcga_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; + SyncPulse* plugin = (SyncPulse*)instance; + + /* Frequency (float value) */ + const float frequency = *(plugin->frequency); + + /* Pulse Width (float value) */ + float pulsewidth = f_clip(*(plugin->pulsewidth), 0.0f, 1.0f); + + /* Gate (array of float of length sample_count) */ + const float* gate = plugin->gate; + + /* Output (pointer to float value) */ + float* output = plugin->output; + + /* Instance Data */ + float phase = plugin->phase; + float srate = plugin->srate; + + pulsewidth *= srate; + + for (uint32_t s = 0; s < sample_count; ++s) { + if (gate[s] > 0.0f) { + if (phase < pulsewidth) { + output[s] = 1.0f; + } else { + output[s] = -1.0f; + } + + phase += frequency; + if (phase < 0.0f) { + phase += srate; + } else if (phase > srate) { + phase -= srate; + } + } else { + output[s] = 0.0f; + phase = 0.0f; + } } - return NULL; + + plugin->phase = phase; } static const LV2_Descriptor descriptor = { - "http://drobilla.net/plugins/blop/sync_pulse", + "http://drobilla.net/plugins/blip/sync_pulse", instantiate, connect_port, activate, - run, + runSyncPulse_fcpcga_oa, NULL, cleanup, - extension_data, + NULL, }; LV2_SYMBOL_EXPORT const LV2_Descriptor* |