Skip to content
Ansh934Public

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Colowave

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.

Features

  • 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 rustfft crate for accurate spectral characteristics, avoiding traditional inaccurate time-domain filters.
  • Zero-cost Serialization: Uses the zerocopy crate to safely and safely pack RIFF/WAVE header chunks.

Supported Noise Colors

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.)

Installation & Build

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 --release

Usage

Run 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 noise

Running the above commands will generate a 10-second file named audio.wav in the root of the directory.

Technical Details: How it Works

  1. Spectrum Setup: Colowave allocates an array of Complex<f64> bins representing the Nyquist range (up to 22.05 kHz).
  2. 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.
  3. Phase Randomness & Drift: Phases are randomized, combined with slight randomized phase drifts between blocks to maintain a continuous, non-repeating auditory texture.
  4. 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.
  5. Inverse FFT (iFFT): The frequency-domain buffer flows into rustfft::FftPlanner's inverse processor to generate time-domain sample points.
  6. 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 of 32,767).
  7. WAV Serialization: Constructs standard RIFF and WAVE headers and streams the 16-bit little-endian samples securely.

Output Specifications

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

Library Dependencies

  • rand: Used to randomize wave phase logic over frequency frames.
  • rustfft: Handles the inverse Fast Fourier Transform computation.
  • zerocopy: Offers safe structural representations and zero-copy binary layout mechanisms for defining RIFF/WAV specification chunks.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages