MCPcopy Create free account
hub / github.com/FastLED/FastLED / makeMix

Function makeMix

tests/misc/vibe_mid_treb_dynamic_range.hpp:32–50  ·  view source on GitHub ↗

Generate a multi-frequency audio::Sample (bass + mid + treble mixed)

Source from the content-addressed store, hash-verified

30
31// Generate a multi-frequency audio::Sample (bass + mid + treble mixed)
32audio::Sample makeMix(float bassAmp, float midAmp, float trebAmp,
33 u32 timestamp, int count = 512,
34 float sampleRate = 44100.0f) {
35 vector<i16> data(count, 0);
36 // Bass: 200 Hz (well inside 20-3688 Hz band)
37 // Mid: 5000 Hz (well inside 3688-7356 Hz band)
38 // Treble: 9000 Hz (well inside 7356-11025 Hz band)
39 const float freqs[3] = {200.0f, 5000.0f, 9000.0f};
40 const float amps[3] = {bassAmp, midAmp, trebAmp};
41
42 for (int band = 0; band < 3; ++band) {
43 for (int i = 0; i < count; ++i) {
44 float phase = 2.0f * FL_M_PI * freqs[band] * i / sampleRate;
45 float sample = amps[band] * fl::sinf(phase);
46 data[i] = clampI16(static_cast<float>(data[i]) + sample);
47 }
48 }
49 return audio::Sample(data, timestamp);
50}
51
52// Generate a multi-frequency audio::Sample with broadband noise floor.
53// Models a MEMS mic (INMP441): self-noise adds continuous energy to all

Callers 1

Calls 3

sinfFunction · 0.85
clampI16Function · 0.85
SampleClass · 0.50

Tested by

no test coverage detected