summaryrefslogtreecommitdiffstats
path: root/super_saw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'super_saw.cpp')
-rw-r--r--super_saw.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/super_saw.cpp b/super_saw.cpp
new file mode 100644
index 0000000..2ce1156
--- /dev/null
+++ b/super_saw.cpp
@@ -0,0 +1,69 @@
+#include <lv2synth.hpp>
+#include "super_saw.peg"
+#include <stdio.h>
+#include <math.h>
+extern "C" void adainit(void);
+extern "C" void adafinal(void);
+extern "C" float Super_Saw(float,float,float,float,float);
+
+class SuperSawVoice : public LV2::Voice {
+public:
+
+ SuperSawVoice(double rate)
+ : m_key(LV2::INVALID_KEY), m_rate(rate), m_period(10), m_counter(0) {
+ }
+
+ void on(unsigned char key, unsigned char velocity) {
+ m_key = key;
+ m_period = m_rate / LV2::key2hz(m_key);
+ }
+
+ void off(unsigned char velocity) {
+ m_key = LV2::INVALID_KEY;
+ }
+
+ unsigned char get_key() const {
+ return m_key;
+ }
+
+ void render(uint32_t from, uint32_t to) {
+ if (m_key == LV2::INVALID_KEY)
+ return;
+ for (uint32_t i = from; i < to; ++i) {
+ //Time, Pitch, Detune, Mix, Sample Rate
+ float detune = *p(p_Detune);
+ float mix = *p(p_Mix);
+ float s = Super_Saw(m_counter,LV2::key2hz(m_key),detune,mix,m_rate)/100.0;
+ p(p_left)[i] += s;
+ p(p_right)[i] += s;
+ m_counter = (m_counter + 1);// % m_period;
+ }
+ }
+
+protected:
+
+ unsigned char m_key;
+ double m_rate;
+ uint32_t m_period;
+ uint32_t m_counter;
+
+};
+
+
+class SuperSaw : public LV2::Synth<SuperSawVoice, SuperSaw> {
+public:
+ SuperSaw(double rate)
+ : LV2::Synth<SuperSawVoice, SuperSaw>(p_n_ports, p_midi) {
+ adainit();
+ add_voices(new SuperSawVoice(rate), new SuperSawVoice(rate), new SuperSawVoice(rate));
+ add_audio_outputs(p_left, p_right);
+ printf("Created object");
+ }
+ ~SuperSaw(){
+ adafinal();
+ }
+};
+
+
+static int _ = SuperSaw::register_class(p_uri);
+