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

Function generatePinkNoise

tests/profile/fft_cq_compare.cpp:55–76  ·  view source on GitHub ↗

Generate pink noise (1/f spectrum, equal energy per octave)

Source from the content-addressed store, hash-verified

53
54// Generate pink noise (1/f spectrum, equal energy per octave)
55static void generatePinkNoise(fl::vector<fl::i16> &buf, int samples) {
56 buf.resize(samples);
57 fl_random rng(54321);
58 const int NUM_OCTAVES = 8;
59 fl::i32 octaveValues[NUM_OCTAVES] = {};
60 for (int o = 0; o < NUM_OCTAVES; o++) {
61 octaveValues[o] = static_cast<fl::i32>(rng.random16()) - 32768;
62 }
63 for (int i = 0; i < samples; i++) {
64 for (int o = 0; o < NUM_OCTAVES; o++) {
65 if ((i & ((1 << o) - 1)) == 0) {
66 octaveValues[o] =
67 static_cast<fl::i32>(rng.random16()) - 32768;
68 }
69 }
70 fl::i32 sum = 0;
71 for (int o = 0; o < NUM_OCTAVES; o++) {
72 sum += octaveValues[o];
73 }
74 buf[i] = static_cast<fl::i16>(sum / NUM_OCTAVES * 20000 / 32768);
75 }
76}
77
78// Generate a pure sine wave at a specific frequency
79static void generateSine(fl::vector<fl::i16> &buf, int samples,

Callers 1

runBenchmarkFunction · 0.85

Calls 2

random16Method · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected