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>
impl<S: Sample> OfflineRenderer<S>
Sourcepub fn new(graph: Graph<S>, writer: Box<dyn Writer<S>>) -> Self
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.
Sourcepub fn render(
&mut self,
duration: RenderDuration,
) -> Result<RenderStats, RenderError>
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.
Sourcepub fn sample_rate(&self) -> f64
pub fn sample_rate(&self) -> f64
Get the sample rate of the renderer.
Sourcepub fn num_channels(&self) -> usize
pub fn num_channels(&self) -> usize
Get the number of channels.
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Get the buffer size.
Sourcepub fn into_graph(self) -> Graph<S>
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.