Colowave (Color-Wave) is a high-performance audio generator written in Rust that synthesizes various "colors" of noise (White, Pink, Brownian, Blue, and Violet) using Fast Fourier Transforms (FFT).
The program mathematically constructs signals in the frequency domain with precise power spectral densities, performs an inverse FFT into the time domain, normalizes the signal to prevent clipping, and outputs a properly formatted 10-second standard 16-bit PCM .wav file.
- Multiple Noise Profiles: Generates 5 distinct spectral colors of noise.
- High-Quality Output: Hardcoded to CD-quality audio (Mono, 44,100 Hz, 16-bit PCM).
- DSP Precision: Uses complex frequency-domain generation via the
rustfftcrate for accurate spectral characteristics, avoiding traditional inaccurate time-domain filters. - Zero-cost Serialization: Uses the
zerocopycrate to safely and safely pack RIFF/WAVE header chunks.
The tool can generate the following colors based on their Power Spectral Density (PSD) characteristics:
-
White Noise (
white): Flat frequency spectrum. Equal power across all frequencies. -
Pink Noise (
pink): Power density decreases by 3 dB per octave ($1/\sqrt{f}$ ). Sounds more balanced to human ears. -
Brownian / Red Noise (
brownian): Power density decreases by 6 dB per octave ($1/f$ ). Deep, bass-heavy rumble. -
Blue Noise (
blue): Power density increases by 3 dB per octave ($\sqrt{f}$ ). Harsh, treble-heavy hiss. -
Violet Noise (
violet): Power density increases by 6 dB per octave ($f$ ). Extremely bright and sharp high-frequency sound.
(Note: In Pink and Brownian generation, the lowest frequencies (up to 20Hz) are aggressively filtered to prevent overwhelming DC/low-end energy from dominating the headroom.)
Ensure you have Rust and Cargo installed. Then build from the source directory:
# Clone the repository and cd into it
# Build the optimal release version
cargo build --releaseRun the compiled executable through Cargo, passing the desired noise color as an argument.
cargo run --release -- <color>Examples:
cargo run --release # Generates white noise (default)
cargo run --release -- pink # Generates pink noise
cargo run --release -- blue # Generates blue noiseRunning the above commands will generate a 10-second file named audio.wav in the root of the directory.
-
Spectrum Setup: Colowave allocates an array of
Complex<f64>bins representing the Nyquist range (up to 22.05 kHz). -
Spectral Shaping: Depending on the selected argument, amplitudes are distributed across frequency bins mathematically. For instance, Pink noise scales amplitude by
$1/\sqrt{k}$ , where$k$ is the frequency bin index. - Phase Randomness & Drift: Phases are randomized, combined with slight randomized phase drifts between blocks to maintain a continuous, non-repeating auditory texture.
- Hermitian Symmetry: The upper half of the FFT buffer is populated with the complex conjugates of the lower half, guaranteeing a purely real-valued time-domain signal.
-
Inverse FFT (iFFT): The frequency-domain buffer flows into
rustfft::FftPlanner's inverse processor to generate time-domain sample points. -
Peak Normalization: To prevent clipping (digital distortion) and ensure optimal volume, the time array is peak-normalized to an amplitude bounds peak of
30,000(just below the 16-bit signed maximum of32,767). -
WAV Serialization: Constructs standard
RIFFandWAVEheaders and streams the 16-bit little-endian samples securely.
The generated audio.wav is formatted uniformly:
- Format: Microsoft PCM format (0x0001)
- Channels: 1 (Mono)
- Sample Rate: 44,100 samples/sec
- Bit Depth: 16 bits per sample
- Length: 10 seconds