aboutsummaryrefslogtreecommitdiffstats
path: root/src/sum.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sum.c')
-rw-r--r--src/sum.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/src/sum.c b/src/sum.c
index 5c9c1c6..5665447 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -21,19 +21,20 @@
#include "lv2/lv2plug.in/ns/ext/morph/morph.h"
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
#include "uris.h"
+#include "vector_op.h"
#define SUM_INPUT1 0
#define SUM_INPUT2 1
#define SUM_OUTPUT 2
typedef struct {
- float* input1;
- float* input2;
- float* output;
- uint32_t input1_is_cv;
- uint32_t input2_is_cv;
- uint32_t output_is_cv;
- URIs uris;
+ const float* input1;
+ const float* input2;
+ float* output;
+ uint32_t input1_is_cv;
+ uint32_t input2_is_cv;
+ uint32_t output_is_cv;
+ URIs uris;
} Sum;
static void
@@ -51,10 +52,10 @@ connect_port(LV2_Handle instance,
switch (port) {
case SUM_INPUT1:
- plugin->input1 = (float*)data;
+ plugin->input1 = (const float*)data;
break;
case SUM_INPUT2:
- plugin->input2 = (float*)data;
+ plugin->input2 = (const float*)data;
break;
case SUM_OUTPUT:
plugin->output = (float*)data;
@@ -95,7 +96,7 @@ port_type(LV2_Handle instance,
uint32_t port,
LV2_Morph_Property*const* properties)
{
- Sum* plugin = (Sum*)instance;
+ const Sum* plugin = (const Sum*)instance;
switch (port) {
case SUM_OUTPUT:
@@ -130,26 +131,14 @@ static void
run(LV2_Handle instance,
uint32_t sample_count)
{
- Sum* plugin = (Sum*)instance;
-
- /* First Input (array of floats of length sample_count) */
- const float* input1 = plugin->input1;
-
- /* Second Input (array of floats of length sample_count) */
- const float* input2 = plugin->input2;
-
- /* Output (array of floats of length sample_count) */
- float* output = plugin->output;
-
- if (!plugin->output_is_cv) { /* TODO: Avoid this branch */
- sample_count = 1;
- }
-
- for (uint32_t s = 0; s < sample_count; ++s) {
- const float in1 = input1[s * plugin->input1_is_cv];
- const float in2 = input2[s * plugin->input2_is_cv];
- output[s] = in1 + in2;
- }
+ const Sum* const plugin = (Sum*)instance;
+ const float* const input1 = plugin->input1;
+ const float* const input2 = plugin->input2;
+ float* const output = plugin->output;
+
+ VECTOR_OP(+, output,
+ input1, plugin->input1_is_cv,
+ input2, plugin->input2_is_cv);
}
static const void*