| 60 | }; |
| 61 | |
| 62 | int runProfiler(bool jsonOutput) { |
| 63 | const int ITERATIONS = 500; |
| 64 | const int SAMPLE_RATE = 16000; |
| 65 | |
| 66 | fl::vector<DetectorCost> costs; |
| 67 | SynthAudioGenerator audioGen(SAMPLE_RATE); |
| 68 | |
| 69 | // ===== PHASE 1: Baseline (Energy only) ===== |
| 70 | // This gives us the true baseline cost without any FFT-dependent detector |
| 71 | fl::u32 baselineTotal_us = 0; |
| 72 | { |
| 73 | fl::audio::Processor processor; |
| 74 | processor.setSampleRate(SAMPLE_RATE); |
| 75 | processor.onEnergy([](float) {}); |
| 76 | |
| 77 | for (int i = 0; i < 10; i++) { |
| 78 | processor.update(audioGen.generateSample()); |
| 79 | } |
| 80 | |
| 81 | fl::u32 t0 = fl::micros(); |
| 82 | for (int i = 0; i < ITERATIONS; i++) { |
| 83 | processor.update(audioGen.generateSample()); |
| 84 | } |
| 85 | fl::u32 t1 = fl::micros(); |
| 86 | baselineTotal_us = t1 - t0; |
| 87 | |
| 88 | costs.push_back({"EnergyAnalyzer (BASELINE)", |
| 89 | baselineTotal_us / static_cast<float>(ITERATIONS), 0.0f, 0.0f}); |
| 90 | } |
| 91 | |
| 92 | // ===== PHASE 2: Measure detector that DON'T use FFT ===== |
| 93 | fl::vector<const char*> noFFTDetectors = { |
| 94 | "Beat", "TempoAnalyzer", "Transient" |
| 95 | }; |
| 96 | |
| 97 | fl::vector<fl::u32> noFFTTotals; |
| 98 | noFFTTotals.push_back(baselineTotal_us); // Start with baseline |
| 99 | |
| 100 | // Beat detector |
| 101 | { |
| 102 | fl::audio::Processor processor; |
| 103 | processor.setSampleRate(SAMPLE_RATE); |
| 104 | processor.onEnergy([](float) {}); |
| 105 | processor.onBeat([]() {}); |
| 106 | |
| 107 | for (int i = 0; i < 10; i++) { |
| 108 | processor.update(audioGen.generateSample()); |
| 109 | } |
| 110 | |
| 111 | fl::u32 t0 = fl::micros(); |
| 112 | for (int i = 0; i < ITERATIONS; i++) { |
| 113 | processor.update(audioGen.generateSample()); |
| 114 | } |
| 115 | fl::u32 t1 = fl::micros(); |
| 116 | fl::u32 total = t1 - t0; |
| 117 | float detectorCost = (total - baselineTotal_us) / static_cast<float>(ITERATIONS); |
| 118 | |
| 119 | costs.push_back({"Beat", |
no test coverage detected