summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/inputprocessor.cc50
1 files changed, 12 insertions, 38 deletions
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index 7d58b52..6d50c68 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -210,19 +210,16 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos,
return false;
}
-
-// TEST dynamic expander
-if(settings.drumkit_is_log_power)
-{
- static auto a = 0.981;
- static auto factor = 126.0f / (pow(a, 126.0f) - 1.0f);
- event.velocity = (factor * (pow(a, event.velocity * 127.0f - 1.0f) - 1.0f) + 1.0f) / 127.0f;
-}
+ // In case log-power and dynamic expander is used, apply a special velocity curve
+ if(settings.drumkit_is_log_power)
+ {
+ auto a = 0.981; // compatible to Roland sound modules
+ event.velocity = (126.0f / (pow(a, 126.0f) - 1.0f) * (pow(a, event.velocity * 127.0f - 1.0f) - 1.0f) + 1.0f) / 127.0f;
+ }
// TODO velocity 1 does not select thehighest amplitude samples... -> maybe bug in sample selection
//event.velocity=1.0;
-
std::size_t instrument_id = event.instrument;
Instrument* instr = nullptr;
@@ -304,35 +301,12 @@ if(settings.drumkit_is_log_power)
event_sample.scale *= event.velocity;
}
-// TEST dynamic expander
-//printf("event_sample.scale: %f, event.velocity: %f, sample->getPower(): %f, instr->getMinPower(): %f, instr->getMaxPower(): %f\n", event_sample.scale, event.velocity, sample->getPower(), instr->getMinPower(), instr->getMaxPower());
-
-if(settings.drumkit_is_log_power)
-{
- // powers in instrument XML are in dB and curve is already applied to event.velocity:
- auto target_max_power_db = instr->getMaxPower();
- auto sel_power_db = sample->getPower();
- auto target_dynamic_db = 50.0; // dB
- auto target_power_db = event.velocity * target_dynamic_db + target_max_power_db - target_dynamic_db;
- auto diff_power_db = target_power_db - sel_power_db;
- event_sample.scale = pow(10.0, diff_power_db / 20);
-}
-else
-{
- auto target_max_power_db = 10 * log10(instr->getMaxPower());
- auto sel_power_db = 10 * log10(sample->getPower());
- auto target_dynamic_db = 40.0; // dB
-
- static auto a = 0.981;
- static auto factor = 126.0f / (pow(a, 126.0f) - 1.0f);
- auto y = (factor * (pow(a, event.velocity * 127.0f - 1.0f) - 1.0f) + 1.0f) / 127.0f;
- auto target_power_db = y * target_dynamic_db + target_max_power_db - target_dynamic_db;
- auto diff_power_db = target_power_db - sel_power_db;
- event_sample.scale = pow(10.0, diff_power_db / 20);
-}
-
-//printf("event_sample.scale: %f, diff_power_db: %f, target_power_db: %f, sel_power_db: %f\n", event_sample.scale, diff_power_db, target_power_db, sel_power_db);
-
+ // Dynamic expander (only enabled if log-power is configured)
+ if(settings.drumkit_is_log_power)
+ {
+ auto target_dynamic_db = 50.0; // dB, defined maximum dynamic after expander
+ event_sample.scale = pow(10.0, (event.velocity * target_dynamic_db + instr->getMaxPower() - target_dynamic_db - sample->getPower()) / 20);
+ }
}
}