summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audioinputenginemidi.cc4
-rw-r--r--src/inputprocessor.cc10
-rw-r--r--src/velocityfilter.cc16
3 files changed, 16 insertions, 14 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index abe00ff..0714546 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -127,8 +127,10 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
case NoteOn:
if(instrument_idx != -1)
{
+ // maps velocities to [.5/127, 126.5/127]
+ auto centered_velocity = (velocity-.5f)/127.0f;
events.push_back({EventType::OnSet, (std::size_t)instrument_idx,
- offset, velocity / 127.0f});
+ offset, centered_velocity});
}
break;
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index b5b887f..4b0b20f 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -182,7 +182,11 @@ bool InputProcessor::processOnset(event_t& event,
}
- const auto sample = instr->sample(event.velocity, event.offset + pos);
+ auto const power_max = instr->getMaxPower();
+ auto const power_min = instr->getMinPower();
+ float const power_span = power_max - power_min;
+ float const instrument_level = power_min + event.velocity*power_span;
+ const auto sample = instr->sample(instrument_level, event.offset + pos);
if(sample == nullptr)
{
@@ -190,9 +194,7 @@ bool InputProcessor::processOnset(event_t& event,
return false;
}
- auto selected_level =
- (sample->getPower() - instr->getMinPower()) /
- (instr->getMaxPower() - instr->getMinPower());
+ auto const selected_level = (sample->getPower() - instr->getMinPower())/power_span;
settings.velocity_modifier_current.store(selected_level / orig_level);
for(Channel& ch: kit.channels)
diff --git a/src/velocityfilter.cc b/src/velocityfilter.cc
index af1c524..7b41045 100644
--- a/src/velocityfilter.cc
+++ b/src/velocityfilter.cc
@@ -36,15 +36,13 @@ VelocityFilter::VelocityFilter(Settings& settings, Random& random, Instruments c
bool VelocityFilter::filter(event_t& event, size_t pos)
{
- auto power_max = instruments[event.instrument]->getMaxPower();
- auto power_min = instruments[event.instrument]->getMinPower();
- float power_span = power_max - power_min;
+ if (settings.enable_velocity_modifier.load())
+ {
+ float mean = event.velocity;
+ float stddev = settings.velocity_stddev.load();
+ // the 30.0f were determined empirically
+ event.velocity += random.normalDistribution(mean, stddev / 30.0f);
+ }
- float mean = event.velocity - .5f/127.f; // XXX: this should actually be done when reading the events
- float stddev = settings.velocity_stddev.load();
- // the 20.0f we determined empirically
- float lvl = power_min + random.normalDistribution(mean, stddev / 30.0f) * power_span;
-
- event.velocity = lvl;
return true;
}