assert_audio_unit_snapshot

Macro assert_audio_unit_snapshot 

Source
macro_rules! assert_audio_unit_snapshot {
    ($unit:expr) => { ... };
    ($name:literal, $unit:expr) => { ... };
    ($name:expr, $unit:expr, $input:expr) => { ... };
    ($name:expr, $unit:expr, $input:expr, $config:expr) => { ... };
    ($unit:expr, $config:expr) => { ... };
}
Expand description

Macro for audio unit snapshot testing

By default (arms without an explicit SnapshotConfig) this macro produces TWO snapshots for the given audio unit:

  1. An SVG chart (default SvgChartConfig)
  2. A 16-bit WAV file (WavOutput::Wav16)

Arms that accept a custom SnapshotConfig produce exactly ONE snapshot using the output_mode specified in that config.

The unit is internally cloned so it can be processed twice (SVG + WAV) without triggering a move error. If your audio unit type does not implement Clone, use the config form and select a single output mode.

ยงExamples

use fundsp::prelude::*;
use insta_fun::prelude::*;

// With a custom name (generates name.svg & name.wav)
let unit = saw_hz(220.0);
assert_audio_unit_snapshot!("doc_sawtooth", unit);
use fundsp::prelude::*;
use insta_fun::prelude::*;

// With input source (generates doc_lowpass.svg & doc_lowpass.wav)
assert_audio_unit_snapshot!("doc_lowpass", lowpass_hz(1000.0, 1.0), InputSource::impulse());
use fundsp::prelude::*;
use insta_fun::prelude::*;

// With input source and custom config (generates only one file per config.output_mode)
let chart = SvgChartConfigBuilder::default().chart_title("Highpass").build().unwrap();
let config = SnapshotConfigBuilder::default()
    .num_samples(512)
    .output_mode(chart)
    .build()
    .unwrap();
assert_audio_unit_snapshot!(
    "doc_highpass",
    highpass_hz(2000.0, 0.7),
    InputSource::sine(100.0, 44100.0),
    config
);
use fundsp::prelude::*;
use insta_fun::prelude::*;

// With unit and config (single snapshot)
let config = SnapshotConfigBuilder::default()
    .output_mode(WavOutput::Wav32)
    .num_samples(512)
    .build()
    .unwrap();
assert_audio_unit_snapshot!(
    "doc_wav32",
    sine_hz::<f32>(440.0),
    InputSource::None,
    config
);

Invariants / Notes:

  • Unit expression is evaluated once per macro invocation; cloned only for dual-snapshot arms.
  • Name expression (in widened arms) is evaluated exactly once and converted with Into.
  • Input expression in the (name, unit, input) arm is evaluated twice (once per SVG, once per WAV).
  • Two-arg (name, unit) arm keeps $name:literal to avoid ambiguity with the (unit, config) arm. To use a dynamic (non-literal) name, supply an input or a config (3 or 4 argument forms).