FastLED 3.9.15
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)
 
static float clampNeg1To1 (float v)
 
float computeAudioDt (fl::size pcmSize, int sampleRate) FL_NOEXCEPT
 Compute the time delta (in seconds) for an audio buffer.
 
float computePinkNoiseGain (float freq_hz, float f_ref)
 Compute pink noise compensation gain for a single frequency.
 
void computePinkNoiseGains (const float *binCenters, int numBins, float *out)
 Compute pink noise compensation gains for all bins.
 
void downsampleMicResponse (const MicResponseCurve &curve, const float *binCenters, int numBins, float *out)
 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)
 Read a float from PROGMEM.
 
MicResponseCurve getMicResponseCurve (MicProfile profile)
 Get the high-resolution response curve for a given mic profile.
 
float interpolateMicResponse (const MicResponseCurve &curve, float freq_hz)
 Interpolate mic response at an arbitrary frequency (Hz).
 
FL_LINK_WEAK fl::shared_ptr< IInputplatform_create_audio_input (const Config &config, fl::string *error_message)
 

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().

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().

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_NOEXCEPT.

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 284 of file mic_response_data.h.

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

References 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 294 of file mic_response_data.h.

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

References computePinkNoiseGain(), fl::expf(), 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 266 of file mic_response_data.h.

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

References 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 25 of file mic_response_data.h.

25 {
26 u32 raw = FL_PGM_READ_DWORD_ALIGNED(addr);
27 float result;
28 FL_BUILTIN_MEMCPY(&result, &raw, sizeof(float));
29 return result;
30}
#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, 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 197 of file mic_response_data.h.

197 {
198 MicResponseCurve curve = {nullptr, nullptr, 0};
199 switch (profile) {
202 break;
205 break;
208 break;
211 break;
214 break;
215 case MicProfile::None:
216 default:
217 break;
218 }
219 return curve;
220}
@ 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 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 229 of file mic_response_data.h.

229 {
230 if (curve.count <= 0 || !curve.freqs || !curve.gains) return 1.0f;
231
232 float f0 = fl_progmem_read_float(&curve.freqs[0]);
233 float fN = fl_progmem_read_float(&curve.freqs[curve.count - 1]);
234
235 // Clamp to endpoints
236 if (freq_hz <= f0) return fl_progmem_read_float(&curve.gains[0]);
237 if (freq_hz >= fN) return fl_progmem_read_float(&curve.gains[curve.count - 1]);
238
239 // Binary search for bracketing interval
240 int lo = 0, hi = curve.count - 1;
241 while (hi - lo > 1) {
242 int mid = (lo + hi) / 2;
243 float fMid = fl_progmem_read_float(&curve.freqs[mid]);
244 if (freq_hz < fMid) {
245 hi = mid;
246 } else {
247 lo = mid;
248 }
249 }
250
251 float fLo = fl_progmem_read_float(&curve.freqs[lo]);
252 float fHi = fl_progmem_read_float(&curve.freqs[hi]);
253 float gLo = fl_progmem_read_float(&curve.gains[lo]);
254 float gHi = fl_progmem_read_float(&curve.gains[hi]);
255
256 // Log-frequency linear interpolation
257 float logFrac = fl::logf(freq_hz / fLo) / fl::logf(fHi / fLo);
258 return gLo + (gHi - gLo) * logFrac;
259}
float fl_progmem_read_float(const float *addr)
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::audio::MicResponseCurve::count, fl_progmem_read_float(), fl::audio::MicResponseCurve::freqs, fl::audio::MicResponseCurve::gains, 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 99 of file audio_input.cpp.hpp.

99 {
100 if (error_message) {
101 *error_message = "AudioInput not supported on this platform.";
102 }
104}
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414

References fl::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 145 of file mic_response_data.h.

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

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 91 of file mic_response_data.h.

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

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 63 of file mic_response_data.h.

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

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 171 of file mic_response_data.h.

171 {
172 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
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
183};

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 119 of file mic_response_data.h.

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

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 41 of file mic_response_data.h.

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

Referenced by getMicResponseCurve().

◆ kMicResponsePoints

int fl::audio::kMicResponsePoints = 61
staticconstexpr

Definition at line 36 of file mic_response_data.h.

Referenced by getMicResponseCurve().