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:
MonoSampleBuilderrequiresfeature = "editing".- Noise generators (
white_noise,pink_noise,brown_noise,exponential_bursts) requirefeature = "random-generation". stereo_*andmultichannel_compound_tonerequirefeature = "channels".
Structs§
- Mono
Sample Builder - Builder for creating mono audio samples through method chaining.
- Tone
Component - 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.