--------------------------------------------------------------------------- Run a single sweep for one (mode, window) pair Sweeps from fmin to sweepMax (Nyquist) in log-spaced steps. Points where inputFreq > fmax are marked as out-of-band. ---------------------------------------------------------------------------
| 129 | // Points where inputFreq > fmax are marked as out-of-band. |
| 130 | // --------------------------------------------------------------------------- |
| 131 | static void runSweep(Mode mode, Window window, |
| 132 | int samples, int bands, float fmin, float fmax, |
| 133 | int sampleRate, int numSteps, |
| 134 | fl::vector<SweepPoint> &out) { |
| 135 | Args args(samples, bands, fmin, fmax, sampleRate, mode, window); |
| 136 | Impl fft(args); |
| 137 | Bins bins(bands); |
| 138 | fl::vector<fl::i16> signal; |
| 139 | |
| 140 | // Sweep from fmin to Nyquist in log-spaced steps |
| 141 | float nyquist = static_cast<float>(sampleRate) / 2.0f; |
| 142 | float logMin = fl::logf(fmin); |
| 143 | float logMax = fl::logf(nyquist); |
| 144 | |
| 145 | int prevPeakBin = -1; |
| 146 | float prevPeakFreq = -1.0f; |
| 147 | |
| 148 | out.clear(); |
| 149 | for (int step = 0; step < numSteps; step++) { |
| 150 | float t = static_cast<float>(step) / static_cast<float>(numSteps - 1); |
| 151 | float freq = fl::expf(logMin + t * (logMax - logMin)); |
| 152 | |
| 153 | generateSine(signal, samples, sampleRate, freq); |
| 154 | fft.run(signal, &bins); |
| 155 | |
| 156 | int peak = peakBin(bins.raw()); |
| 157 | float peakFreq = bins.binToFreq(peak); |
| 158 | float conc = energyConcentration(bins.raw(), peak); |
| 159 | |
| 160 | SweepPoint pt; |
| 161 | pt.inputFreq = freq; |
| 162 | pt.peakBinIdx = peak; |
| 163 | pt.peakBinFreq = peakFreq; |
| 164 | pt.concentration = conc; |
| 165 | pt.monotonic = (peak >= prevPeakBin); |
| 166 | pt.aliased = (prevPeakFreq > 0.0f && peakFreq < prevPeakFreq * 0.8f); |
| 167 | pt.inBand = (freq <= fmax); |
| 168 | |
| 169 | out.push_back(pt); |
| 170 | prevPeakBin = peak; |
| 171 | prevPeakFreq = peakFreq; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // --------------------------------------------------------------------------- |
| 176 | // Compute summary stats for a subset of sweep points |
no test coverage detected