208 {
209 MultibandAccent accent;
210
211
212
213
214
215
216 size numBins =
fft.raw().size();
217 if (numBins == 0) {
218 accent = {0.0f, 0.0f, 0.0f, 0.0f};
219 return accent;
220 }
221
222
223 float bassEnergy = 0.0f;
224 float midEnergy = 0.0f;
225 float highEnergy = 0.0f;
226
227
228 size bassEnd =
fl::min(
static_cast<size
>(4), numBins);
229 size midStart = bassEnd;
230 size midEnd =
fl::min(
static_cast<size
>(11), numBins);
231 size highStart = midEnd;
232 size highEnd = numBins;
233
234
235 for (size i = 0; i < bassEnd; i++) {
236 bassEnergy +=
fft.raw()[i];
237 }
238 for (size i = midStart; i < midEnd; i++) {
239 midEnergy +=
fft.raw()[i];
240 }
241 for (size i = highStart; i < highEnd; i++) {
242 highEnergy +=
fft.raw()[i];
243 }
244
245
246 bassEnergy /= static_cast<float>(bassEnd);
247 if (midEnd > midStart) {
248 midEnergy /= static_cast<float>(midEnd - midStart);
249 }
250 if (highEnd > highStart) {
251 highEnergy /= static_cast<float>(highEnd - highStart);
252 }
253
254
255
256 const float epsilon = 1e-6f;
257 const float maxRatio = 10.0f;
258
261 : 1.0f;
264 : 1.0f;
267 : 1.0f;
268
269
270 float logMaxRatio =
fl::log10f(1.0f + maxRatio);
274
275
276 accent.bass = bassEnergy;
277 accent.mid = midEnergy;
278 accent.high = highEnergy;
279
280
284
285
286
287 accent.total = (bassAccent * 0.3f) + (midAccent * 0.5f) + (highAccent * 0.2f);
288
289
290 return {bassEnergy, midEnergy, highEnergy, accent.total};
291}
MultibandAccent mPreviousAccent
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
float log10f(float value) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT