|
FastLED 3.9.15
|
FrequencyBinMapper maps FFT output bins to perceptually-spaced frequency channels.
This class converts the linear FFT spectrum into logarithmically-spaced frequency bands that better match human hearing. It supports both 16-bin (WLED-compatible) and 32-bin (higher resolution) modes with pre-calculated bin boundaries for efficient real-time processing.
Frequency ranges (16-bin mode, log spacing 20-16000 Hz):
Usage:
Definition at line 71 of file frequency_bin_mapper.h.
#include <frequency_bin_mapper.h>
Collaboration diagram for fl::audio::FrequencyBinMapper:Classes | |
| struct | BinMapping |
| Mapping from output bins to FFT bin ranges Each entry contains (startBin, endBin) for averaging. More... | |
| struct | FrequencyRange |
| Get frequency boundaries for a specific output bin. More... | |
| struct | Stats |
| Get statistics (for debugging/monitoring) More... | |
Public Member Functions | |
| FrequencyBinMapper () FL_NOEXCEPT | |
| FrequencyBinMapper (const FrequencyBinMapperConfig &config) | |
| ~FrequencyBinMapper () FL_NOEXCEPT | |
| void | configure (const FrequencyBinMapperConfig &config) |
| Configure the frequency bin mapper This calculates bin boundaries and FFT-to-frequency bin mappings. | |
| float | getBassEnergy (span< const float > frequencyBins) const |
| Get bass energy (average of bins 0-1 in 16-bin mode) | |
| FrequencyRange | getBinFrequencyRange (size binIndex) const |
| const FrequencyBinMapperConfig & | getConfig () const |
| Get current configuration. | |
| float | getMidEnergy (span< const float > frequencyBins) const |
| Get mid energy (average of bins 6-7 in 16-bin mode) | |
| size | getNumBins () const |
| Get number of output bins (16 or 32) | |
| const Stats & | getStats () const |
| float | getTrebleEnergy (span< const float > frequencyBins) const |
| Get treble energy (average of bins 14-15 in 16-bin mode) | |
| void | mapBins (span< const float > fftBins, span< float > outputBins) const |
| Map FFT bins to frequency channels. | |
Private Member Functions | |
| void | calculateBinBoundaries () |
| Calculate frequency bin boundaries (linear or logarithmic spacing) | |
| void | calculateBinMappings () |
| Calculate FFT bin to frequency bin mappings Pre-calculates which FFT bins contribute to each frequency bin. | |
| void | calculateLinearFrequencies () |
| Calculate linearly-spaced frequency boundaries. | |
| void | calculateLogFrequencies () |
| Calculate logarithmically-spaced frequency boundaries. | |
| float | frequencyToFFTBin (float frequency) const |
| Convert frequency (Hz) to FFT bin index. | |
Private Attributes | |
| vector< float > | mBinFrequencies |
| Pre-calculated frequency boundaries for each output bin Size: numBins + 1 (includes both lower and upper edges) | |
| vector< BinMapping > | mBinMappings |
| FrequencyBinMapperConfig | mConfig |
| Stats | mStats |
Static Private Attributes | |
| static constexpr size | BASS_BIN_END = 2 |
| static constexpr size | BASS_BIN_START = 0 |
| Bass/mid/treble bin indices (for 16-bin mode) These are pre-calculated based on the bin count. | |
| static constexpr size | MID_BIN_END = 8 |
| static constexpr size | MID_BIN_START = 6 |
| static constexpr size | TREBLE_BIN_END = 16 |
| static constexpr size | TREBLE_BIN_START = 14 |