diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-07-27 11:42:03 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-07-28 21:34:08 +0200 |
commit | af48a660a3410c3a63cab324fd8a345b648f821d (patch) | |
tree | 0c3a9cb6f073ae6884866d4af7e1965777384982 /src | |
parent | 6f0518b9a5999442d063369d9818c41fb9ac2ed6 (diff) |
WIP
Diffstat (limited to 'src')
-rw-r--r-- | src/sample_selection.cc | 25 | ||||
-rw-r--r-- | src/settings.h | 2 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/sample_selection.cc b/src/sample_selection.cc index b7b6bcd..4bd1979 100644 --- a/src/sample_selection.cc +++ b/src/sample_selection.cc @@ -89,6 +89,7 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo instrument_power_span = 1.0; } +#if 0 // start with most promising power value and then stop when reaching far values // which cannot become opt anymore auto closest_it = std::lower_bound(samples.begin(), samples.end(), power); @@ -165,6 +166,30 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo ++count; } while (up_value_lb <= value_opt || down_value_lb <= value_opt); +#else + for(std::size_t current_index = 0; current_index < samples.size(); ++current_index) + { + auto random = rand.floatInRange(0.,1.); + auto close = (samples[current_index].power - power)/instrument_power_span; + auto diverse = 1./(1. + (float)(pos - last[current_index])/settings.samplerate); + auto closepos = samples[current_index].sample->getPosition() - position; + // note that the value below for close and closepos is actually the weighted squared l2 distance in 2d + auto value = f_close*pow2(close) + f_position*pow2(closepos) + f_diverse*diverse + f_random*random; + + if (value < value_opt) + { + index_opt = current_index; + power_opt = samples[current_index].power; + pos_opt = samples[current_index].sample->getPosition(); + value_opt = value; + random_opt = random; + close_opt = close; + diverse_opt = diverse; + closepos_opt = closepos; + } + } + int count{}; // not used +#endif DEBUG(rand, "Chose sample with index: %d, value: %f, power: %f, position: %f, random: %f, close: %f, diverse: %f, closepos: %f, count: %d", (int)index_opt, value_opt, power_opt, pos_opt, random_opt, close_opt, diverse_opt, closepos_opt, (int)count); diff --git a/src/settings.h b/src/settings.h index 58b17f3..074c7bc 100644 --- a/src/settings.h +++ b/src/settings.h @@ -78,7 +78,7 @@ struct Settings static float constexpr velocity_stddev_default = .45f; static float constexpr position_stddev_default = .45f; static float constexpr sample_selection_f_close_default = .85f; - static float constexpr sample_selection_f_position_default = .016f; + static float constexpr sample_selection_f_position_default = .85f; static float constexpr sample_selection_f_diverse_default = .16f; static float constexpr sample_selection_f_random_default = .07f; Atomic<float> velocity_modifier_falloff{velocity_modifier_falloff_default}; |