aboutsummaryrefslogtreecommitdiffstats
path: root/src/square.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/square.c')
-rw-r--r--src/square.c76
1 files changed, 35 insertions, 41 deletions
diff --git a/src/square.c b/src/square.c
index 3e7f78f..fb78859 100644
--- a/src/square.c
+++ b/src/square.c
@@ -18,9 +18,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 "wavedata.h"
#define SQUARE_FREQUENCY 0
@@ -30,9 +28,7 @@ typedef struct {
float* frequency;
float* output;
float phase;
- uint32_t frequency_is_cv;
Wavedata wdat;
- URIs uris;
} Square;
static void
@@ -52,23 +48,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)
-{
- 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,
@@ -83,10 +62,6 @@ 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;
}
@@ -108,8 +83,8 @@ activate(LV2_Handle instance)
}
static void
-run(LV2_Handle instance,
- uint32_t sample_count)
+runSquare_fa_oa(LV2_Handle instance,
+ uint32_t sample_count)
{
Square* plugin = (Square*)instance;
@@ -124,11 +99,8 @@ run(LV2_Handle instance,
float phase = plugin->phase;
for (uint32_t s = 0; s < sample_count; ++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 table to play */
+ wavedata_get_table(wdat, frequency[s]);
/* Get interpolated sample */
output[s] = wavedata_get_sample(wdat, phase);
@@ -144,25 +116,47 @@ run(LV2_Handle instance,
plugin->phase = phase;
}
-static const void*
-extension_data(const char* uri)
+static void
+runSquare_fc_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;
+ 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;
+ }
}
- return NULL;
+ plugin->phase = phase;
}
static const LV2_Descriptor descriptor = {
- "http://drobilla.net/plugins/blop/square",
+ "http://drobilla.net/plugins/blip/square",
instantiate,
connect_port,
activate,
- run,
+ runSquare_fc_oa,
NULL,
cleanup,
- extension_data,
+ NULL,
};
LV2_SYMBOL_EXPORT const LV2_Descriptor*