pub trait Source:
Send
+ Sync
+ 'static {
// Required methods
fn sample_rate(&self) -> u32;
fn channel_count(&self) -> usize;
fn is_exhausted(&self) -> bool;
fn weight(&self) -> usize;
fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize;
// Provided method
fn into_box(self) -> Box<dyn Source>
where Self: Sized { ... }
}Expand description
Audio signal producer that generates new or processes existing audio samples.
Sources are the fundamental building blocks of audio playback in phonic. They produce audio
samples in f32 format and can represent various kinds of audio:
- Audio file playback via
FileSource - Synthesized tones via
SynthSource - Note-driven instruments via
Generator(which is a specializedSource) - DSP operations like mixing, panning, resampling, etc.
The output buffer is a raw interleaved buffer, which is written by the source in the specified
channel_count and sample_rate specs. Specs may not change during runtime, so downstream
sources don’t have to adapt to new specs.
Important: write is called in real-time audio threads, so it must not block!
Required Methods§
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
The source’s output sample rate.
Sourcefn channel_count(&self) -> usize
fn channel_count(&self) -> usize
The source’s output channel count.
Sourcefn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
Returns whether the source finished playback. Exhausted sources should only return 0
on write and may be removed from a source render graph.
Sourcefn weight(&self) -> usize
fn weight(&self) -> usize
Return a rough estimate of the processing costs for this source in range ~1..10,
where 1 means pretty lightweight and 10 very CPU intensive. This is used in parallel
processing to distribute work loads evenly before or without actual CPU measurements.
Sourcefn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
Write at most output.len() samples into the interleaved output
The given SourceTime parameter specifies which absolute time this buffer in the
final output stream refers to. It can be used to schedule and apply real-time events.
Returns the number of written samples (not frames).
Provided Methods§
Trait Implementations§
Source§impl Source for Box<dyn Source>
Allow adding/using boxed dyn Sources as Source impls.
impl Source for Box<dyn Source>
Allow adding/using boxed dyn Sources as Source impls.
Source§fn into_box(self) -> Box<dyn Source>
fn into_box(self) -> Box<dyn Source>
dyn Source. Read moreSource§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Source§fn channel_count(&self) -> usize
fn channel_count(&self) -> usize
Source§fn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
write and may be removed from a source render graph.Source§fn weight(&self) -> usize
fn weight(&self) -> usize
~1..10,
where 1 means pretty lightweight and 10 very CPU intensive. This is used in parallel
processing to distribute work loads evenly before or without actual CPU measurements.Source§fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
output.len() samples into the interleaved output
The given SourceTime parameter specifies which absolute time this buffer in the
final output stream refers to. It can be used to schedule and apply real-time events.
Returns the number of written samples (not frames).Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Implementors§
impl Source for EmptyGenerator
impl Source for EmptySource
impl Source for FunDspGenerator
fundsp only.impl Source for FunDspSynthSource
fundsp only.