Struct OfflineRenderer

Source
pub struct OfflineRenderer<S: Sample> { /* private fields */ }
Expand description

Offline renderer for DSP graphs.

Renders a Graph to a Writer at maximum CPU speed, bypassing real-time constraints. This is ideal for bouncing/exporting audio to files.

§Example

use bbx_dsp::graph::GraphBuilder;
use bbx_file::{OfflineRenderer, RenderDuration, writers::wav::WavFileWriter};

let graph = GraphBuilder::<f32>::new(44100.0, 512, 2)
    .oscillator(440.0, Waveform::Sine)
    .build();

let writer = WavFileWriter::new("output.wav", 44100.0, 2)?;
let mut renderer = OfflineRenderer::new(graph, Box::new(writer));
let stats = renderer.render(RenderDuration::Duration(30))?;
println!("Rendered {}s in {:.2}s ({:.1}x realtime)",
    stats.duration_seconds, stats.render_time_seconds, stats.speedup);

Implementations§

Source§

impl<S: Sample> OfflineRenderer<S>

Source

pub fn new(graph: Graph<S>, writer: Box<dyn Writer<S>>) -> Self

Create a new offline renderer.

The graph should already be built via GraphBuilder::build(). The writer’s sample rate and channel count should match the graph’s context.

§Arguments
  • graph - A prepared DSP graph (already built)
  • writer - A boxed writer implementation (e.g., WavFileWriter)
§Panics

Panics if the writer’s sample rate or channel count doesn’t match the graph.

Source

pub fn render( &mut self, duration: RenderDuration, ) -> Result<RenderStats, RenderError>

Render audio for the specified duration.

Processes the graph at maximum CPU speed and writes output to the writer. Automatically calls finalize() on the writer when complete.

§Arguments
  • duration - How long to render (in seconds or samples)
§Returns

Statistics about the render including speedup factor.

Source

pub fn sample_rate(&self) -> f64

Get the sample rate of the renderer.

Source

pub fn num_channels(&self) -> usize

Get the number of channels.

Source

pub fn buffer_size(&self) -> usize

Get the buffer size.

Source

pub fn into_graph(self) -> Graph<S>

Consume the renderer and return the graph.

Useful if you need to reuse the graph after rendering. Note: The writer is consumed and cannot be retrieved.

Auto Trait Implementations§

§

impl<S> Freeze for OfflineRenderer<S>

§

impl<S> !RefUnwindSafe for OfflineRenderer<S>

§

impl<S> Send for OfflineRenderer<S>

§

impl<S> Sync for OfflineRenderer<S>

§

impl<S> Unpin for OfflineRenderer<S>
where S: Unpin,

§

impl<S> !UnwindSafe for OfflineRenderer<S>

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.