pub struct OfflineRenderer { /* private fields */ }Expand description
The engine’s synthesiser with no audio device behind it.
It runs exactly the code the real-time thread runs (the same sources,
filters, ducking, reverb and limiter), but you pull the samples out
yourself. Use it to bounce sounds to a WAV file with
crate::audio::wav::write_wav, to render audio for a captured video,
or to test sound design on a machine with no sound card.
use proof_engine::audio::{AudioEvent, OfflineRenderer};
use proof_engine::audio::math_source::MathAudioSource;
use proof_engine::prelude::Vec3;
let mut synth = OfflineRenderer::new(48_000);
synth.emit(AudioEvent::SpawnSource {
source: MathAudioSource::death_knell(Vec3::ZERO),
position: Vec3::ZERO,
});
let stereo = synth.render(0.5);
assert_eq!(stereo.len(), 2 * 24_000);
assert!(stereo.iter().any(|s| s.abs() > 0.01));Implementations§
Source§impl OfflineRenderer
impl OfflineRenderer
Sourcepub fn with_seed(sample_rate: u32, seed: u32) -> Self
pub fn with_seed(sample_rate: u32, seed: u32) -> Self
As new, with the seed of the noise generators, for
renders that must differ from each other.
Sourcepub fn emit(&mut self, event: AudioEvent)
pub fn emit(&mut self, event: AudioEvent)
Queue an event. It takes effect at the start of the next
render, as events do at the start of each buffer
on the real-time thread.
Sourcepub fn render(&mut self, secs: f32) -> Vec<f32>
pub fn render(&mut self, secs: f32) -> Vec<f32>
Render secs seconds as interleaved stereo (left, right, left, …),
each sample in [-1, 1].
Sourcepub fn render_frames(&mut self, frames: usize) -> Vec<f32>
pub fn render_frames(&mut self, frames: usize) -> Vec<f32>
Render exactly frames stereo frames, interleaved.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
The sample rate this renderer was made with.
Sourcepub fn active_sources(&self) -> usize
pub fn active_sources(&self) -> usize
Sources still sounding (effects that have not ended, plus music).
Auto Trait Implementations§
impl !Sync for OfflineRenderer
impl Freeze for OfflineRenderer
impl RefUnwindSafe for OfflineRenderer
impl Send for OfflineRenderer
impl Unpin for OfflineRenderer
impl UnsafeUnpin for OfflineRenderer
impl UnwindSafe for OfflineRenderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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