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

Function makeVoiceInMixLike

tests/fl/audio/detector/vocal.hpp:373–405  ·  view source on GitHub ↗

Generate a voice-in-mix-like signal matching real MP3 CQ features: centroid ~0.21, rolloff ~0.24, flatness ~0.46, density ~48 Guitar-like broadband base + strong harmonic overtones at voice fundamental. The harmonics create peaks in specific CQ bins, lowering flatness compared to the uniform guitar spectrum.

Source from the content-addressed store, hash-verified

371/// fundamental. The harmonics create peaks in specific CQ bins,
372/// lowering flatness compared to the uniform guitar spectrum.
373inline audio::Sample makeVoiceInMixLike(fl::u32 timestamp, float amplitude = 16000.0f,
374 int count = 512, float sampleRate = 44100.0f) {
375 fl::vector<fl::i16> data(count, 0);
376 fl::fl_random rng(43);
377
378 const float fMin = 150.0f;
379 const float fMax = 5000.0f;
380
381 // 1. Weak broadband base (much weaker than guitar → harmonics dominate)
382 const int numComponents = 30;
383 for (int c = 0; c < numComponents; ++c) {
384 float t = static_cast<float>(rng.random16()) / 65535.0f;
385 float freq = fMin * fl::powf(fMax / fMin, t);
386 float envAmp = amplitude * 0.015f / fl::powf(freq / fMin, 1.1f);
387 float phase0 = static_cast<float>(rng.random16()) / 65535.0f * 2.0f * FL_M_PI;
388 for (int i = 0; i < count; ++i) {
389 float phase = phase0 + 2.0f * FL_M_PI * freq * i / sampleRate;
390 data[i] += static_cast<fl::i16>(envAmp * fl::sinf(phase));
391 }
392 }
393
394 // 2. Very strong voice harmonics → dominate over broadband → lower flatness
395 const float f0 = 180.0f;
396 for (int h = 1; h * f0 < fMax; ++h) {
397 float freq = f0 * h;
398 float harmonicAmp = amplitude * 0.3f / fl::powf(static_cast<float>(h), 1.2f);
399 for (int i = 0; i < count; ++i) {
400 float phase = 2.0f * FL_M_PI * freq * i / sampleRate;
401 data[i] += static_cast<fl::i16>(harmonicAmp * fl::sinf(phase));
402 }
403 }
404 return audio::Sample(data, timestamp);
405}
406
407} // namespace test_vocal
408

Callers 1

vocal.hppFile · 0.85

Calls 4

powfFunction · 0.85
sinfFunction · 0.85
random16Method · 0.80
SampleClass · 0.50

Tested by

no test coverage detected