summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-19 21:41:14 +0800
committerrekado <rekado@elephly.net>2013-01-19 21:57:22 +0800
commitdda62de3830503e45ee809aa0492dfc6c386e5c8 (patch)
tree7df1e1889c86ba7aa84a4cf931e5feac501a402a
parente55e6f5ae2fb57bb8a2c341fa1cc726195aae2ed (diff)
set pos = 0 and get end from sample size
-rw-r--r--src/mdaPianoVoice.cpp15
-rw-r--r--src/mdaPianoVoice.h5
2 files changed, 11 insertions, 9 deletions
diff --git a/src/mdaPianoVoice.cpp b/src/mdaPianoVoice.cpp
index 86edcb5..80f55da 100644
--- a/src/mdaPianoVoice.cpp
+++ b/src/mdaPianoVoice.cpp
@@ -1,11 +1,11 @@
#include "mdaPianoVoice.h"
-mdaPianoVoice::mdaPianoVoice(double rate, short * samples, KGRP * master_kgrp) {
+mdaPianoVoice::mdaPianoVoice(double rate, Sample * master_samples, KGRP * master_kgrp) {
//set tuning
Fs = rate;
iFs = 1.0f/Fs;
- waves = samples;
+ samples = master_samples;
kgrp = master_kgrp;
default_preset[p_offset(p_envelope_decay)] = 0.500f;
@@ -65,14 +65,15 @@ void mdaPianoVoice::on(unsigned char note, unsigned char velocity)
k = 0;
while(note > (kgrp[k].high + s)) k++; //find keygroup
+ sample_index = k; //store sample index
l += (float)(note - kgrp[k].root); //pitch
l = 22050.0f * iFs * (float)exp(0.05776226505 * l);
delta = (uint32_t)(65536.0f * l);
frac = 0;
- pos = kgrp[k].pos;
- end = kgrp[k].end;
- loop = kgrp[k].loop;
+ pos = 0;
+ end = samples[sample_index].size;
+ loop = kgrp[sample_index].loop;
env = (0.5f + velsens) * (float)pow(0.0078f * velocity, velsens); //velocity
@@ -137,8 +138,8 @@ void mdaPianoVoice::render(uint32_t from, uint32_t to)
frac &= 0xFFFF;
if(pos > end) pos -= loop;
- i = waves[pos];
- i = (i << 7) + (frac >> 9) * (waves[pos + 1] - i) + 0x40400000;
+ i = samples[sample_index].buffer[pos];
+ i = (i << 7) + (frac >> 9) * (samples[sample_index].buffer[pos + 1] - i) + 0x40400000;
x = env * (*(float *)&i - 3.0f); //fast int->float
env = env * dec; //envelope
diff --git a/src/mdaPianoVoice.h b/src/mdaPianoVoice.h
index 3276d74..3eb62e1 100644
--- a/src/mdaPianoVoice.h
+++ b/src/mdaPianoVoice.h
@@ -18,7 +18,8 @@ class mdaPianoVoice : public LV2::Voice {
/// global internal variables
KGRP *kgrp;
- short *waves;
+ Sample *samples;
+ uint32_t sample_index;
float default_preset[NPARAMS]; // contains the default preset
short sustain;
float comb[256];
@@ -50,7 +51,7 @@ class mdaPianoVoice : public LV2::Voice {
unsigned char m_key;
public:
- mdaPianoVoice(double, short*, KGRP*);
+ mdaPianoVoice(double, Sample*, KGRP*);
void set_sustain(unsigned short v) { sustain = v; }
void set_volume(float v) { volume = v; }
void set_muff(float v) { muff = v; }