AUDIO
Source snapshot · 11 November 2026

API reference / ravet_gain

Crate ravet_gain 

Expand description

The first RAVET reference product: mono/stereo gain with sample-timed events.

This is portable processor code, not a plug-in or an audio-device backend. Gain uses a linear amplitude multiplier in 0..=4 (unity = 1); finite values outside that range are clamped. Audio samples themselves are not sanitized. Unknown parameter IDs and note events are ignored. Smoothing defaults to 5 ms, is shared between channels, and advances once per frame. Reset and reprepare snap to the latest requested gain. Transport does not affect gain. Portable bypass switches at the event sample without a crossfade. Gain smoothing continues while bypassed. Input/output peak and RMS measure each successful nonempty block; nonfinite samples are flagged and counted as silence in telemetry without sanitizing audio. The state module provides a versioned product record for control-thread persistence; the processor does not perform stream I/O.

use ravet::foundation::{AudioBuffer, AudioLayout, Event, EventData,
    ProcessBlock, ProcessConfig, ProcessStatus, Processor, Transport};
use ravet_gain::{GainProcessor, GAIN_ID};

let mut gain = GainProcessor::new(0.0)?; // immediate automation
gain.prepare(ProcessConfig::new(48_000.0, 4, 4, AudioLayout::MONO)?)?;
let mut samples = [1.0, -1.0, 0.5, -0.5];
let events = [Event {
    frame_offset: 2,
    data: EventData::ParameterValue { id: GAIN_ID, value: 0.5 },
}];
let mut channels = [&mut samples[..]];
let audio = AudioBuffer::in_place(&mut channels, 4)?;
let mut block = ProcessBlock::new(audio, &events, Transport::default());
assert_eq!(gain.process(&mut block), ProcessStatus::Continue);
assert_eq!(samples, [1.0, -1.0, 0.25, -0.25]);

Modules§

state
Legacy scalar state and complete portable gain/bypass state.

Structs§

GainMeterMailbox
Separate audio-to-control mailbox. Intermediate blocks may be overwritten. No retries, event queue, GUI scheduling, or peak retention across blocks.
GainMeters
One block’s input/output sample peak and RMS per channel.
GainMeters64
Native f64 levels from the last successful nonempty block.
GainProcessor
GainProcessor64
Mono/stereo f64 reference with the existing f32 gain/bypass parameter and smoother semantics. Audio copying/multiplication and meters remain native f64; the smoother’s per-frame gain is promoted exactly. State bytes/IDs match f32. Nonfinite audio propagates through DSP and counts as silence in telemetry. Prepared processing/reset has no framework heap, lock or I/O operations.

Constants§

BYPASS_ID
Permanent portable bypass ID. Values below 0.5 mean off; other finite values mean on.
GAIN_ID
Permanent ID; changing the display name must not change this identity.
MAXIMUM_GAIN

Statics§

GAIN_PROGRAMS
Permanent IDs 1..3, MIDI bank 0/numbers 0..2. Unity/Silence/Bypass contain complete gain/bypass values [1,0]/[0,0]/[1,1]. Programs have no DSP history, selected identity, host notification, smoothing or file policy of their own.

Functions§

factory_program_bank
Validate/borrow the fixed complete catalogue for preparation. Consumers can copy a state and restore either native-precision processor under its existing lifecycle rules. No current program identity is inferred from custom edits.
parameter_schema
Shared gain/bypass product metadata, also exposed by the CLAP prototype.