summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-14 18:40:58 +0800
committerrekado <rekado@elephly.net>2013-01-14 20:59:38 +0800
commit9319944c9cae9da4fe40da7f72c3ea9d95689140 (patch)
tree0c419dca2365d7b33cd21e568055328d97452a53 /src
parent4f7d3d1a521bd3f49009b730c1088586223c9082 (diff)
move `process` to voice
Diffstat (limited to 'src')
-rw-r--r--src/mdaPiano.cpp86
-rw-r--r--src/mdaPiano.h1
-rw-r--r--src/mdaPianoVoice.cpp86
3 files changed, 86 insertions, 87 deletions
diff --git a/src/mdaPiano.cpp b/src/mdaPiano.cpp
index 8d1ca52..19cc0b1 100644
--- a/src/mdaPiano.cpp
+++ b/src/mdaPiano.cpp
@@ -83,92 +83,6 @@ void mdaPiano::setParameter(uint32_t index, float value)
}
-void mdaPiano::process(float **inputs, float **outputs, uint32_t sampleFrames)
-{
- float* out0 = outputs[0];
- float* out1 = outputs[1];
- uint32_t event=0, frame=0, frames, v;
- float x, l, r;
- uint32_t i;
-
- while(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
-
- while(--frames>=0)
- {
- VOICE *V = voice;
- l = r = 0.0f;
-
- for(v=0; v<activevoices; v++)
- {
- V->frac += V->delta; //integer-based linear interpolation
- V->pos += V->frac >> 16;
- V->frac &= 0xFFFF;
- if(V->pos > V->end) V->pos -= V->loop;
-
- i = waves[V->pos];
- i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000;
- x = V->env * (*(float *)&i - 3.0f); //fast int->float
-
- /////////////////////
- //TODO: This was used in processReplacing instead of the above
- /*
- //i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000; //not working on intel mac !?!
- i = waves[V->pos] + ((V->frac * (waves[V->pos + 1] - waves[V->pos])) >> 16);
- x = V->env * (float)i / 32768.0f;
- //x = V->env * (*(float *)&i - 3.0f); //fast int->float
- */
- /////////////////////
-
- V->env = V->env * V->dec; //envelope
- V->f0 += V->ff * (x + V->f1 - V->f0); //muffle filter
- V->f1 = x;
-
- l += V->outl * V->f0;
- r += V->outr * V->f0;
-
- //TODO: this was used in processReplacing
- /////////////////////
- /*
- if(!(l > -2.0f) || !(l < 2.0f))
- {
- printf("what is this shit? %d, %f, %f\n", i, x, V->f0);
- l = 0.0f;
- }
-if(!(r > -2.0f) || !(r < 2.0f))
- {
- r = 0.0f;
- }
- */
- /////////////////////
-
- V++;
- }
- comb[cpos] = l + r;
- ++cpos &= cmax;
- x = cdep * comb[cpos]; //stereo simulator
-
- // TODO: processReplacing simply assigned instead of adding
- *out0++ += l + x;
- *out1++ += r - x;
- }
-
- if(frame<sampleFrames)
- {
- uint32_t note = notes[event++];
- uint32_t vel = notes[event++];
- noteOn(note, vel);
- }
- }
- for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
-}
-
-
uint32_t mdaPiano::processEvents(VstEvents* ev)
{
uint32_t npos=0;
diff --git a/src/mdaPiano.h b/src/mdaPiano.h
index 56e5293..14de4fd 100644
--- a/src/mdaPiano.h
+++ b/src/mdaPiano.h
@@ -19,7 +19,6 @@ public:
void load_kgrp(KGRP*);
void load_samples(short**);
- virtual void process(float **inputs, float **outputs, uint32_t sampleframes);
virtual uint32_t processEvents(VstEvents* events);
virtual void setParameter(uint32_t index, float value);
diff --git a/src/mdaPianoVoice.cpp b/src/mdaPianoVoice.cpp
index 633fb5a..a1f9529 100644
--- a/src/mdaPianoVoice.cpp
+++ b/src/mdaPianoVoice.cpp
@@ -119,3 +119,89 @@ mdaPianoVoice::on(unsigned char note, unsigned char velocity)
}
}
}
+
+
+void mdaPianoVoice::process(float **inputs, float **outputs, uint32_t sampleFrames)
+{
+ float* out0 = outputs[0];
+ float* out1 = outputs[1];
+ uint32_t event=0, frame=0, frames, v;
+ float x, l, r;
+ uint32_t i;
+
+ while(frame<sampleFrames)
+ {
+ frames = notes[event++];
+ if(frames>sampleFrames) frames = sampleFrames;
+ frames -= frame;
+ frame += frames;
+
+ while(--frames>=0)
+ {
+ VOICE *V = voice;
+ l = r = 0.0f;
+
+ for(v=0; v<activevoices; v++)
+ {
+ V->frac += V->delta; //integer-based linear interpolation
+ V->pos += V->frac >> 16;
+ V->frac &= 0xFFFF;
+ if(V->pos > V->end) V->pos -= V->loop;
+
+ i = waves[V->pos];
+ i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000;
+ x = V->env * (*(float *)&i - 3.0f); //fast int->float
+
+ /////////////////////
+ //TODO: This was used in processReplacing instead of the above
+ /*
+ //i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000; //not working on intel mac !?!
+ i = waves[V->pos] + ((V->frac * (waves[V->pos + 1] - waves[V->pos])) >> 16);
+ x = V->env * (float)i / 32768.0f;
+ //x = V->env * (*(float *)&i - 3.0f); //fast int->float
+ */
+ /////////////////////
+
+ V->env = V->env * V->dec; //envelope
+ V->f0 += V->ff * (x + V->f1 - V->f0); //muffle filter
+ V->f1 = x;
+
+ l += V->outl * V->f0;
+ r += V->outr * V->f0;
+
+ //TODO: this was used in processReplacing
+ /////////////////////
+ /*
+ if(!(l > -2.0f) || !(l < 2.0f))
+ {
+ printf("what is this shit? %d, %f, %f\n", i, x, V->f0);
+ l = 0.0f;
+ }
+if(!(r > -2.0f) || !(r < 2.0f))
+ {
+ r = 0.0f;
+ }
+ */
+ /////////////////////
+
+ V++;
+ }
+ comb[cpos] = l + r;
+ ++cpos &= cmax;
+ x = cdep * comb[cpos]; //stereo simulator
+
+ // TODO: processReplacing simply assigned instead of adding
+ *out0++ += l + x;
+ *out1++ += r - x;
+ }
+
+ if(frame<sampleFrames)
+ {
+ uint32_t note = notes[event++];
+ uint32_t vel = notes[event++];
+ noteOn(note, vel);
+ }
+ }
+ for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
+ notes[0] = EVENTS_DONE; //mark events buffer as done
+}