aboutsummaryrefslogtreecommitdiffstats
path: root/src/product.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/product.c')
-rw-r--r--src/product.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/src/product.c b/src/product.c
index 194a071..ea07ee6 100644
--- a/src/product.c
+++ b/src/product.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 PRODUCT_MULTIPLICAND 0
#define PRODUCT_MULTIPLIER 1
#define PRODUCT_PRODUCT 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;
} Product;
static void
@@ -51,10 +52,10 @@ connect_port(LV2_Handle instance,
switch (port) {
case PRODUCT_MULTIPLICAND:
- plugin->input1 = (float*)data;
+ plugin->input1 = (const float*)data;
break;
case PRODUCT_MULTIPLIER:
- plugin->input2 = (float*)data;
+ plugin->input2 = (const float*)data;
break;
case PRODUCT_PRODUCT:
plugin->output = (float*)data;
@@ -95,7 +96,7 @@ port_type(LV2_Handle instance,
uint32_t port,
LV2_Morph_Property*const* properties)
{
- Product* plugin = (Product*)instance;
+ const Product* plugin = (const Product*)instance;
switch (port) {
case PRODUCT_PRODUCT:
@@ -131,26 +132,14 @@ static void
run(LV2_Handle instance,
uint32_t sample_count)
{
- Product* plugin = (Product*)instance;
-
- /* First Input (array of floats of length 1 or sample_count) */
- const float* input1 = plugin->input1;
-
- /* Second Input (array of floats of length 1 or 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 Product* const plugin = (Product*)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*