Generate pink noise (1/f spectrum, equal energy per octave)
| 53 | |
| 54 | // Generate pink noise (1/f spectrum, equal energy per octave) |
| 55 | static 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 |
| 79 | static void generateSine(fl::vector<fl::i16> &buf, int samples, |
no test coverage detected