FastLED 3.9.15
Loading...
Searching...
No Matches

◆ computeConfidences()

void fl::audio::detector::Percussion::computeConfidences ( )
private

Definition at line 228 of file percussion.cpp.hpp.

228 {
229 // Feature distributions with frequency-based bands (90-14080 Hz, 16 CQ bins):
230 //
231 // Type | bassToTotal | trebleToTotal | clickRatio | trebleFlatness | midToTreble | subBassProxy
232 // ---------|-------------|---------------|------------|----------------|-------------|-------------
233 // Kick | 0.30-0.45 | 0.30-0.50 | 1.0-2.0 | 0.9-1.0 | 0.5-0.9 | 0.5-3
234 // Snare | 0.10-0.25 | 0.55-0.75 | 1.5-2.5 | 0.9-1.0 | 0.2-0.5 | 0.0-0.2
235 // HiHat | 0.03-0.10 | 0.70-0.90 | 2.5-5.0 | 0.9-1.0 | 0.1-0.2 | 0.2-1.5
236 // Tom | 0.25-0.45 | 0.30-0.50 | 0.8-1.5 | 0.9-1.0 | 0.5-1.0 | 0.0-0.3
237
238 // Kick: bass-dominant with high sub-bass proxy (distinguishes from tom)
239 // Key discriminants from tom: subBassProxy (kick > 0.5, tom < 0.3)
240 {
241 // Bass score: peaks at 0.35 (kick range 0.25-0.50)
242 float bassScore = fl::max(0.0f, 1.0f - fl::abs(mBassToTotal - 0.35f) / 0.20f);
243 // Sub-bass proxy: kick has notable sub-bass energy (> 0.5)
244 float subBassScore = fl::min(1.0f, mSubBassProxy / 2.0f);
245 // Moderate treble (0.30-0.50 — higher than tom due to click)
246 float trebleScore = fl::max(0.0f, 1.0f - fl::abs(mTrebleToTotal - 0.40f) / 0.20f);
247 // ZCF: kick has low-moderate zero crossings (~0.1-0.4)
248 float zcfScore = fl::max(0.0f, 1.0f - fl::abs(mZeroCrossingFactor - 0.25f) / 0.25f);
249
250 mKickConfidence = 0.25f * bassScore + 0.35f * subBassScore +
251 0.20f * trebleScore + 0.20f * zcfScore;
252 }
253
254 // Snare: low-moderate bass + high treble from noise rattles
255 {
256 // Bass score: low bass (0.10-0.25) — lower than kick/tom
257 float bassScore = fl::max(0.0f, 1.0f - fl::abs(mBassToTotal - 0.15f) / 0.15f);
258 // Treble presence: snare has high treble (0.55-0.75)
259 float trebleScore = fl::max(0.0f, 1.0f - fl::abs(mTrebleToTotal - 0.65f) / 0.20f);
260 // Mid/Treble ratio: snare ~0.2-0.5 (moderate)
261 float midTrebleScore = fl::max(0.0f, 1.0f - fl::abs(mMidToTreble - 0.30f) / 0.25f);
262 // Very low sub-bass (< 0.2 — no body resonance)
263 float noSubBassScore = fl::max(0.0f, 1.0f - mSubBassProxy / 0.5f);
264 // ZCF: moderate (noise has many zero crossings)
265 float zcfScore = fl::max(0.0f, (mZeroCrossingFactor - 0.20f) / 0.40f);
266 zcfScore = fl::min(1.0f, zcfScore);
267
268 mSnareConfidence = 0.20f * bassScore + 0.25f * trebleScore +
269 0.15f * midTrebleScore + 0.20f * noSubBassScore +
270 0.20f * zcfScore;
271 }
272
273 // HiHat: treble-dominant with high ZCF
274 {
275 // Treble dominance: hi-hat is mostly treble (0.70-0.90)
276 float trebleScore = fl::max(0.0f, (mTrebleToTotal - 0.60f) / 0.30f);
277 trebleScore = fl::min(1.0f, trebleScore);
278 // No bass
279 float noBassScore = fl::max(0.0f, 1.0f - mBassToTotal / 0.15f);
280 // Very high click ratio (> 2.5 — all energy in click band)
281 float highClickScore = fl::max(0.0f, (mClickRatio - 2.0f) / 3.0f);
282 highClickScore = fl::min(1.0f, highClickScore);
283 // ZCF: hi-hat has very high zero crossings (~0.5-0.8)
284 float zcfScore = fl::max(0.0f, (mZeroCrossingFactor - 0.35f) / 0.45f);
285 zcfScore = fl::min(1.0f, zcfScore);
286
287 mHiHatConfidence = 0.30f * trebleScore + 0.20f * noBassScore +
288 0.25f * highClickScore + 0.25f * zcfScore;
289 }
290
291 // Tom: bass with NO sub-bass, low mid-to-treble discriminates from kick
292 {
293 // Moderate bass (0.25-0.45) — similar range to kick
294 float bassScore = fl::max(0.0f, 1.0f - fl::abs(mBassToTotal - 0.35f) / 0.20f);
295 // NO sub-bass: key discriminant from kick (tom < 0.3, kick > 0.5)
296 float noSubBassScore = fl::max(0.0f, 1.0f - mSubBassProxy / 0.5f);
297 // High mid-to-treble ratio (tom body resonance in mid)
298 float midTrebleScore = fl::max(0.0f, (mMidToTreble - 0.50f) / 0.50f);
299 midTrebleScore = fl::min(1.0f, midTrebleScore);
300 // ZCF: tom has very low zero crossings (~0.05-0.15)
301 float zcfScore = fl::max(0.0f, 1.0f - mZeroCrossingFactor / 0.25f);
302
303 mTomConfidence = 0.25f * bassScore + 0.30f * noSubBassScore +
304 0.20f * midTrebleScore + 0.25f * zcfScore;
305 }
306
307 // Clamp all to [0, 1]
312}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT

References fl::abs(), fl::clamp(), fl::max(), mBassToTotal, mClickRatio, mHiHatConfidence, fl::min(), mKickConfidence, mMidToTreble, mSnareConfidence, mSubBassProxy, mTomConfidence, mTrebleToTotal, and mZeroCrossingFactor.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: