From d1d04592d49b9ef66cb7b7b59f3a9b0dd9609d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 13 Jul 2019 02:17:20 +0200 Subject: Improve the function for diverse in the sample selection. --- src/sample_selection.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') 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(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) -- cgit v1.2.3