summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-16 08:13:38 +0800
committerrekado <rekado@elephly.net>2013-01-16 08:13:38 +0800
commit059fa5f432c7584126b3de2ea63d91ec303af4c3 (patch)
treeab47f574046e024387d9217f5207a318aa10b83a
parent8756fad2507a864288f8afa7c82354e5dc4146c0 (diff)
convert process into render
-rw-r--r--src/mdaPianoVoice.cpp132
-rw-r--r--src/mdaPianoVoice.h3
2 files changed, 61 insertions, 74 deletions
diff --git a/src/mdaPianoVoice.cpp b/src/mdaPianoVoice.cpp
index a59aee1..d45fee0 100644
--- a/src/mdaPianoVoice.cpp
+++ b/src/mdaPianoVoice.cpp
@@ -51,7 +51,7 @@ void mdaPianoVoice::on(unsigned char note, unsigned char velocity)
m_key = note;
float l=99.0f;
- uint32_t v, k, s;
+ uint32_t k, s;
if(velocity>0)
{
@@ -138,89 +138,73 @@ void mdaPianoVoice::release(unsigned char velocity)
}
-void mdaPianoVoice::process(float **inputs, float **outputs, uint32_t sampleFrames)
+void mdaPianoVoice::render(uint32_t from, uint32_t to)
{
- float* out0 = outputs[0];
- float* out1 = outputs[1];
- uint32_t event=0, frame=0, frames, v;
+ uint32_t v;
float x, l, r;
uint32_t i;
- while(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
+ for (uint32_t frame = from; frame < to; ++frame) {
+ VOICE *V = voice;
+ l = r = 0.0f;
- while(--frames>=0)
+ for(v=0; v<activevoices; v++)
{
- 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;
- }
+ 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;
- }
+{
+ r = 0.0f;
+}
+ */
+ /////////////////////
- if(frame<sampleFrames)
- {
- uint32_t note = notes[event++];
- uint32_t vel = notes[event++];
- noteOn(note, vel);
+ V++;
}
+ comb[cpos] = l + r;
+ ++cpos &= cmax;
+ x = cdep * comb[cpos]; //stereo simulator
+
+ // TODO: processReplacing simply assigned instead of adding
+ // write to output
+ p(p_left)[frame] += l + x;
+ p(p_right)[frame] += r - x;
}
- for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
+
+ // TODO: move this away
+ //for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
}
diff --git a/src/mdaPianoVoice.h b/src/mdaPianoVoice.h
index e50c176..12e0c49 100644
--- a/src/mdaPianoVoice.h
+++ b/src/mdaPianoVoice.h
@@ -61,6 +61,9 @@ class mdaPianoVoice : public LV2::Voice {
void reset(void);
bool is_sustained(void) { return (note == SUSTAIN); }
unsigned char get_key(void) const { return m_key; }
+
+ // generates the sound for this voice
+ void render(uint32_t, uint32_t);
};
#endif