summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2019-07-13 02:17:20 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2019-07-13 02:18:34 +0200
commitd1d04592d49b9ef66cb7b7b59f3a9b0dd9609d97 (patch)
tree9479c676dc48694821c314e85d2eed046527fa48
parent41aa578e8e0e6761ebdf7317a03ff2cef48a39c7 (diff)
Improve the function for diverse in the sample selection.
-rw-r--r--src/sample_selection.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/sample_selection.cc b/src/sample_selection.cc
index d4f78d7..fafeda4 100644
--- a/src/sample_selection.cc
+++ b/src/sample_selection.cc
@@ -85,6 +85,9 @@ const Sample* SampleSelection::get(level_t level, std::size_t pos)
std::size_t count = 0;
do
{
+ // at least avoid infinite loops in case of a bug...
+ if (count > samples.size()) { break; }
+
std::size_t current_index;
if (up_value_lb < down_value_lb)
{
@@ -115,7 +118,7 @@ const Sample* SampleSelection::get(level_t level, std::size_t pos)
auto random = rand.floatInRange(0.,1.);
auto close = samples[current_index].power - level;
- auto diverse = (float)settings.samplerate/std::max<std::size_t>(pos - last[current_index], 1);
+ auto diverse = 1./(1. + (float)(pos - last[current_index])/settings.samplerate);
auto value = f_close*pow2(close) + f_diverse*pow2(diverse) + f_random*random;
if (value < value_opt)