diff options
author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2014-05-02 16:30:08 +0200 |
---|---|---|
committer | Jonas Suhr Christensen <jsc@umbraculum.org> | 2014-05-02 16:30:08 +0200 |
commit | a5ea8e72059ec9fb7145c7117bd9ea77dee0eee7 (patch) | |
tree | 001f5f49d0c7b1dd096a5a69ac231d4925ac7e26 /src/powerlist.cc | |
parent | 10923660851e14fc954dcb0917e9f50185ab401f (diff) | |
parent | 07471554a11d3bf5d275ebffe71682fd7d7440b0 (diff) |
Merge branch 'master' of http://git.drumgizmo.org/drumgizmo
Diffstat (limited to 'src/powerlist.cc')
-rw-r--r-- | src/powerlist.cc | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/powerlist.cc b/src/powerlist.cc index 236bcf8..1888733 100644 --- a/src/powerlist.cc +++ b/src/powerlist.cc @@ -52,6 +52,7 @@ static float box_muller_transform(float mean, float stddev) PowerList::PowerList() { power_max = 0; + power_min = 100000000; lastsample = NULL; } @@ -194,6 +195,7 @@ void PowerList::finalise() item.power = sample->power; if(item.power > power_max) power_max = item.power; + if(item.power < power_min) power_min = item.power; DEBUG(rand, " - power: %f\n", item.power); @@ -206,17 +208,31 @@ Sample *PowerList::get(level_t level) int retry = 3; // TODO: This must be user controllable via the UI. Sample *sample = NULL; - float power = 0; - float mean = level * power_max; - float stddev = power_max / samples.size() * 1.5; + if(!samples.size()) return NULL; // No samples to choose from. + + float power_span = power_max - power_min; + + // Spread out at most 1.5 samples away from center + float stddev = power_span / samples.size() * 1.5; + + // Cut off mean value with stddev/2 in both ends in order to make room for + // downwards expansion on velocity 0 and upwards expansion on velocity 1. + float mean = level * (power_span - stddev) + (stddev / 2.0); again: + // Select normal distributed value between + // (stddev/2) and (power_span-stddev/2) float lvl = box_muller_transform(mean, stddev); + // Adjust this value to be in range + // (power_min+stddev/2) and (power_max-stddev/2) + lvl += power_min; + DEBUG(rand, "level: %f, lvl: %f (mean: %.2f, stddev: %.2f)\n", level, lvl, mean, stddev); + float power = 0; std::vector<PowerListItem>::iterator i = samples.begin(); while(i != samples.end()) { if(sample == NULL) { @@ -232,9 +248,12 @@ again: i++; } - DEBUG(rand, "Found power %f\n", power); + if(lastsample == sample && retry--) { + DEBUG(rand, "Retry [%d retries left]", retry); + goto again; + } - if(lastsample == sample && retry--) goto again; + DEBUG(rand, "Found sample with power %f\n", power); lastsample = sample; |