summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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)