| 400 | } |
| 401 | |
| 402 | u8 Downbeat::findMostCommonMeter() const { |
| 403 | if (mMeterCandidates.empty()) { |
| 404 | return 4; // Default to 4/4 |
| 405 | } |
| 406 | |
| 407 | // Count occurrences of each meter |
| 408 | fl::array<u8, 16> counts = {}; // Support meters 2-16 |
| 409 | |
| 410 | for (size i = 0; i < mMeterCandidates.size(); i++) { |
| 411 | u8 meter = mMeterCandidates[i]; |
| 412 | if (meter >= 2 && meter < 16) { |
| 413 | counts[meter]++; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // Find most common |
| 418 | u8 maxCount = 0; |
| 419 | u8 mostCommonMeter = 4; |
| 420 | |
| 421 | for (u8 meter = 2; meter < 16; meter++) { |
| 422 | if (counts[meter] > maxCount) { |
| 423 | maxCount = counts[meter]; |
| 424 | mostCommonMeter = meter; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | return mostCommonMeter; |
| 429 | } |
| 430 | |
| 431 | } // namespace detector |
| 432 | } // namespace audio |