Skip to main content

AudioRenderer

Struct AudioRenderer 

Source
pub struct AudioRenderer { /* private fields */ }
Expand description

Mixes a project’s audio tracks into one project-rate block.

Implementations§

Source§

impl AudioRenderer

Source

pub fn new( snapshot: &EngineProject, channels: usize, max_block: usize, ) -> Result<Self, EngineError>

Builds every track and master processor for a project snapshot. Clip processors are built when the clip is first mixed.

§Errors

Returns EngineError::InvalidAudioConfiguration for an unsupported channel count, a zero sample rate, or an oversized block.

Source

pub const fn sample_rate(&self) -> u32

Returns the project sample rate every block uses.

Source

pub const fn channels(&self) -> usize

Returns the channel count of every mixed block.

Source

pub fn track_ids(&self) -> Vec<&TrackId>

Returns the audio tracks this renderer mixes, in bus order.

Source

pub const fn max_block(&self) -> usize

Returns the largest block this renderer accepts.

Source

pub fn channel(&self, index: usize) -> &[f32]

Returns one mixed output channel from the most recent render.

Source

pub fn required_lookahead_samples(&self) -> u32

How far ahead of a block, in samples, the renderer reads its sources.

The renderer reads each path’s input early by its latency to the output (for example a compressor’s lookahead_ms), so the output lines up with the timeline. Use Self::audio_needs for source supply, since a cold seek also needs settling history.

Source

pub fn audio_needs( &self, snapshot: &EngineProject, start_sample: i64, frames: usize, ) -> Result<Vec<AudioNeed>, EngineError>

The source intervals rendering frames samples from start_sample reads, for a host to decode first.

These are exactly what Self::render would read, including any settling replay, so a host that holds them needs no margin. Overlapping or touching intervals of one source are merged; disjoint ones stay separate.

§Errors

Returns EngineError::InvalidAudioConfiguration for a negative start, an empty or oversized block, or a span that does not fit in ticks, and an evaluation error when the snapshot cannot be evaluated over a block’s span.

Source

pub const fn required_history_samples(&self) -> i64

Settling history replayed on discontinuities, in samples, excluding latency. At most MAX_SETTLING_SECONDS.

Source

pub fn set_continuity(&mut self, continuity: AudioContinuity)

Sets the AudioContinuity policy (default AudioContinuity::Exact). Changing it resets the renderer.

Source

pub const fn continuity(&self) -> AudioContinuity

The policy Self::set_continuity last chose.

Source

pub fn reset(&mut self)

Clears every processor history without changing authored parameters.

Self::render resets on its own at discontinuities. Call this only to start fresh exactly where the last block ended, such as an export beginning where preview stopped.

Source

pub fn render( &mut self, snapshot: &EngineProject, start_sample: i64, frames: usize, provider: &dyn AudioBlockProvider, transport: TransportState, ) -> Result<AudioRenderStatus, EngineError>

Mixes frames samples starting at an absolute project-rate sample index.

A block that does not continue the previous one (see AudioContinuity) first resets every processor and replays the settling history Self::audio_needs asks for, so its output matches a fresh renderer’s regardless of block size.

Recursive effects settle over a finite horizon (32 exponential time constants plus filter/feedback margins, capped at MAX_SETTLING_SECONDS), not bit-exactly. Each stage joins the replay only at its own horizon, so a long reverb on one track replays only that track.

§Errors

Returns EngineError::InvalidAudioConfiguration for a negative start, an oversized block, or a span that does not fit in ticks, and an evaluation error when the snapshot cannot be evaluated over the block’s span.

Source

pub fn set_normalization_gain_db( &mut self, gain_db: f64, ) -> Result<(), EngineError>

Sets the loudness normalization gain in dB, applied between the master gain and the limiter. Zero removes it, as does Self::set_loudness_metering.

§Errors

Returns EngineError::InvalidNormalizationGain for a non-finite gain or one whose linear factor is not a normal f32 (beyond about 760 dB either way).

Source

pub const fn set_hold_incomplete_blocks(&mut self, hold: bool)

Whether a block missing a source is held: output as silence with nothing advanced, so rendering it again after the host supplies the source matches an uninterrupted render. Off by default (live playback); exports turn it on.

Source

pub fn set_loudness_metering( &mut self, enabled: bool, ) -> Result<(), EngineError>

Starts (or restarts from empty) measuring the loudness of what reaches the limiter; false stops. Only complete requested blocks are measured, never replayed history.

Starting removes the normalization gain (Self::set_normalization_gain_db) so the authored mix is measured; a gain set afterwards is included.

§Errors

Returns EngineError::InvalidAudioConfiguration for an unsupported layout or rate.

Source

pub fn loudness_report(&self) -> Option<LoudnessReport>

What the meter has measured, if metering is on.

Source

pub fn limiter_threshold(&self) -> Option<f64>

The master limiter’s linear threshold, if any. Pass it to alpha2_audio::LoudnessNormalization::plan so the planned gain stops short of the limiter.

Source

pub fn set_output_loudness_metering( &mut self, enabled: bool, ) -> Result<(), EngineError>

Starts (or restarts from empty) measuring the loudness of the final output, after the limiter and normalization gain; false stops. Unlike Self::set_loudness_metering it leaves the gain unchanged.

§Errors

Returns EngineError::InvalidAudioConfiguration for an unsupported layout or rate.

Source

pub fn output_loudness_report(&self) -> Option<LoudnessReport>

What the output meter has measured, if output metering is on.

Source

pub fn block(&self, status: &AudioRenderStatus) -> AudioBlock

Copies the most recent render into an owned block for offline sinks.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,