summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-14 08:33:29 +0800
committerrekado <rekado@elephly.net>2013-01-14 17:46:52 +0800
commit8952fd3bd059645228d2a096775261fca05bc60d (patch)
tree5f391b5466020f6bd5781af43bddddcc51ca0ecb
parent772db9ce89841d0f2ecb377c76822241c6eb1fb7 (diff)
begin moving voice-related stuff to mdaPianoVoice
-rw-r--r--src/mdaPiano.cpp41
-rw-r--r--src/mdaPiano.h2
-rw-r--r--src/mdaPianoVoice.cpp41
-rw-r--r--src/mdaPianoVoice.h51
4 files changed, 95 insertions, 40 deletions
diff --git a/src/mdaPiano.cpp b/src/mdaPiano.cpp
index 11c6fa4..f88e062 100644
--- a/src/mdaPiano.cpp
+++ b/src/mdaPiano.cpp
@@ -21,55 +21,16 @@
#define STRING_BUF 2048
static const char* sample_file = "samples.raw";
-mdaPianoProgram::mdaPianoProgram()
-{
- param[0] = 0.50f; //Decay
- param[1] = 0.50f; //Release
- param[2] = 0.50f; //Hardness
-
- param[3] = 0.50f; //Vel>Hard
- param[4] = 1.00f; //Muffle
- param[5] = 0.50f; //Vel>Muff
-
- param[6] = 0.33f; //Vel Curve
- param[7] = 0.50f; //Stereo
- param[8] = 0.33f; //Max Poly
-
- param[9] = 0.50f; //Tune
- param[10] = 0.00f; //Random
- param[11] = 0.50f; //Stretch
-
- strcpy (name, "mda Piano");
-}
-
mdaPiano::mdaPiano(double rate)
: LV2::Synth<mdaPianoVoice, mdaPiano>(NPROGS, NPARAMS)
{
- Fs = 44100.0f; iFs = 1.0f/Fs; cmax = 0x7F; //just in case...
-
- programs = new mdaPianoProgram[NPROGS];
- if(programs)
- {
- //fill patches...
- uint32_t i=0;
- //TODO: load initial values from default preset
- fillpatch(i++, "mda Piano", 0.500f, 0.500f, 0.500f, 0.5f, 0.803f, 0.251f, 0.376f, 0.500f, 0.330f, 0.500f, 0.246f, 0.500f);
- setProgram(0);
- }
+ cmax = 0x7F; //just in case...
load_samples(&waves);
load_kgrp(kgrp);
- //initialise...
- for(uint32_t v=0; v<NVOICES; v++)
- {
- voice[v].env = 0.0f;
- voice[v].dec = 0.99f; //all notes off
- }
notes[0] = EVENTS_DONE;
- volume = 0.2f;
- muff = 160.0f;
cpos = sustain = activevoices = 0;
comb = new float[256];
diff --git a/src/mdaPiano.h b/src/mdaPiano.h
index c8a02a3..d8449c7 100644
--- a/src/mdaPiano.h
+++ b/src/mdaPiano.h
@@ -4,6 +4,8 @@
#define __mdaPiano__
#pragma GCC system_header
+#include "mdaPianoVoice.h"
+#include "mdaPiano.peg"
#include <lv2synth.hpp>
#include <string.h>
diff --git a/src/mdaPianoVoice.cpp b/src/mdaPianoVoice.cpp
new file mode 100644
index 0000000..1223e43
--- /dev/null
+++ b/src/mdaPianoVoice.cpp
@@ -0,0 +1,41 @@
+#include "mdaPianoVoice.h"
+
+mdaPianoVoice::mdaPianoVoice(double rate, short * samples, KGRP * master_kgrp) {
+ //set tuning
+ Fs = rate;
+ iFs = 1.0f/Fs;
+
+ waves = samples;
+ kgrp = master_kgrp;
+
+ default_preset[p_offset(p_envelope_decay)] = 0.500f;
+ default_preset[p_offset(p_envelope_release)] = 0.500f;
+ default_preset[p_offset(p_hardness_offset)] = 0.500f;
+ default_preset[p_offset(p_velocity_to_hardness)] = 0.500f;
+ default_preset[p_offset(p_muffling_filter)] = 0.803f;
+ default_preset[p_offset(p_velocity_to_muffling)] = 0.251f;
+ default_preset[p_offset(p_velocity_sensitivity)] = 0.376f;
+ default_preset[p_offset(p_stereo_width)] = 0.500f;
+ default_preset[p_offset(p_polyphony)] = 0.330f;
+ default_preset[p_offset(p_fine_tuning)] = 0.500f;
+ default_preset[p_offset(p_random_detuning)] = 0.246f;
+ default_preset[p_offset(p_stretch_tuning)] = 0.500f;
+
+ reset();
+}
+
+
+void mdaPianoVoice::reset() {
+ env = 0.0f;
+ dec = 0.99f;
+ muff = 160.0f;
+ volume = 0.2f;
+}
+
+
+float mdaPianoVoice::p_helper(unsigned short id, Param d) {
+ if (d == Default)
+ return default_preset[p_offset(id)];
+ else
+ return *p(id);
+}
diff --git a/src/mdaPianoVoice.h b/src/mdaPianoVoice.h
new file mode 100644
index 0000000..86a1c2a
--- /dev/null
+++ b/src/mdaPianoVoice.h
@@ -0,0 +1,51 @@
+#ifndef MDA_PIANO_VOICE_H
+#define MDA_PIANO_VOICE_H
+
+#include "mdaPianoCommon.h"
+#include "mdaPiano.peg"
+
+#pragma GCC system_header
+#include <lv2synth.hpp>
+
+enum Param {
+ Default,
+ Current
+};
+
+class mdaPianoVoice : public LV2::Voice {
+ private:
+ float Fs, iFs;
+
+ /// global internal variables
+ KGRP *kgrp;
+ short *waves;
+ float default_preset[NPARAMS]; // contains the default preset
+
+ // voice state
+ uint32_t delta; //sample playback
+ uint32_t frac;
+ uint32_t pos;
+ uint32_t end;
+ uint32_t loop;
+
+ float env; //envelope
+ float dec;
+
+ float f0; //first-order LPF
+ float f1;
+ float ff;
+
+ float outl;
+ float outr;
+ uint32_t note; //remember what note triggered this
+ // end of voice state
+
+
+ public:
+ mdaPianoVoice(double, short*, KGRP*);
+
+ float p_helper(unsigned short, Param);
+ void reset(void);
+};
+
+#endif