aboutsummaryrefslogtreecommitdiffstats
path: root/src/sawtooth.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-31 06:03:45 +0000
committerDavid Robillard <d@drobilla.net>2012-05-31 06:03:45 +0000
commit8b46fd1ff51b29cded517c9c2d166611e8c453fc (patch)
tree14a338294d302e663818570796bb5311297a9748 /src/sawtooth.c
parent9529f203c09d6dc8f4c2f12c3add9ec906f4bdba (diff)
downloadblop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.tar.gz
blop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.tar.bz2
blop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.zip
Blip => Blop. I give up trying to give ports new names.
git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/blop.lv2@4484 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/sawtooth.c')
-rw-r--r--src/sawtooth.c78
1 files changed, 42 insertions, 36 deletions
diff --git a/src/sawtooth.c b/src/sawtooth.c
index 3c242e1..0af927e 100644
--- a/src/sawtooth.c
+++ b/src/sawtooth.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 SAWTOOTH_FREQUENCY 0
@@ -28,7 +30,9 @@ typedef struct {
float* frequency;
float* output;
float phase;
+ uint32_t frequency_is_cv;
Wavedata wdat;
+ URIs uris;
} Sawtooth;
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)
+{
+ Sawtooth* plugin = (Sawtooth*)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,
@@ -62,6 +83,10 @@ instantiate(const LV2_Descriptor* descriptor,
return 0;
}
+ plugin->frequency_is_cv = 0;
+ map_uris(&plugin->uris, features);
+ wavedata_get_table(&plugin->wdat, 440.0);
+
return (LV2_Handle)plugin;
}
@@ -83,12 +108,12 @@ activate(LV2_Handle instance)
}
static void
-runSawtooth_fa_oa(LV2_Handle instance,
- uint32_t sample_count)
+run(LV2_Handle instance,
+ uint32_t sample_count)
{
Sawtooth* plugin = (Sawtooth*)instance;
- /* Frequency (array of float of length sample_count) */
+ /* Frequency (array of float of length 1 or sample_count) */
const float* frequency = plugin->frequency;
/* Output (pointer to float value) */
@@ -99,8 +124,11 @@ runSawtooth_fa_oa(LV2_Handle instance,
float phase = plugin->phase;
for (uint32_t s = 0; s < sample_count; s++) {
- /* Lookup 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);
+ }
output[s] = wavedata_get_sample(wdat, phase);
@@ -115,47 +143,25 @@ runSawtooth_fa_oa(LV2_Handle instance,
plugin->phase = phase;
}
-static void
-runSawtooth_fc_oa(LV2_Handle instance,
- uint32_t sample_count)
+static const void*
+extension_data(const char* uri)
{
- Sawtooth* plugin = (Sawtooth*)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/sawtooth",
+ "http://drobilla.net/plugins/blop/sawtooth",
instantiate,
connect_port,
activate,
- runSawtooth_fc_oa,
+ run,
NULL,
cleanup,
- NULL,
+ extension_data,
};
LV2_SYMBOL_EXPORT const LV2_Descriptor*