| 118 | } |
| 119 | |
| 120 | const fft::Bins* Context::getHistoricalFFT(int framesBack) const { |
| 121 | if (framesBack < 0 || framesBack >= static_cast<int>(mFFTHistory.size())) { |
| 122 | return nullptr; |
| 123 | } |
| 124 | // Ring buffer lookup: walk backwards from the most-recently-written slot. |
| 125 | // Adding history.size() before the modulo avoids negative values from |
| 126 | // the subtraction, since C++ modulo of negative ints is implementation-defined. |
| 127 | const int n = static_cast<int>(mFFTHistory.size()); |
| 128 | int index = (mFFTHistoryIndex - 1 - framesBack + n) % n; |
| 129 | return &mFFTHistory[index]; |
| 130 | } |
| 131 | |
| 132 | void Context::setSample(const Sample& sample) { |
| 133 | // Save current fft::FFT to history (use first cached entry if available) |
no test coverage detected