Created
January 27, 2026 06:29
-
-
Save LightningStalker/5673da4e665c7a99c2197d169aedc889 to your computer and use it in GitHub Desktop.
Generate the pink noise by Voss-McCartney
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Voss-McCartney pink noise | |
| * http://en.wikipedia.org/Pink_Noise | |
| * Project Crew™ 1/27/2026 | |
| * | |
| * S16_LE, 44100Hz Mono raw to stdout | |
| * It still needs a steep low freq high pass to be use | |
| */ | |
| #include <iostream> | |
| #include <random> | |
| #include <array> | |
| #include <numeric> | |
| #include <cmath> | |
| using namespace std; | |
| #define N_STREAMS 64 | |
| #define VOLMAX 120000 / N_STREAMS | |
| #define RATE 44100 | |
| #define SECONDS 2 | |
| #define TIME RATE * SECONDS | |
| #define ENDIAN LE | |
| int | |
| main() | |
| { | |
| random_device&& rd = random_device {}; | |
| static uniform_int_distribution<int> d(-VOLMAX, VOLMAX); | |
| array<uint16_t, N_STREAMS> streams; | |
| uint16_t it; | |
| char ch, cl; | |
| int i, j; | |
| for(i = 0; i < TIME; i++) | |
| { | |
| for(j = 0; j < N_STREAMS; j++) | |
| { | |
| if(i % (1 << j) == 0) | |
| streams[j] = d(rd); | |
| } | |
| it = (uint16_t)accumulate(streams.begin(), streams.end(), 0); | |
| cl = it & 0xff; | |
| ch = it >> 8; | |
| #if ENDIAN == LE | |
| cout << cl << ch; | |
| #else | |
| cout << ch << cl; | |
| #endif | |
| } | |
| /* | |
| cout << endl; | |
| for(uint16_t i : streams) | |
| cout << i << ", "; | |
| cout << endl; | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment