From 068bbbba9248fc11c7c852508c916579bd2621e2 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 8 Oct 2011 15:29:28 +0200 Subject: Humaniser added. Speedy strokes get lower velocity levels. --- src/instrument.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/instrument.cc') diff --git a/src/instrument.cc b/src/instrument.cc index 1b3c31a..8cfaec7 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -30,17 +30,40 @@ #include #include "sample.h" +#include "configuration.h" Instrument::Instrument() { + mod = 1.0; + lastpos = 0; } -Sample *Instrument::sample(level_t level) +Sample *Instrument::sample(level_t level, size_t pos) { + if(Conf::enable_velocity_randomiser) { + float r = (float)rand() / (float)RAND_MAX; // random number: [0;1] + r -= 0.5; // random number [-0.5;0.5] + r *= Conf::velocity_randomiser_weight * 2; // ex. random number [-0.1;0.1] + level += r; + if(level > 1.0) level = 1.0; + if(level < 0.0) level = 0.0; + } + + if(Conf::enable_velocity_modifier) { + mod += (pos - lastpos) / (44100.0 * Conf::velocity_modifier_falloff); + if(mod > 1.0) mod = 1.0; + } + // printf("Find level %f\n", level); - std::vector s = samples.get(level); + std::vector s = samples.get(level * mod); if(s.size() == 0) return NULL; size_t idx = rand()%(s.size()); + + if(Conf::enable_velocity_modifier) { + lastpos = pos; + mod *= Conf::velocity_modifier_weight; + } + return s[idx]; } -- cgit v1.2.3