Signal Generation

The generation module provides functions to generate various audio waveforms and noise types with precise control over frequency, amplitude, and duration. All functions return AudioSamples objects with embedded metadata.

Basic Waveforms

audio_samples.generation.sine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a sine wave audio signal.

Parameters:
  • frequency – Frequency of the sine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated sine wave audio data

Return type:

AudioSamples

audio_samples.generation.cosine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a cosine wave audio signal.

Parameters:
  • frequency – Frequency of the cosine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated cosine wave audio data

Return type:

AudioSamples

audio_samples.generation.sawtooth_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a sawtooth wave audio signal.

Parameters:
  • frequency – Frequency of the sawtooth wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated sawtooth wave audio data

Return type:

AudioSamples

audio_samples.generation.square_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a square wave audio signal.

Parameters:
  • frequency – Frequency of the square wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated square wave audio data

Return type:

AudioSamples

audio_samples.generation.triangle_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a triangle wave audio signal.

Parameters:
  • frequency – Frequency of the triangle wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated triangle wave audio data

Return type:

AudioSamples

Advanced Signals

audio_samples.generation.chirp(f0, f1, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a frequency chirp (sweep) audio signal.

Parameters:
  • f0 – Starting frequency in Hz

  • f1 – Ending frequency in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated chirp audio data

Return type:

AudioSamples

audio_samples.generation.impulse(duration_secs, sample_rate=44100, amplitude=1.0, position=0.5, dtype=None)

Generate an impulse (delta function) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the impulse (default: 1.0)

  • position – Position of the impulse as fraction of duration (default: 0.5)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated impulse audio data

Return type:

AudioSamples

audio_samples.generation.silence(duration_secs, sample_rate=44100, dtype=None)

Generate silence (zero amplitude) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated silence audio data

Return type:

AudioSamples

Band-limited Waveforms

audio_samples.generation.sawtooth_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) sawtooth wave via additive synthesis.

Sums only the harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the sawtooth wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal sawtooth wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited sawtooth wave audio data

Return type:

AudioSamples

audio_samples.generation.square_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) square wave via additive synthesis.

Unlike a hard-clipped square wave, this sums only the odd harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the square wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal square wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited square wave audio data

Return type:

AudioSamples

audio_samples.generation.triangle_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) triangle wave via additive synthesis.

Sums only the odd harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the triangle wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal triangle wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited triangle wave audio data

Return type:

AudioSamples

Modulated and Compound Signals

audio_samples.generation.am_signal(carrier_freq, modulator_freq, modulation_depth, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate an amplitude-modulated (AM) signal.

A carrier signal modulated by a low-frequency envelope.

Parameters:
  • carrier_freq – Frequency of the carrier signal in Hz

  • modulator_freq – Frequency of the modulating envelope in Hz

  • modulation_depth – Depth of modulation (0.0 = none, 1.0 = full)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Overall amplitude (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated AM signal audio data

Return type:

AudioSamples

audio_samples.generation.fm_signal(carrier_freq, modulator_freq, modulation_index, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a frequency-modulated (FM) signal.

A sinusoidal carrier whose instantaneous phase is modulated by a sinusoidal modulator. With modulation_index == 0 this reduces to a pure sine at the carrier frequency.

Parameters:
  • carrier_freq – Carrier frequency in Hz

  • modulator_freq – Modulator frequency in Hz

  • modulation_index – Modulation index (peak phase deviation in radians)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated FM signal audio data

Return type:

AudioSamples

audio_samples.generation.compound_tone(components, duration_secs, sample_rate=44100, dtype=None)

Generate a compound tone from multiple frequency components.

Useful for creating signals with harmonics or multiple simultaneous tones. Each component is given as a (frequency_hz, amplitude) tuple.

Parameters:
  • components – List of (frequency_hz, amplitude) tuples. Must be non-empty.

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated compound tone audio data

Return type:

AudioSamples

Raises:

ValueError – If components is empty or duration_secs is not positive.

audio_samples.generation.exponential_chirp(start_freq, end_freq, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate an exponential (logarithmic) frequency chirp (sweep) audio signal.

The instantaneous frequency sweeps geometrically from start_freq to end_freq. Both frequencies must be strictly positive.

Parameters:
  • start_freq – Starting frequency in Hz (must be > 0)

  • end_freq – Ending frequency in Hz (must be > 0)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated exponential chirp audio data

Return type:

AudioSamples

audio_samples.generation.exponential_bursts(burst_rate, decay_rate, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a signal with periodic exponential-decay bursts.

Creates percussive-like transients useful for testing onset detection.

Parameters:
  • burst_rate – Number of bursts per second

  • decay_rate – Exponential decay rate (higher = faster decay)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of bursts (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated burst signal audio data

Return type:

AudioSamples

Stereo Signals

audio_samples.generation.stereo_chirp(start_freq, end_freq, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a stereo chirp signal (frequency sweep on both channels).

Parameters:
  • start_freq – Starting frequency in Hz

  • end_freq – Ending frequency in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the chirp (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated stereo chirp audio data

Return type:

AudioSamples

audio_samples.generation.stereo_silence(duration_secs, sample_rate=44100, dtype=None)

Generate stereo silence.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Stereo silence audio data

Return type:

AudioSamples

audio_samples.generation.stereo_sine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a stereo sine wave audio signal (same frequency on both channels).

Parameters:
  • frequency – Frequency of the sine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated stereo sine wave audio data

Return type:

AudioSamples

Noise Generators

audio_samples.generation.white_noise(duration_secs, sample_rate=44100, amplitude=1.0, dtype=None, seed=None)

Generate white noise audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

  • seed – Optional seed for reproducible noise generation

Returns:

Generated white noise audio data

Return type:

AudioSamples

audio_samples.generation.pink_noise(duration_secs, sample_rate=44100, amplitude=1.0, dtype=None, seed=None)

Generate pink noise audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated pink noise audio data

Return type:

AudioSamples

audio_samples.generation.brown_noise(duration_secs, sample_rate=44100, step=0.01, amplitude=1.0, dtype=None, seed=None)

Generate brown noise (Brownian/red noise) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • step – Step size for the random walk (default: 0.01)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated brown noise audio data

Return type:

AudioSamples

Example Clips

audio_samples.generation.example_clip(name, duration_secs=8.0, sample_rate=44100, dtype=None)

Render a named example clip of realistic audio.

The clip is synthesised on each call: nothing is stored or downloaded. The same arguments give the same samples on any platform, and a shorter clip is a prefix of a longer one.

Name

Contents

"chords"

C, G, Am, F in equal temperament (A4 = 440 Hz), one chord per four beats at EXAMPLE_TEMPO_BPM, soft attacks

"drum_loop"

Kick on beats 1 and 3, snare on 2 and 4, hi-hat on every eighth note at EXAMPLE_TEMPO_BPM, first kick at time zero

"chords_and_drums"

0.5 * chords + 0.5 * drum_loop

"speech"

Voiced speech-like signal with formants, following example_speech_f0; a 2.4 s phrase every 3 s, pauses between

"noisy_recording"

speech with low-passed noise and 50 Hz mains hum, at EXAMPLE_NOISY_SNR_DB over the voiced parts

Parameters:
  • name – The clip, one of the names above (see example_clip_names)

  • duration_secs – Duration in seconds (default: 8.0); the pattern repeats for as long as requested

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Mono audio of the given sample type at the given sample rate

Return type:

AudioSamples

Raises:

ValueError – Unknown name, or a duration that gives no samples

audio_samples.generation.example_clip_names()

The names example_clip accepts.

Returns:

The clip names

Return type:

list[str]

audio_samples.generation.example_speech_f0(times)

The F0 of the "speech" and "noisy_recording" clips at the given times.

Parameters:

times – Times in seconds from the start of the clip

Returns:

F0 in Hz as 1-D float64, NaN during pauses

Return type:

numpy.ndarray

example_clip gives realistic audio for documentation and experiments without a file or a download. The clip is computed when you ask for it, with the sample rate, duration and sample type you choose; the defaults are 44100 Hz, 8 s and float32, and the returned audio carries them.

import numpy as np
import audio_samples as aus

drums = aus.generation.example_clip("drum_loop", 8.0, 22050, dtype=np.float32)
tempo, beats = drums.beat_track(units="time")
assert abs(float(np.ravel(tempo)[0]) - aus.generation.EXAMPLE_TEMPO_BPM) < 3.0

Each clip has known contents, so analysis results can be checked against them:

Name

Contents

"chords"

C, G, Am, F in equal temperament (A4 = 440 Hz), one chord per four beats at EXAMPLE_TEMPO_BPM (110), with soft attacks and harmonic partials only

"drum_loop"

Kick on beats 1 and 3, snare on beats 2 and 4, hi-hat on every eighth note at EXAMPLE_TEMPO_BPM, with the first kick at time zero

"chords_and_drums"

Exactly 0.5 * chords + 0.5 * drum_loop before conversion to the sample type

"speech"

A voiced source following example_speech_f0(times) through five formant resonators: a 2.4 s phrase starting every 3 s. The vowels last 0.6 s each, /a e i o/ in the first phrase and /u a i e/ in the second, with first three formants /a/ (730, 1090, 2440), /e/ (530, 1840, 2480), /i/ (270, 2290, 3010), /o/ (570, 840, 2410), /u/ (300, 870, 2240) Hz

"noisy_recording"

"speech" plus low-passed noise and 50 Hz mains hum with harmonics, at EXAMPLE_NOISY_SNR_DB (15 dB) over the voiced parts

A shorter clip is a prefix of a longer one. Components above 95 % of the Nyquist frequency are omitted, and the peak stays below full scale, so integer sample types do not clip.

Reproducibility. Rendering uses only IEEE 754 addition, subtraction, multiplication, division, square root and floor, plus a hand-written random number generator, so it does not depend on a platform’s maths library. The same arguments give the same bytes on any platform with IEEE 754 float64 arithmetic, which excludes x87 builds such as i586. The test suites check digests of the 16-bit output, which match on x86-64 with glibc and with musl, in debug and release builds and with -C target-cpu=native, and on aarch64.

Examples

Basic Waveform Generation

Generate a 440 Hz sine wave for 1 second:

import audio_samples as aus

# Generate a 440 Hz sine wave
sine = aus.generation.sine_wave(440.0, 1.0, 44100)

# Properties are embedded automatically
print(f"Sample rate: {sine.sample_rate()} Hz")
print(f"Duration: {sine.duration_seconds():.2f} seconds")
print(f"Samples: {sine.samples_per_channel()}")

Multi-tone Generation

Create complex signals by mixing waveforms:

# Generate harmonic series
fundamental = aus.generation.sine_wave(220.0, 1.0, 44100, 0.8)
second_harmonic = aus.generation.sine_wave(440.0, 1.0, 44100, 0.4)
third_harmonic = aus.generation.sine_wave(660.0, 1.0, 44100, 0.2)

# Mix harmonics
complex_tone = fundamental + second_harmonic + third_harmonic

# Normalize to prevent clipping
complex_tone.normalize(-1.0, 1.0, 'peak')

Noise Generation

Generate different types of noise for testing and synthesis:

# White noise (equal energy per frequency)
white = aus.generation.white_noise(2.0, 44100, 0.3)

# Pink noise (1/f power spectrum)
pink = aus.generation.pink_noise(2.0, 44100, 0.3)

# Brown noise (1/f² power spectrum)
brown = aus.generation.brown_noise(2.0, 44100, 0.01, 0.3)

Frequency Sweeps

Create frequency sweeps for testing and analysis:

# Linear chirp from 100 Hz to 2000 Hz
sweep = aus.generation.chirp(100.0, 2000.0, 5.0, 44100, 0.5)

# Can be used for impulse response measurement
print(f"Sweep range: 100 Hz to 2000 Hz over {sweep.duration_seconds():.1f} seconds")

Signal generators (tones, noise, chirps, band-limited, modulated and compound waveforms) and the example clips.

audio_samples.utils.generation.am_signal(carrier_freq, modulator_freq, modulation_depth, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate an amplitude-modulated (AM) signal.

A carrier signal modulated by a low-frequency envelope.

Parameters:
  • carrier_freq – Frequency of the carrier signal in Hz

  • modulator_freq – Frequency of the modulating envelope in Hz

  • modulation_depth – Depth of modulation (0.0 = none, 1.0 = full)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Overall amplitude (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated AM signal audio data

Return type:

AudioSamples

audio_samples.utils.generation.brown_noise(duration_secs, sample_rate=44100, step=0.01, amplitude=1.0, dtype=None, seed=None)

Generate brown noise (Brownian/red noise) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • step – Step size for the random walk (default: 0.01)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated brown noise audio data

Return type:

AudioSamples

audio_samples.utils.generation.chirp(f0, f1, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a frequency chirp (sweep) audio signal.

Parameters:
  • f0 – Starting frequency in Hz

  • f1 – Ending frequency in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated chirp audio data

Return type:

AudioSamples

audio_samples.utils.generation.compound_tone(components, duration_secs, sample_rate=44100, dtype=None)

Generate a compound tone from multiple frequency components.

Useful for creating signals with harmonics or multiple simultaneous tones. Each component is given as a (frequency_hz, amplitude) tuple.

Parameters:
  • components – List of (frequency_hz, amplitude) tuples. Must be non-empty.

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated compound tone audio data

Return type:

AudioSamples

Raises:

ValueError – If components is empty or duration_secs is not positive.

audio_samples.utils.generation.cosine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a cosine wave audio signal.

Parameters:
  • frequency – Frequency of the cosine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated cosine wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.example_clip(name, duration_secs=8.0, sample_rate=44100, dtype=None)

Render a named example clip of realistic audio.

The clip is synthesised on each call: nothing is stored or downloaded. The same arguments give the same samples on any platform, and a shorter clip is a prefix of a longer one.

Name

Contents

"chords"

C, G, Am, F in equal temperament (A4 = 440 Hz), one chord per four beats at EXAMPLE_TEMPO_BPM, soft attacks

"drum_loop"

Kick on beats 1 and 3, snare on 2 and 4, hi-hat on every eighth note at EXAMPLE_TEMPO_BPM, first kick at time zero

"chords_and_drums"

0.5 * chords + 0.5 * drum_loop

"speech"

Voiced speech-like signal with formants, following example_speech_f0; a 2.4 s phrase every 3 s, pauses between

"noisy_recording"

speech with low-passed noise and 50 Hz mains hum, at EXAMPLE_NOISY_SNR_DB over the voiced parts

Parameters:
  • name – The clip, one of the names above (see example_clip_names)

  • duration_secs – Duration in seconds (default: 8.0); the pattern repeats for as long as requested

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Mono audio of the given sample type at the given sample rate

Return type:

AudioSamples

Raises:

ValueError – Unknown name, or a duration that gives no samples

audio_samples.utils.generation.example_clip_info(name)

What an example clip contains.

Parameters:

name – The clip, one of example_clip_names()

Returns:

One sentence on the clip’s known contents

Return type:

str

Raises:

ValueError – Unknown name

audio_samples.utils.generation.example_clip_names()

The names example_clip accepts.

Returns:

The clip names

Return type:

list[str]

audio_samples.utils.generation.example_speech_f0(times)

The F0 of the "speech" and "noisy_recording" clips at the given times.

Parameters:

times – Times in seconds from the start of the clip

Returns:

F0 in Hz as 1-D float64, NaN during pauses

Return type:

numpy.ndarray

audio_samples.utils.generation.exponential_bursts(burst_rate, decay_rate, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a signal with periodic exponential-decay bursts.

Creates percussive-like transients useful for testing onset detection.

Parameters:
  • burst_rate – Number of bursts per second

  • decay_rate – Exponential decay rate (higher = faster decay)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of bursts (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated burst signal audio data

Return type:

AudioSamples

audio_samples.utils.generation.exponential_chirp(start_freq, end_freq, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate an exponential (logarithmic) frequency chirp (sweep) audio signal.

The instantaneous frequency sweeps geometrically from start_freq to end_freq. Both frequencies must be strictly positive.

Parameters:
  • start_freq – Starting frequency in Hz (must be > 0)

  • end_freq – Ending frequency in Hz (must be > 0)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated exponential chirp audio data

Return type:

AudioSamples

audio_samples.utils.generation.fm_signal(carrier_freq, modulator_freq, modulation_index, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a frequency-modulated (FM) signal.

A sinusoidal carrier whose instantaneous phase is modulated by a sinusoidal modulator. With modulation_index == 0 this reduces to a pure sine at the carrier frequency.

Parameters:
  • carrier_freq – Carrier frequency in Hz

  • modulator_freq – Modulator frequency in Hz

  • modulation_index – Modulation index (peak phase deviation in radians)

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated FM signal audio data

Return type:

AudioSamples

audio_samples.utils.generation.impulse(duration_secs, sample_rate=44100, amplitude=1.0, position=0.5, dtype=None)

Generate an impulse (delta function) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the impulse (default: 1.0)

  • position – Position of the impulse as fraction of duration (default: 0.5)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated impulse audio data

Return type:

AudioSamples

audio_samples.utils.generation.pink_noise(duration_secs, sample_rate=44100, amplitude=1.0, dtype=None, seed=None)

Generate pink noise audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated pink noise audio data

Return type:

AudioSamples

audio_samples.utils.generation.sawtooth_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a sawtooth wave audio signal.

Parameters:
  • frequency – Frequency of the sawtooth wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated sawtooth wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.sawtooth_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) sawtooth wave via additive synthesis.

Sums only the harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the sawtooth wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal sawtooth wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited sawtooth wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.silence(duration_secs, sample_rate=44100, dtype=None)

Generate silence (zero amplitude) audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated silence audio data

Return type:

AudioSamples

audio_samples.utils.generation.sine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a sine wave audio signal.

Parameters:
  • frequency – Frequency of the sine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated sine wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.square_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a square wave audio signal.

Parameters:
  • frequency – Frequency of the square wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated square wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.square_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) square wave via additive synthesis.

Unlike a hard-clipped square wave, this sums only the odd harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the square wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal square wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited square wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.stereo_chirp(start_freq, end_freq, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a stereo chirp signal (frequency sweep on both channels).

Parameters:
  • start_freq – Starting frequency in Hz

  • end_freq – Ending frequency in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the chirp (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated stereo chirp audio data

Return type:

AudioSamples

audio_samples.utils.generation.stereo_silence(duration_secs, sample_rate=44100, dtype=None)

Generate stereo silence.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Stereo silence audio data

Return type:

AudioSamples

audio_samples.utils.generation.stereo_sine_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a stereo sine wave audio signal (same frequency on both channels).

Parameters:
  • frequency – Frequency of the sine wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated stereo sine wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.triangle_wave(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a triangle wave audio signal.

Parameters:
  • frequency – Frequency of the triangle wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated triangle wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.triangle_wave_bandlimited(frequency, duration_secs, sample_rate=44100, amplitude=1.0, dtype=None)

Generate a band-limited (alias-free) triangle wave via additive synthesis.

Sums only the odd harmonics that lie strictly below the Nyquist frequency, producing an exactly band-limited signal with no aliasing.

Parameters:
  • frequency – Fundamental frequency of the triangle wave in Hz

  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the underlying ideal triangle wave (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

Returns:

Generated band-limited triangle wave audio data

Return type:

AudioSamples

audio_samples.utils.generation.white_noise(duration_secs, sample_rate=44100, amplitude=1.0, dtype=None, seed=None)

Generate white noise audio signal.

Parameters:
  • duration_secs – Duration of the signal in seconds

  • sample_rate – Sample rate in samples per second (default: 44100)

  • amplitude – Peak amplitude of the noise (default: 1.0)

  • dtype – Output sample type as a NumPy dtype, scalar type (np.float64) or string ("float64"). Default: float32

  • seed – Optional seed for reproducible noise generation

Returns:

Generated white noise audio data

Return type:

AudioSamples