| 216 | } |
| 217 | |
| 218 | void TempoAnalyzer::pruneHypotheses() { |
| 219 | // Remove hypotheses that haven't been updated recently |
| 220 | for (size i = 0; i < mHypotheses.size(); ) { |
| 221 | // Decay score over time |
| 222 | mHypotheses[i].score *= 0.95f; |
| 223 | |
| 224 | if (mHypotheses[i].score < 0.1f) { |
| 225 | mHypotheses.erase(mHypotheses.begin() + i); |
| 226 | } else { |
| 227 | i++; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // Sort by score (highest first) |
| 232 | for (size i = 0; i < mHypotheses.size(); i++) { |
| 233 | for (size j = i + 1; j < mHypotheses.size(); j++) { |
| 234 | if (mHypotheses[j].score > mHypotheses[i].score) { |
| 235 | TempoHypothesis temp = mHypotheses[i]; |
| 236 | mHypotheses[i] = mHypotheses[j]; |
| 237 | mHypotheses[j] = temp; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // Keep only top hypotheses |
| 243 | if (mHypotheses.size() > MAX_HYPOTHESES) { |
| 244 | mHypotheses.resize(MAX_HYPOTHESES); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | void TempoAnalyzer::updateCurrentTempo() { |
| 249 | if (mHypotheses.empty()) { |