110 {
111 const int numBins =
static_cast<int>(
fft.raw().size());
112 if (numBins <= 1) {
113 return 0.0f;
114 }
115
116 float totalEnergy = 0.0f;
117 float totalWeight = 0.0f;
118
119 for (int i = 0; i < numBins; i++) {
120
121
122 float binLow;
123 float binHigh;
124 if (i == 0) {
125 binLow = fftMinFreq;
126 } else {
127 binLow =
fft.binBoundary(i - 1);
128 }
129 if (i == numBins - 1) {
130 binHigh = fftMaxFreq;
131 } else {
132 binHigh =
fft.binBoundary(i);
133 }
134
135
136 float overlapMin =
fl::max(binLow, minFreq);
137 float overlapMax =
fl::min(binHigh, maxFreq);
138
139 if (overlapMax <= overlapMin) {
140 continue;
141 }
142
143 float binWidth = binHigh - binLow;
144 float overlapFraction = (overlapMax - overlapMin) / binWidth;
145
146 totalEnergy +=
fft.raw()[i] * overlapFraction;
147 totalWeight += overlapFraction;
148 }
149
150
151 return (totalWeight > 0.0f) ? totalEnergy / totalWeight : 0.0f;
152}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT