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

Function makeSnare

tests/fl/audio/test_helpers.h:387–416  ·  view source on GitHub ↗

Generate a synthetic snare: 250Hz body (25ms decay) + high-frequency noise (50ms decay) Produces moderate bass + significant treble energy from noise rattles

Source from the content-addressed store, hash-verified

385/// Generate a synthetic snare: 250Hz body (25ms decay) + high-frequency noise (50ms decay)
386/// Produces moderate bass + significant treble energy from noise rattles
387inline Sample makeSnare(fl::u32 timestamp, float amplitude = 16000.0f,
388 int count = 512, float sampleRate = 44100.0f) {
389 fl::fl_random rng(42); // Deterministic seed
390 fl::vector<fl::i16> data(count, 0);
391 float prevNoise = 0.0f;
392 for (int i = 0; i < count; ++i) {
393 float t = static_cast<float>(i) / sampleRate;
394 // Tonal body: 250Hz with 25ms decay — reduced to let treble dominate
395 float bodyDecay = fl::expf(-t / 0.025f);
396 float body = amplitude * 0.20f * bodyDecay * fl::sinf(2.0f * FL_M_PI * 250.0f * t);
397 // Noise rattle: high-pass filtered white noise with 50ms decay
398 float noiseDecay = fl::expf(-t / 0.050f);
399 float rawNoise = (static_cast<float>(rng.random16()) / 32767.5f) - 1.0f;
400 // Second-order high-pass approximation for stronger treble content
401 float highPassNoise = rawNoise - 0.95f * prevNoise;
402 prevNoise = rawNoise;
403 float noise = amplitude * 0.80f * noiseDecay * highPassNoise;
404 // Also add explicit high-frequency tones to boost CQ treble bins
405 float trebleTones = amplitude * 0.25f * bodyDecay * (
406 0.4f * fl::sinf(2.0f * FL_M_PI * 2000.0f * t) +
407 0.3f * fl::sinf(2.0f * FL_M_PI * 3500.0f * t) +
408 0.3f * fl::sinf(2.0f * FL_M_PI * 4500.0f * t)
409 );
410 float sample = body + noise + trebleTones;
411 if (sample > 32767.0f) sample = 32767.0f;
412 if (sample < -32768.0f) sample = -32768.0f;
413 data[i] = static_cast<fl::i16>(sample);
414 }
415 return Sample(data, timestamp);
416}
417
418/// Generate a synthetic hi-hat: high-pass shaped white noise
419/// @param open If true, use 80ms decay (open hi-hat); if false, use 5ms decay (closed)

Callers 2

makeFullBandMixFunction · 0.85
percussion.hppFile · 0.85

Calls 4

expfFunction · 0.85
sinfFunction · 0.85
random16Method · 0.80
SampleClass · 0.50

Tested by

no test coverage detected