Generate a synthetic crash cymbal: broadband noise with 80ms decay All treble bins have similar energy (high flatness)
| 458 | /// Generate a synthetic crash cymbal: broadband noise with 80ms decay |
| 459 | /// All treble bins have similar energy (high flatness) |
| 460 | inline Sample makeCrashCymbal(fl::u32 timestamp, float amplitude = 16000.0f, |
| 461 | int count = 512, float sampleRate = 44100.0f) { |
| 462 | fl::fl_random rng(77); // Deterministic seed |
| 463 | fl::vector<fl::i16> data(count, 0); |
| 464 | for (int i = 0; i < count; ++i) { |
| 465 | float t = static_cast<float>(i) / sampleRate; |
| 466 | float decay = fl::expf(-t / 0.080f); |
| 467 | float noiseVal = (static_cast<float>(rng.random16()) / 32767.5f) - 1.0f; |
| 468 | float sample = amplitude * decay * noiseVal; |
| 469 | if (sample > 32767.0f) sample = 32767.0f; |
| 470 | if (sample < -32768.0f) sample = -32768.0f; |
| 471 | data[i] = static_cast<fl::i16>(sample); |
| 472 | } |
| 473 | return Sample(data, timestamp); |
| 474 | } |
| 475 | |
| 476 | // ============================================================================ |
| 477 | // Realistic Instrument Generators (calibrated to match real audio features) |