summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Fischer <corrados@users.noreply.github.com>2021-08-11 17:39:36 +0200
committerVolker Fischer <corrados@users.noreply.github.com>2021-08-11 17:39:36 +0200
commit96b6eed18281005990990f8fe5eaa7e5c0556913 (patch)
tree4474f7960f0103e47bda6efc2fb80fd32a91febe
parent8c02033ce689f73834e0b41fd09ef05a74f9a0ba (diff)
use sqrt(event.velocity) for the dynamic expander to get a MIDI curve which matches the ones of edrum modules
-rw-r--r--src/inputprocessor.cc21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index 8481684..9822daf 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -294,21 +294,16 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos,
// 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());
-auto instr_dynamic = 10 * log10(instr->getMaxPower()) - 10 * log10(instr->getMinPower());
-auto sel_power = 10 * log10(sample->getPower());
+auto target_max_power_db = 10 * log10(instr->getMaxPower());
+auto target_min_power_db = 10 * log10(instr->getMinPower());
+auto sel_power_db = 10 * log10(sample->getPower());
+auto target_dynamic_db = 35.0; // dB
-auto target_dynamic = 35.0; // dB
-auto target_max_power = 10 * log10(instr->getMaxPower());
-auto target_min_power = target_max_power - target_dynamic;
-
-auto target_power = event.velocity * target_dynamic - target_dynamic + target_max_power;
-
-auto diff_power = target_power - sel_power;
-
-event_sample.scale = pow(10.0, diff_power / 20);
-
-//printf("event_sample.scale: %f, diff_power: %f, target_power: %f, sel_power: %f\n", event_sample.scale, diff_power, target_power, sel_power);
+auto target_power_db = sqrt(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);
+//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);
}
}