FastLED 3.10.8
Loading...
Searching...
No Matches
fl::audio Namespace Reference

Namespaces

namespace  anonymous_namespace{audio.cpp.hpp}
 
namespace  detector
 
namespace  fft
 
namespace  TeensyI2S
 

Classes

class  AudioManager
 
class  AutoGain
 AutoGain implements adaptive gain control using a PI (proportional-integral) controller with slow peak envelope tracking, inspired by WLED Sound Reactive. More...
 
struct  AutoGainConfig
 Configuration for automatic gain control. More...
 
struct  BandEnergy
 
struct  BeatDetectors
 
class  Config
 
struct  ConfigI2S
 
struct  ConfigPdm
 
class  Context
 
struct  Data
 
class  Detector
 
class  FrequencyBinMapper
 FrequencyBinMapper maps FFT output bins to perceptually-spaced frequency channels. More...
 
struct  FrequencyBinMapperConfig
 Configuration for frequency bin mapping. More...
 
class  IInput
 
class  ISynthEngine
 Interface for synth engine that holds BLEP/BLAMP tables. More...
 
class  ISynthOscillator
 Interface class for synth oscillator. More...
 
struct  MicResponseCurve
 
class  NoiseFloorTracker
 NoiseFloorTracker maintains an adaptive estimate of the background noise floor for audio signals, with hysteresis to prevent "noise chasing" where the floor continuously adjusts to the signal level. More...
 
struct  NoiseFloorTrackerConfig
 Configuration for noise floor tracking. More...
 
class  PerceptualWeighting
 
class  Processor
 
class  Reactive
 
struct  ReactiveConfig
 
class  Sample
 
class  SampleImpl
 
class  SignalConditioner
 SignalConditioner performs low-level audio preprocessing to clean raw PCM samples before FFT analysis or beat detection. More...
 
struct  SignalConditionerConfig
 Configuration for signal conditioning pipeline. More...
 
class  SilenceEnvelope
 
class  SoundLevelMeter
 
class  SpectralEqualizer
 SpectralEqualizer applies frequency-dependent gain correction to address mid-frequency dominance and provide perceptual weighting of audio spectra. More...
 
struct  SpectralEqualizerConfig
 Configuration for spectral equalizer. More...
 
class  SpectralFluxDetector
 
class  SynthEngineImpl
 
class  SynthOscillatorImpl
 
struct  SynthParams
 Waveform parameters for custom waveforms. More...
 

Enumerations

enum class  AGCPreset { AGCPreset_Normal , AGCPreset_Vivid , AGCPreset_Lazy , AGCPreset_Custom }
 AGC preset selection — derived from WLED Sound Reactive's proven approach. More...
 
enum class  AudioChannel { Left = 0 , Right = 1 , Both = 2 }
 
enum class  EqualizationCurve { Flat , AWeighting , Custom }
 Equalization curve type. More...
 
enum class  FrequencyBinMode { Bins16 = 16 , Bins32 = 32 }
 Frequency bin mode - controls number of output bins. More...
 
enum class  I2SCommFormat {
  Philips = 0X01 , MSB = 0X02 , PCMShort = 0x04 , PCMLong = 0x0C ,
  Max = 0x0F
}
 
enum class  MicProfile : u8 {
  None , INMP441 , ICS43434 , SPM1423 ,
  GenericMEMS , LineIn
}
 Microphone frequency response correction profile. More...
 
enum class  SynthShape {
  Sawtooth , Square , Triangle , AlternatingSaw ,
  Custom
}
 Predefined waveform shapes for synth oscillator. More...
 

Functions

static float clamp01 (float v) FL_NO_EXCEPT
 
static float clampNeg1To1 (float v) FL_NO_EXCEPT
 
float computeAudioDt (fl::size pcmSize, int sampleRate) FL_NO_EXCEPT
 Compute the time delta (in seconds) for an audio buffer.
 
float computePinkNoiseGain (float freq_hz, float f_ref) FL_NO_EXCEPT
 Compute pink noise compensation gain for a single frequency.
 
void computePinkNoiseGains (const float *binCenters, int numBins, float *out) FL_NO_EXCEPT
 Compute pink noise compensation gains for all bins.
 
void downsampleMicResponse (const MicResponseCurve &curve, const float *binCenters, int numBins, float *out) FL_NO_EXCEPT
 Downsample a high-resolution mic response curve to N output bins.
 
 FASTLED_SHARED_PTR (ISynthEngine)
 
 FASTLED_SHARED_PTR (ISynthOscillator)
 
 FASTLED_SHARED_PTR (SampleImpl)
 
float fl_progmem_read_float (const float *addr) FL_NO_EXCEPT
 Read a float from PROGMEM.
 
MicResponseCurve getMicResponseCurve (MicProfile profile) FL_NO_EXCEPT
 Get the high-resolution response curve for a given mic profile.
 
float interpolateMicResponse (const MicResponseCurve &curve, float freq_hz) FL_NO_EXCEPT
 Interpolate mic response at an arbitrary frequency (Hz).
 
FL_LINK_WEAK fl::shared_ptr< IInput > platform_create_audio_input (const Config &config, fl::string *error_message) FL_NO_EXCEPT
 

Variables

static const float kMicResponse_GenericMEMS [kMicResponsePoints]
 
static const float kMicResponse_ICS43434 [kMicResponsePoints]
 
static const float kMicResponse_INMP441 [kMicResponsePoints]
 
static const float kMicResponse_LineIn [kMicResponsePoints]
 
static const float kMicResponse_SPM1423 [kMicResponsePoints]
 
static const float kMicResponseFreqs [kMicResponsePoints]
 
static constexpr int kMicResponsePoints = 61
 

Controls how quickly the peak tracker forgets old peaks. Longer = more stable.

AGCPreset preset = AGCPreset::AGCPreset_Normal AGC behavior preset (default: Normal) float targetRMSLevel = 8000.0f Target RMS level after gain (0-32767) The AGC will adjust gain to maintain this average level.

◆ fl::audio::BandEnergy

struct fl::audio::BandEnergy
Class Members
float bass = 0.0f
float mid = 0.0f
float treb = 0.0f

◆ fl::audio::Data

struct fl::audio::Data
Class Members
bool bassBeatDetected = false
float bassEnergy = 0.0f
bool beatDetected = false
float dominantFrequency = 0.0f
float frequencyBins[16] = {0}
float magnitude = 0.0f
bool midBeatDetected = false
float midEnergy = 0.0f
float peak = 0.0f
float spectralFlux = 0.0f
u32 timestamp = 0
bool trebleBeatDetected = false
float trebleEnergy = 0.0f
float volume = 0.0f
float volumeRaw = 0.0f

◆ fl::audio::FrequencyBinMapperConfig

struct fl::audio::FrequencyBinMapperConfig
Class Members
u32 fftBinCount = 256 Number of FFT bins available from FFT output For 512-sample FFT at 22050 Hz: 256 bins (512/2)
float maxFrequency = 16000.0f Maximum frequency (Hz) - default 16000 Hz (treble)
float minFrequency = 20.0f Minimum frequency (Hz) - default 20 Hz (bass)
FrequencyBinMode mode = FrequencyBinMode::Bins16 Number of output frequency bins (16 or 32)
u32 sampleRate = 22050 Sample rate (Hz) - must match FFT sample rate.
bool useLogSpacing = true Use logarithmic spacing (recommended for audio) Logarithmic spacing provides better bass/mid/treble separation.

◆ fl::audio::MicResponseCurve

struct fl::audio::MicResponseCurve
Class Members
int count Number of data points.
const float * freqs Pointer to frequency array (PROGMEM)
const float * gains Pointer to gain array (PROGMEM)

◆ fl::audio::NoiseFloorTrackerConfig

struct fl::audio::NoiseFloorTrackerConfig
Class Members
float attackRate = 0.001f Attack rate for noise floor (0.0-1.0) How quickly the floor rises when signal is consistently low.
float crossDomainWeight = 0.3f Cross-domain calibration weight (0.0-1.0) Blends time-domain RMS and frequency-domain energy for floor estimation 0.0 = use only time-domain, 1.0 = use only frequency-domain.
float decayRate = 0.99f Decay rate for noise floor (0.0-1.0) Higher = slower decay (more stable, less responsive) Lower = faster decay (more responsive, less stable)
bool enabled = true Enable noise floor tracking.
float hysteresisMargin = 100.0f Hysteresis margin (prevents noise chasing) Floor must drop by this amount before it can rise again.
float maxFloor = 5000.0f Maximum floor value (prevents floor from growing unbounded)
float minFloor = 10.0f Minimum floor value (prevents floor from going to zero)

◆ fl::audio::ReactiveConfig

struct fl::audio::ReactiveConfig
Class Members
u8 attack = 50
float bassThreshold = 0.15f
u8 decay = 200
bool enableLogBinSpacing = true
bool enableMultiBand = true
bool enableMultiBandBeats = false
bool enableMusicalBeatDetection = false
bool enableNoiseFloorTracking = true
bool enableSignalConditioning = true
bool enableSpectralEqualizer = false
bool enableSpectralFlux = true
u8 gain = 128
float midThreshold = 0.12f
float musicalBeatConfidence = 0.5f
float musicalBeatMaxBPM = 180.0f
float musicalBeatMinBPM = 60.0f
bool noiseGate = true
u16 sampleRate = 22050
u8 scalingMode = 3
u8 sensitivity = 128
float spectralFluxThreshold = 0.1f
float trebleThreshold = 0.08f

◆ fl::audio::SignalConditionerConfig

struct fl::audio::SignalConditionerConfig
Class Members
bool enableDCRemoval = true Enable DC offset removal (running average high-pass filter)
bool enableNoiseGate = true Enable noise gate with hysteresis.
bool enableSpikeFilter = true Enable spike filtering for I2S glitches.
i16 noiseGateCloseThreshold = 300 Noise gate close threshold (signal must fall below to close gate)
i16 noiseGateOpenThreshold = 500 Noise gate open threshold (signal must exceed to open gate)
i16 spikeThreshold = 10000 Spike detection threshold (absolute value) Samples beyond ±spikeThreshold are rejected as glitches.

◆ fl::audio::SpectralEqualizerConfig

struct fl::audio::SpectralEqualizerConfig
+ Collaboration diagram for fl::audio::SpectralEqualizerConfig:
Class Members
bool applyMakeupGain = false Apply makeup gain to compensate for overall level changes If true, automatically adjusts overall gain to maintain average level.
float compressionRatio = 2.0f Compression ratio (1.0 = no compression, higher = more compression) 2.0 = 2:1 ratio, 4.0 = 4:1 ratio, etc.
float compressionThreshold = 0.7f Compression threshold (0.0-1.0) Signals above this level are compressed.
EqualizationCurve curve = EqualizationCurve::Flat Equalization curve type.
vector< float > customGains Custom per-band gain multipliers (only used if curve = Custom) Size must match numBands.

Default: all 1.0 (no eq)

bool enableCompression = false Enable dynamic range compression per band Compresses loud signals to reduce dynamic range.
float makeupGainTarget = 0.5f Makeup gain target level (0.0-1.0) The equalizer will scale output to maintain this average level.
size numBands = 16 Number of frequency bands (must match FrequencyBinMapper output)

Enumeration Type Documentation

◆ AGCPreset

enum class fl::audio::AGCPreset
strong

AGC preset selection — derived from WLED Sound Reactive's proven approach.

Normal/Vivid/Lazy control how quickly the AGC adapts to source-level changes.

Enumerator
AGCPreset_Normal 

Balanced: 3.3s peak decay, moderate PI gains.

AGCPreset_Vivid 

Faster response: 1.3s peak decay, higher PI gains.

AGCPreset_Lazy 

Slower, more stable: 6.7s peak decay, lower PI gains.

AGCPreset_Custom 

Use custom PI tuning fields below.

Definition at line 13 of file auto_gain.h.

13 {
18};
@ AGCPreset_Vivid
Faster response: 1.3s peak decay, higher PI gains.
Definition auto_gain.h:15
@ AGCPreset_Normal
Balanced: 3.3s peak decay, moderate PI gains.
Definition auto_gain.h:14
@ AGCPreset_Custom
Use custom PI tuning fields below.
Definition auto_gain.h:17
@ AGCPreset_Lazy
Slower, more stable: 6.7s peak decay, lower PI gains.
Definition auto_gain.h:16

◆ AudioChannel

enum class fl::audio::AudioChannel
strong
Enumerator
Left 
Right 
Both 

Definition at line 27 of file input.h.

27 {
28 Left = 0,
29 Right = 1,
30 Both = 2, // Two microphones can be used to capture both channels with one
31 // AudioSource.
32};

◆ EqualizationCurve

enum class fl::audio::EqualizationCurve
strong

Equalization curve type.

Enumerator
Flat 
AWeighting 
Custom 

Definition at line 12 of file spectral_equalizer.h.

12 {
13 Flat, // No equalization (all gains = 1.0)
14 AWeighting, // A-weighting curve (emphasizes 1-6 kHz, de-emphasizes bass/treble)
15 Custom // User-defined per-band gains
16};

◆ FrequencyBinMode

enum class fl::audio::FrequencyBinMode
strong

Frequency bin mode - controls number of output bins.

Enumerator
Bins16 
Bins32 

Definition at line 12 of file frequency_bin_mapper.h.

12 {
13 Bins16 = 16, // 16-bin mode (default, matches WLED)
14 Bins32 = 32 // 32-bin mode (higher resolution)
15};

◆ I2SCommFormat

enum class fl::audio::I2SCommFormat
strong
Enumerator
Philips 
MSB 
PCMShort 
PCMLong 
Max 

Definition at line 34 of file input.h.

34 {
35 Philips = 0X01, // I2S communication I2S Philips standard, data launch at
36 // second BCK
37 MSB = 0X02, // I2S communication MSB alignment standard, data launch at
38 // first BCK
39 PCMShort = 0x04, // PCM Short standard, also known as DSP mode. The period
40 // of synchronization signal (WS) is 1 bck cycle.
41 PCMLong = 0x0C, // PCM Long standard. The period of synchronization signal
42 // (WS) is channel_bit*bck cycles.
43 Max = 0x0F, // standard max
44};

◆ MicProfile

enum class fl::audio::MicProfile : u8
strong

Microphone frequency response correction profile.

Each profile provides 16-channel gain corrections to flatten the frequency response of a specific microphone. Derived from manufacturer datasheet data.

Set on Processor via setMicProfile() — the correction is applied inside EqualizerDetector before per-bin normalization.

Enumerator
None 

No correction (flat response assumed)

INMP441 

InvenSense INMP441 MEMS mic (most common)

ICS43434 

InvenSense ICS-43434 MEMS mic.

SPM1423 

Knowles SPM1423 MEMS mic.

GenericMEMS 

Generic MEMS microphone (moderate bass rolloff)

LineIn 

Line-in input (relatively flat, minor HF rolloff)

Definition at line 14 of file mic_profiles.h.

14 : u8 {
15 None,
16 INMP441,
17 ICS43434,
18 SPM1423,
20 LineIn,
21};
unsigned char u8
Definition stdint.h:131
@ None
Raw magnitudes (no scaling)
Definition equalizer.h:18
@ LineIn
Line-in input (relatively flat, minor HF rolloff)
@ GenericMEMS
Generic MEMS microphone (moderate bass rolloff)
@ INMP441
InvenSense INMP441 MEMS mic (most common)
@ ICS43434
InvenSense ICS-43434 MEMS mic.
@ SPM1423
Knowles SPM1423 MEMS mic.

◆ SynthShape

enum class fl::audio::SynthShape
strong

Predefined waveform shapes for synth oscillator.

Enumerator
Sawtooth 
Square 
Triangle 
AlternatingSaw 
Custom 

Definition at line 59 of file synth.h.

59 {
60 Sawtooth, // Classic sawtooth wave (reflect=1, peak=0, half=0, wait=0)
61 Square, // Classic square wave (reflect=1, peak=0, half=1, wait=0)
62 Triangle, // Classic triangle wave (reflect=1, peak=0.5, half=0, wait=0)
63 AlternatingSaw, // Alternating sawtooth (reflect=0, peak=0, half=0, wait=0)
64 Custom // User-defined parameters
65};

Function Documentation

◆ clamp01()

static float fl::audio::clamp01 ( float v)
static

Definition at line 457 of file audio_processor.cpp.hpp.

457 {
458 if (v < 0.0f) return 0.0f;
459 if (v > 1.0f) return 1.0f;
460 return v;
461}

References clamp01(), and fl::FL_NO_EXCEPT.

Referenced by clamp01(), fl::audio::Processor::getBackbeatConfidence(), fl::audio::Processor::getBackbeatStrength(), fl::audio::Processor::getBassLevel(), fl::audio::Processor::getBeatConfidence(), fl::audio::Processor::getBuildupIntensity(), fl::audio::Processor::getBuildupProgress(), fl::audio::Processor::getChordConfidence(), fl::audio::Processor::getDownbeatConfidence(), fl::audio::Processor::getDropImpact(), fl::audio::Processor::getEnergy(), fl::audio::Processor::getEqBass(), fl::audio::Processor::getEqBin(), fl::audio::Processor::getEqDominantMagnitude(), fl::audio::Processor::getEqMid(), fl::audio::Processor::getEqTreble(), fl::audio::Processor::getEqVolume(), fl::audio::Processor::getEqVolumeNormFactor(), fl::audio::Processor::getEqZcf(), fl::audio::Processor::getKeyConfidence(), fl::audio::Processor::getMeasurePhase(), fl::audio::Processor::getMidLevel(), fl::audio::Processor::getMoodArousal(), fl::audio::Processor::getPeakLevel(), fl::audio::Processor::getPitchConfidence(), fl::audio::Processor::getTempoConfidence(), fl::audio::Processor::getTransientStrength(), fl::audio::Processor::getTrebleLevel(), and fl::audio::Processor::getVocalConfidence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clampNeg1To1()

static float fl::audio::clampNeg1To1 ( float v)
static

Definition at line 464 of file audio_processor.cpp.hpp.

464 {
465 if (v < -1.0f) return -1.0f;
466 if (v > 1.0f) return 1.0f;
467 return v;
468}

References clampNeg1To1(), and fl::FL_NO_EXCEPT.

Referenced by clampNeg1To1(), fl::audio::Processor::getDynamicTrend(), and fl::audio::Processor::getMoodValence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ computeAudioDt()

float fl::audio::computeAudioDt ( fl::size pcmSize,
int sampleRate )
inline

Compute the time delta (in seconds) for an audio buffer.

Each buffer of pcmSize samples at sampleRate Hz represents exactly pcmSize/sampleRate seconds of audio, regardless of when the CPU reads it.

Definition at line 101 of file audio_context.h.

101 {
102 if (sampleRate <= 0 || pcmSize == 0) return 0.0f;
103 return static_cast<float>(pcmSize) / static_cast<float>(sampleRate);
104}

References fl::FL_NO_EXCEPT.

Referenced by fl::audio::Reactive::processSample(), fl::audio::detector::EnergyAnalyzer::update(), fl::audio::detector::EqualizerDetector::update(), fl::audio::detector::FrequencyBands::update(), fl::audio::detector::Percussion::update(), fl::audio::detector::Pitch::update(), fl::audio::detector::Vibe::update(), and fl::audio::detector::Vocal::update().

+ Here is the caller graph for this function:

◆ computePinkNoiseGain()

float fl::audio::computePinkNoiseGain ( float freq_hz,
float f_ref )
inline

Compute pink noise compensation gain for a single frequency.

Pink noise has 1/f spectral density → equal power per octave. To flatten it: multiply by sqrt(f / f_ref).

Parameters
freq_hzBin center frequency in Hz
f_refReference frequency (typically geometric mean of all bins)
Returns
Compensation gain factor

Definition at line 285 of file mic_response_data.h.

285 {
286 if (freq_hz <= 0.0f || f_ref <= 0.0f) return 1.0f;
287 return fl::sqrtf(freq_hz / f_ref);
288}
float sqrtf(float value) FL_NO_EXCEPT
Definition math.h:461

References fl::FL_NO_EXCEPT, and fl::sqrtf().

Referenced by computePinkNoiseGains().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ computePinkNoiseGains()

void fl::audio::computePinkNoiseGains ( const float * binCenters,
int numBins,
float * out )
inline

Compute pink noise compensation gains for all bins.

Normalizes so the geometric mean of all gains ≈ 1.0.

Parameters
binCentersArray of bin center frequencies (Hz)
numBinsNumber of bins
outOutput array of gains (length numBins)

Definition at line 295 of file mic_response_data.h.

295 {
296 if (numBins <= 0) return;
297
298 // Compute geometric mean of bin centers for f_ref
299 float logSum = 0.0f;
300 int validCount = 0;
301 for (int i = 0; i < numBins; ++i) {
302 if (binCenters[i] > 0.0f) {
303 logSum += fl::logf(binCenters[i]);
304 ++validCount;
305 }
306 }
307 float f_ref = (validCount > 0)
308 ? fl::expf(logSum / static_cast<float>(validCount))
309 : 1000.0f;
310
311 // Compute raw gains
312 for (int i = 0; i < numBins; ++i) {
313 out[i] = computePinkNoiseGain(binCenters[i], f_ref);
314 }
315
316 // Cap individual gains to prevent extreme boosting of high-frequency bins
317 static constexpr float kMaxPinkNoiseGain = 3.0f;
318 for (int i = 0; i < numBins; ++i) {
319 if (out[i] > kMaxPinkNoiseGain) {
320 out[i] = kMaxPinkNoiseGain;
321 }
322 }
323
324 // Normalize so geometric mean of output gains = 1.0
325 float outLogSum = 0.0f;
326 for (int i = 0; i < numBins; ++i) {
327 if (out[i] > 0.0f) {
328 outLogSum += fl::logf(out[i]);
329 }
330 }
331 float geoMean = fl::expf(outLogSum / static_cast<float>(numBins));
332 if (geoMean > 0.001f) {
333 for (int i = 0; i < numBins; ++i) {
334 out[i] /= geoMean;
335 }
336 }
337}
float computePinkNoiseGain(float freq_hz, float f_ref) FL_NO_EXCEPT
Compute pink noise compensation gain for a single frequency.
float logf(float value) FL_NO_EXCEPT
Definition math.h:426
float expf(float value) FL_NO_EXCEPT
Definition math.h:406

References computePinkNoiseGain(), fl::expf(), fl::FL_NO_EXCEPT, and fl::logf().

Referenced by fl::audio::Reactive::begin(), and fl::audio::detector::EqualizerDetector::recomputePinkNoiseGains().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ downsampleMicResponse()

void fl::audio::downsampleMicResponse ( const MicResponseCurve & curve,
const float * binCenters,
int numBins,
float * out )
inline

Downsample a high-resolution mic response curve to N output bins.

Parameters
curveThe source mic response curve
binCentersArray of bin center frequencies (Hz), length numBins
numBinsNumber of output bins
outOutput array of gains, length numBins

Definition at line 267 of file mic_response_data.h.

269 {
270 for (int i = 0; i < numBins; ++i) {
271 out[i] = interpolateMicResponse(curve, binCenters[i]);
272 }
273}
float interpolateMicResponse(const MicResponseCurve &curve, float freq_hz) FL_NO_EXCEPT
Interpolate mic response at an arbitrary frequency (Hz).

References fl::FL_NO_EXCEPT, and interpolateMicResponse().

Referenced by fl::audio::detector::EqualizerDetector::setMicProfile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FASTLED_SHARED_PTR() [1/3]

fl::audio::FASTLED_SHARED_PTR ( ISynthEngine )

◆ FASTLED_SHARED_PTR() [2/3]

fl::audio::FASTLED_SHARED_PTR ( ISynthOscillator )

◆ FASTLED_SHARED_PTR() [3/3]

fl::audio::FASTLED_SHARED_PTR ( SampleImpl )

◆ fl_progmem_read_float()

float fl::audio::fl_progmem_read_float ( const float * addr)
inline

Read a float from PROGMEM.

On AVR this reads flash via pgm_read_dword; on other platforms it's a plain memory read via memcpy (no aliasing issues).

Definition at line 26 of file mic_response_data.h.

26 {
27 u32 raw = FL_PGM_READ_DWORD_ALIGNED(addr);
28 float result;
29 FL_BUILTIN_MEMCPY(&result, &raw, sizeof(float));
30 return result;
31}
#define FL_PGM_READ_DWORD_ALIGNED(addr)
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
#define FL_BUILTIN_MEMCPY(dest, src, n)

References FL_BUILTIN_MEMCPY, fl::FL_NO_EXCEPT, and FL_PGM_READ_DWORD_ALIGNED.

Referenced by interpolateMicResponse().

+ Here is the caller graph for this function:

◆ getMicResponseCurve()

MicResponseCurve fl::audio::getMicResponseCurve ( MicProfile profile)
inline

Get the high-resolution response curve for a given mic profile.

Returns a curve with count=0 for MicProfile::None.

Definition at line 198 of file mic_response_data.h.

198 {
199 MicResponseCurve curve = {nullptr, nullptr, 0};
200 switch (profile) {
203 break;
206 break;
209 break;
212 break;
215 break;
216 case MicProfile::None:
217 default:
218 break;
219 }
220 return curve;
221}
@ None
No correction (flat response assumed)
static const float kMicResponse_GenericMEMS[kMicResponsePoints]
static const float kMicResponse_ICS43434[kMicResponsePoints]
static const float kMicResponseFreqs[kMicResponsePoints]
static const float kMicResponse_SPM1423[kMicResponsePoints]
static constexpr int kMicResponsePoints
static const float kMicResponse_INMP441[kMicResponsePoints]
static const float kMicResponse_LineIn[kMicResponsePoints]

References fl::FL_NO_EXCEPT, GenericMEMS, ICS43434, INMP441, kMicResponse_GenericMEMS, kMicResponse_ICS43434, kMicResponse_INMP441, kMicResponse_LineIn, kMicResponse_SPM1423, kMicResponseFreqs, kMicResponsePoints, LineIn, None, and SPM1423.

Referenced by fl::audio::detector::EqualizerDetector::setMicProfile().

+ Here is the caller graph for this function:

◆ interpolateMicResponse()

float fl::audio::interpolateMicResponse ( const MicResponseCurve & curve,
float freq_hz )
inline

Interpolate mic response at an arbitrary frequency (Hz).

Uses log-frequency linear interpolation with binary search. Clamps to endpoint values outside the data range.

Definition at line 230 of file mic_response_data.h.

230 {
231 if (curve.count <= 0 || !curve.freqs || !curve.gains) return 1.0f;
232
233 float f0 = fl_progmem_read_float(&curve.freqs[0]);
234 float fN = fl_progmem_read_float(&curve.freqs[curve.count - 1]);
235
236 // Clamp to endpoints
237 if (freq_hz <= f0) return fl_progmem_read_float(&curve.gains[0]);
238 if (freq_hz >= fN) return fl_progmem_read_float(&curve.gains[curve.count - 1]);
239
240 // Binary search for bracketing interval
241 int lo = 0, hi = curve.count - 1;
242 while (hi - lo > 1) {
243 int mid = (lo + hi) / 2;
244 float fMid = fl_progmem_read_float(&curve.freqs[mid]);
245 if (freq_hz < fMid) {
246 hi = mid;
247 } else {
248 lo = mid;
249 }
250 }
251
252 float fLo = fl_progmem_read_float(&curve.freqs[lo]);
253 float fHi = fl_progmem_read_float(&curve.freqs[hi]);
254 float gLo = fl_progmem_read_float(&curve.gains[lo]);
255 float gHi = fl_progmem_read_float(&curve.gains[hi]);
256
257 // Log-frequency linear interpolation
258 float logFrac = fl::logf(freq_hz / fLo) / fl::logf(fHi / fLo);
259 return gLo + (gHi - gLo) * logFrac;
260}
float fl_progmem_read_float(const float *addr) FL_NO_EXCEPT
Read a float from PROGMEM.
const float * freqs
Pointer to frequency array (PROGMEM)
int count
Number of data points.
const float * gains
Pointer to gain array (PROGMEM)

References fl::FL_NO_EXCEPT, fl_progmem_read_float(), and fl::logf().

Referenced by downsampleMicResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platform_create_audio_input()

fl::shared_ptr< IInput > fl::audio::platform_create_audio_input ( const Config & config,
fl::string * error_message )

Definition at line 100 of file audio_input.cpp.hpp.

100 {
101 FL_UNUSED(config); // no audio input here to configure
102 if (error_message) {
103 *error_message = "AudioInput not supported on this platform.";
104 }
106}
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
#define FL_UNUSED(x)

References fl::FL_NO_EXCEPT, FL_UNUSED, and fl::adl_barrier::make_shared().

Referenced by fl::audio::IInput::create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ kMicResponse_GenericMEMS

const float fl::audio::kMicResponse_GenericMEMS[kMicResponsePoints]
static
Initial value:
= {
3.65f, 3.35f, 3.00f, 2.70f, 2.40f, 2.10f,
1.82f, 1.60f, 1.42f, 1.29f, 1.19f, 1.12f,
1.07f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
0.99f, 0.97f, 0.95f, 0.94f, 0.92f, 0.91f,
0.89f, 0.86f, 0.84f, 0.81f, 0.79f, 0.78f,
0.76f, 0.76f, 0.77f, 0.80f, 0.85f, 0.91f,
0.95f
}

Definition at line 146 of file mic_response_data.h.

146 {
147 // 20-36 Hz (f[0..5])
148 3.65f, 3.35f, 3.00f, 2.70f, 2.40f, 2.10f,
149 // 40-71 Hz (f[6..11])
150 1.82f, 1.60f, 1.42f, 1.29f, 1.19f, 1.12f,
151 // 80-143 Hz (f[12..17])
152 1.07f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
153 // 160-285 Hz (f[18..23])
154 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
155 // 320-570 Hz (f[24..29])
156 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
157 // 640-1140 Hz (f[30..35])
158 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
159 // 1280-2281 Hz (f[36..41])
160 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
161 // 2560-4562 Hz (f[42..47])
162 0.99f, 0.97f, 0.95f, 0.94f, 0.92f, 0.91f,
163 // 5120-9123 Hz (f[48..53])
164 0.89f, 0.86f, 0.84f, 0.81f, 0.79f, 0.78f,
165 // 10240-18247 Hz (f[54..59])
166 0.76f, 0.76f, 0.77f, 0.80f, 0.85f, 0.91f,
167 // 20480 Hz (f[60])
168 0.95f
169};

Referenced by getMicResponseCurve().

◆ kMicResponse_ICS43434

const float fl::audio::kMicResponse_ICS43434[kMicResponsePoints]
static
Initial value:
= {
3.80f, 3.50f, 3.10f, 2.80f, 2.50f, 2.20f,
1.90f, 1.65f, 1.45f, 1.30f, 1.20f, 1.13f,
1.08f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
0.98f, 0.96f, 0.93f, 0.91f, 0.89f, 0.87f,
0.85f, 0.83f, 0.81f, 0.80f, 0.79f, 0.78f,
0.77f, 0.77f, 0.78f, 0.80f, 0.83f, 0.87f,
0.90f
}

Definition at line 92 of file mic_response_data.h.

92 {
93 // 20-36 Hz: significant bass rolloff (f[0..5])
94 3.80f, 3.50f, 3.10f, 2.80f, 2.50f, 2.20f,
95 // 40-71 Hz: moderate rolloff (f[6..11])
96 1.90f, 1.65f, 1.45f, 1.30f, 1.20f, 1.13f,
97 // 80-143 Hz: transitioning to flat (f[12..17])
98 1.08f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
99 // 160-285 Hz (f[18..23])
100 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
101 // 320-570 Hz (f[24..29])
102 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
103 // 640-1140 Hz (f[30..35])
104 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
105 // 1280-2281 Hz: flat (f[36..41])
106 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
107 // 2560-4562 Hz: beginning of HF rise (f[42..47])
108 0.98f, 0.96f, 0.93f, 0.91f, 0.89f, 0.87f,
109 // 5120-9123 Hz: strong HF rise (f[48..53])
110 0.85f, 0.83f, 0.81f, 0.80f, 0.79f, 0.78f,
111 // 10240-18247 Hz: very hot at HF (f[54..59])
112 0.77f, 0.77f, 0.78f, 0.80f, 0.83f, 0.87f,
113 // 20480 Hz (f[60])
114 0.90f
115};

Referenced by getMicResponseCurve().

◆ kMicResponse_INMP441

const float fl::audio::kMicResponse_INMP441[kMicResponsePoints]
static
Initial value:
= {
3.50f, 3.20f, 2.90f, 2.60f, 2.30f, 2.00f,
1.74f, 1.55f, 1.40f, 1.28f, 1.18f, 1.12f,
1.07f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 0.99f, 0.98f, 0.97f, 0.96f, 0.95f,
0.93f, 0.90f, 0.87f, 0.83f, 0.80f, 0.78f,
0.76f, 0.75f, 0.76f, 0.80f, 0.88f, 0.95f,
1.00f
}

Definition at line 64 of file mic_response_data.h.

64 {
65 // 20-36 Hz: significant bass rolloff (f[0..5])
66 3.50f, 3.20f, 2.90f, 2.60f, 2.30f, 2.00f,
67 // 40-71 Hz: moderate rolloff (f[6..11])
68 1.74f, 1.55f, 1.40f, 1.28f, 1.18f, 1.12f,
69 // 80-143 Hz: transitioning to flat (f[12..17])
70 1.07f, 1.04f, 1.02f, 1.01f, 1.00f, 1.00f,
71 // 160-285 Hz: essentially flat (f[18..23])
72 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
73 // 320-570 Hz: flat (f[24..29])
74 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
75 // 640-1140 Hz: flat (f[30..35])
76 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
77 // 1280-2281 Hz: flat (f[36..41])
78 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
79 // 2560-4562 Hz: beginning of rise (f[42..47])
80 1.00f, 0.99f, 0.98f, 0.97f, 0.96f, 0.95f,
81 // 5120-9123 Hz: resonance approach (f[48..53])
82 0.93f, 0.90f, 0.87f, 0.83f, 0.80f, 0.78f,
83 // 10240-18247 Hz: resonance peak region (f[54..59])
84 0.76f, 0.75f, 0.76f, 0.80f, 0.88f, 0.95f,
85 // 20480 Hz (f[60])
86 1.00f
87};

Referenced by getMicResponseCurve().

◆ kMicResponse_LineIn

const float fl::audio::kMicResponse_LineIn[kMicResponsePoints]
static
Initial value:
= {
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f
}

Definition at line 172 of file mic_response_data.h.

172 {
173 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
174 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
175 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
176 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
177 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
178 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
179 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
180 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
181 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
182 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
183 1.0f
184};

Referenced by getMicResponseCurve().

◆ kMicResponse_SPM1423

const float fl::audio::kMicResponse_SPM1423[kMicResponsePoints]
static
Initial value:
= {
2.80f, 2.60f, 2.40f, 2.20f, 2.00f, 1.80f,
1.60f, 1.45f, 1.32f, 1.22f, 1.15f, 1.10f,
1.06f, 1.03f, 1.01f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
0.98f, 0.96f, 0.94f, 0.93f, 0.92f, 0.91f,
0.90f, 0.89f, 0.88f, 0.87f, 0.86f, 0.85f,
0.84f, 0.84f, 0.85f, 0.87f, 0.90f, 0.93f,
0.95f
}

Definition at line 120 of file mic_response_data.h.

120 {
121 // 20-36 Hz: bass rolloff (f[0..5])
122 2.80f, 2.60f, 2.40f, 2.20f, 2.00f, 1.80f,
123 // 40-71 Hz: moderate rolloff (f[6..11])
124 1.60f, 1.45f, 1.32f, 1.22f, 1.15f, 1.10f,
125 // 80-143 Hz: transitioning to flat (f[12..17])
126 1.06f, 1.03f, 1.01f, 1.00f, 1.00f, 1.00f,
127 // 160-285 Hz (f[18..23])
128 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
129 // 320-570 Hz (f[24..29])
130 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
131 // 640-1140 Hz (f[30..35])
132 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
133 // 1280-2281 Hz: flat (f[36..41])
134 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f,
135 // 2560-4562 Hz: slight HF rise (f[42..47])
136 0.98f, 0.96f, 0.94f, 0.93f, 0.92f, 0.91f,
137 // 5120-9123 Hz: moderate rise (f[48..53])
138 0.90f, 0.89f, 0.88f, 0.87f, 0.86f, 0.85f,
139 // 10240-18247 Hz: strong rise (f[54..59])
140 0.84f, 0.84f, 0.85f, 0.87f, 0.90f, 0.93f,
141 // 20480 Hz (f[60])
142 0.95f
143};

Referenced by getMicResponseCurve().

◆ kMicResponseFreqs

const float fl::audio::kMicResponseFreqs[kMicResponsePoints]
static
Initial value:
= {
20.0f, 22.4f, 25.2f, 28.3f, 31.7f, 35.6f,
40.0f, 44.9f, 50.4f, 56.6f, 63.5f, 71.3f,
80.0f, 89.8f, 100.8f, 113.1f, 127.0f, 142.5f,
160.0f, 179.6f, 201.6f, 226.3f, 254.0f, 285.1f,
320.0f, 359.1f, 403.1f, 452.5f, 508.0f, 570.2f,
640.0f, 718.3f, 806.3f, 905.1f, 1016.0f, 1140.4f,
1280.0f, 1436.5f, 1612.5f, 1810.2f, 2032.0f, 2280.8f,
2560.0f, 2873.1f, 3225.0f, 3620.4f, 4064.0f, 4561.6f,
5120.0f, 5746.1f, 6450.0f, 7240.8f, 8128.0f, 9123.2f,
10240.0f, 11492.2f, 12900.0f, 14481.6f, 16256.1f, 18246.5f,
20480.0f
}

Definition at line 42 of file mic_response_data.h.

42 {
43 20.0f, 22.4f, 25.2f, 28.3f, 31.7f, 35.6f, // 0- 5
44 40.0f, 44.9f, 50.4f, 56.6f, 63.5f, 71.3f, // 6-11
45 80.0f, 89.8f, 100.8f, 113.1f, 127.0f, 142.5f, // 12-17
46 160.0f, 179.6f, 201.6f, 226.3f, 254.0f, 285.1f, // 18-23
47 320.0f, 359.1f, 403.1f, 452.5f, 508.0f, 570.2f, // 24-29
48 640.0f, 718.3f, 806.3f, 905.1f, 1016.0f, 1140.4f, // 30-35
49 1280.0f, 1436.5f, 1612.5f, 1810.2f, 2032.0f, 2280.8f, // 36-41
50 2560.0f, 2873.1f, 3225.0f, 3620.4f, 4064.0f, 4561.6f, // 42-47
51 5120.0f, 5746.1f, 6450.0f, 7240.8f, 8128.0f, 9123.2f, // 48-53
52 10240.0f, 11492.2f, 12900.0f, 14481.6f, 16256.1f, 18246.5f, // 54-59
53 20480.0f // 60
54};

Referenced by getMicResponseCurve().

◆ kMicResponsePoints

int fl::audio::kMicResponsePoints = 61
staticconstexpr

Definition at line 37 of file mic_response_data.h.

Referenced by getMicResponseCurve().