171 {
172
173
174
175
176 if (peakLag <= 0 || peakLag >= static_cast<int>(autocorr.size())) {
177 return 0.0f;
178 }
179
180 float peakValue = autocorr[static_cast<size>(peakLag)];
181
182
183
185
186
187
188 int windowSize =
fl::max(2, peakLag / 10);
189 float neighborSum = 0.0f;
190 int neighborCount = 0;
191
193 if (
offset == 0)
continue;
194
195 int lag = peakLag +
offset;
197 neighborSum +=
fl::max(0.0f, autocorr[
static_cast<size
>(lag)]);
198 neighborCount++;
199 }
200 }
201
202 if (neighborCount > 0) {
203 float neighborAvg = neighborSum / static_cast<float>(neighborCount);
204
205
206
207 if (neighborAvg > 1e-6f) {
208 float clarity =
fl::min(1.0f, (peakValue - neighborAvg) / neighborAvg);
209 confidence *= (0.7f + 0.3f * clarity);
210 }
211 }
212
213 return confidence;
214}
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT