Skip to main content

Module generation

Module generation 

Source
Expand description

Audio signal generation utilities.

Functions for synthesising deterministic and stochastic audio signals: waveforms (sine, cosine, square, sawtooth, triangle), frequency sweeps (chirp), noise (white, pink, brown), silence, impulses, compound multi-harmonic tones, and amplitude-modulated signals.

Multi-channel convenience wrappers (stereo_sine_wave, stereo_chirp, etc.) are provided when the channels feature is enabled. A MonoSampleBuilder for constructing concatenated sequences through method chaining is available when editing is enabled. Generated signals are the backbone of audio unit tests, benchmarks, and DSP prototyping. By centralising generators in this module, dependent code can produce reproducible test data without reaching for external audio files. All generators accept a NonZeroU32 sample rate. Use the sample_rate! macro to construct one from an integer literal:

use audio_samples::utils::generation::sine_wave;
use audio_samples::sample_rate;
use std::time::Duration;

let tone = sine_wave::<f32>(440.0, Duration::from_secs(1), sample_rate!(44100), 1.0);
assert_eq!(tone.samples_per_channel().get(), 44100);

Some helpers are feature-gated:

  • MonoSampleBuilder requires feature = "editing".
  • Noise generators (white_noise, pink_noise, brown_noise, exponential_bursts) require feature = "random-generation".
  • stereo_* and multichannel_compound_tone require feature = "channels".

Structs§

MonoSampleBuilder
Builder for creating mono audio samples through method chaining.
ToneComponent
A component of a compound tone, specifying frequency and relative amplitude.

Functions§

am_signal
Generates an amplitude-modulated (AM) signal.
brown_noise
Generates brown noise (Brownian / red noise) with the specified parameters.
chirp
Generates a linear chirp (frequency sweep) signal.
compound_tone
Generates a compound tone from multiple frequency components.
cosine_wave
Generates a cosine wave with the specified parameters.
exponential_bursts
Generates a signal with periodic exponential decay bursts.
impulse
Generates a unit impulse (Dirac delta approximation) signal.
multichannel_compound_tone
Generates a multi-channel compound tone.
pink_noise
Generates pink noise (1/f noise) with the specified parameters.
sawtooth_wave
Generates a sawtooth wave with the specified parameters.
silence
Generates a silence buffer (all-zero samples) with the specified duration.
sine_wave
Generates a sine wave with the specified parameters.
square_wave
Generates a square wave with the specified parameters.
stereo_chirp
Generates a stereo chirp signal by duplicating mono to both channels.
stereo_silence
Generates stereo silence.
stereo_sine_wave
Generates a stereo sine wave by duplicating mono to both channels.
triangle_wave
Generates a triangle wave with the specified parameters.
white_noise
Generates white noise with the specified parameters.