| 29 | |
| 30 | |
| 31 | void FFTAnalyzer::process(float* fftSamples, int numSamples) |
| 32 | { |
| 33 | if (!enabled->boolValue()) return; |
| 34 | |
| 35 | float result = 0; |
| 36 | float targetPos = position->floatValue(); |
| 37 | float maxDist = size->floatValue() / 2; |
| 38 | |
| 39 | int numGoodSamples = 0; |
| 40 | float totalCoef = 0; |
| 41 | for (int i = 0; i < numSamples; ++i) |
| 42 | { |
| 43 | float pos = i * 1.0f / numSamples; |
| 44 | float dist = jmin<float>(fabsf(targetPos - pos) / maxDist, 1); |
| 45 | if (dist >= 1) continue; |
| 46 | |
| 47 | numGoodSamples++; |
| 48 | float factor = cosf(dist * MathConstants<float>::pi / 2); //smooth |
| 49 | |
| 50 | result += fftSamples[i] * factor; |
| 51 | totalCoef += factor; |
| 52 | } |
| 53 | |
| 54 | if (totalCoef > 0) |
| 55 | { |
| 56 | result /= totalCoef; |
| 57 | value->setValue(result); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void FFTAnalyzer::onContainerNiceNameChanged() |
| 62 | { |
no test coverage detected