diff options
author | David Robillard <d@drobilla.net> | 2012-05-31 06:23:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-31 06:23:57 +0000 |
commit | 7b20413c84b14d2c2bc1037bb08134dcdf152ddb (patch) | |
tree | c7c339d6c4d0d26b01e654163e7a8a203f62baf4 /src/square.c | |
parent | 46caaf6b96f185a4a25d1d12fc85720a03220e97 (diff) | |
download | blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.tar.gz blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.tar.bz2 blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.zip |
Umm... commit pretty much all the work of the past few days. Again.
git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/blop.lv2@4488 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/square.c')
-rw-r--r-- | src/square.c | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/src/square.c b/src/square.c index fb78859..59dd22f 100644 --- a/src/square.c +++ b/src/square.c @@ -18,7 +18,9 @@ */ #include <stdlib.h> +#include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "uris.h" #include "wavedata.h" #define SQUARE_FREQUENCY 0 @@ -28,7 +30,9 @@ typedef struct { float* frequency; float* output; float phase; + uint32_t frequency_is_cv; Wavedata wdat; + URIs uris; } Square; static void @@ -48,6 +52,23 @@ 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) +{ + Square* plugin = (Square*)instance; + if (type == plugin->uris.lv2_ControlPort) { + plugin->frequency_is_cv = 0; + } else if (type == plugin->uris.lv2_CVPort) { + plugin->frequency_is_cv = 1; + } else { + return LV2_MORPH_ERR_BAD_TYPE; + } + return LV2_MORPH_SUCCESS; +} + static LV2_Handle instantiate(const LV2_Descriptor* descriptor, double sample_rate, @@ -55,6 +76,9 @@ instantiate(const LV2_Descriptor* descriptor, const LV2_Feature* const* features) { Square* plugin = (Square*)malloc(sizeof(Square)); + if (!plugin) { + return NULL; + } if (wavedata_load(&plugin->wdat, bundle_path, "square_data", BLOP_DLSYM_SQUARE, sample_rate)) { @@ -62,6 +86,10 @@ instantiate(const LV2_Descriptor* descriptor, return NULL; } + plugin->frequency_is_cv = 0; + map_uris(&plugin->uris, features); + wavedata_get_table(&plugin->wdat, 440.0); + return (LV2_Handle)plugin; } @@ -83,8 +111,8 @@ activate(LV2_Handle instance) } static void -runSquare_fa_oa(LV2_Handle instance, - uint32_t sample_count) +run(LV2_Handle instance, + uint32_t sample_count) { Square* plugin = (Square*)instance; @@ -99,8 +127,11 @@ runSquare_fa_oa(LV2_Handle instance, float phase = plugin->phase; for (uint32_t s = 0; s < sample_count; ++s) { - /* Get table to play */ - wavedata_get_table(wdat, frequency[s]); + const float freq = frequency[s * plugin->frequency_is_cv]; + if (freq != wdat->frequency) { + /* Frequency changed, look up table to play */ + wavedata_get_table(wdat, freq); + } /* Get interpolated sample */ output[s] = wavedata_get_sample(wdat, phase); @@ -116,47 +147,25 @@ runSquare_fa_oa(LV2_Handle instance, plugin->phase = phase; } -static void -runSquare_fc_oa(LV2_Handle instance, - uint32_t sample_count) +static const void* +extension_data(const char* uri) { - Square* plugin = (Square*)instance; - - /* Frequency (float value) */ - const float frequency = *(plugin->frequency); - - /* Output (pointer to float value) */ - float* output = plugin->output; - - /* Instance data */ - Wavedata* wdat = &plugin->wdat; - float phase = plugin->phase; - - wavedata_get_table(wdat, frequency); - - for (uint32_t s = 0; s < sample_count; ++s) { - output[s] = wavedata_get_sample(wdat, phase); - - /* Update phase, wrapping if necessary */ - phase += wdat->frequency; - if (phase < 0.0f) { - phase += wdat->sample_rate; - } else if (phase > wdat->sample_rate) { - phase -= wdat->sample_rate; - } + static const LV2_Morph_Interface morph = { morph_port, NULL }; + if (!strcmp(uri, LV2_MORPH__interface)) { + return &morph; } - plugin->phase = phase; + return NULL; } static const LV2_Descriptor descriptor = { - "http://drobilla.net/plugins/blip/square", + "http://drobilla.net/plugins/blop/square", instantiate, connect_port, activate, - runSquare_fc_oa, + run, NULL, cleanup, - NULL, + extension_data, }; LV2_SYMBOL_EXPORT const LV2_Descriptor* |