Skip to main content

Source

Trait Source 

Source
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 specialized Source)
  • 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§

Source

fn sample_rate(&self) -> u32

The source’s output sample rate.

Source

fn channel_count(&self) -> usize

The source’s output channel count.

Source

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.

Source

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.

Source

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§

Source

fn into_box(self) -> Box<dyn Source>
where Self: Sized,

Convert the Source impl into a boxed dyn Source.

Avoids double boxing when a generator impl already is a Box<dyn Source>.

Trait Implementations§

Source§

impl Source for Box<dyn Source>

Allow adding/using boxed dyn Sources as Source impls.

Source§

fn into_box(self) -> Box<dyn Source>

Convert the Source impl into a boxed dyn Source. Read more
Source§

fn sample_rate(&self) -> u32

The source’s output sample rate.
Source§

fn channel_count(&self) -> usize

The source’s output channel count.
Source§

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.
Source§

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.
Source§

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).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Source for Box<dyn Generator>

Allow adding/using boxed dyn Generators as Source impls.

Source§

fn sample_rate(&self) -> u32

Source§

fn channel_count(&self) -> usize

Source§

fn is_exhausted(&self) -> bool

Source§

fn weight(&self) -> usize

Source§

fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize

Source§

impl Source for Box<dyn Source>

Allow adding/using boxed dyn Sources as Source impls.

Source§

fn into_box(self) -> Box<dyn Source>

Source§

fn sample_rate(&self) -> u32

Source§

fn channel_count(&self) -> usize

Source§

fn is_exhausted(&self) -> bool

Source§

fn weight(&self) -> usize

Source§

fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize

Implementors§

Source§

impl Source for EmptyGenerator

Source§

impl Source for EmptySource

Source§

impl Source for FunDspGenerator

Available on crate feature fundsp only.
Source§

impl Source for FunDspSynthSource

Available on crate feature fundsp only.
Source§

impl Source for PreloadedFileSource

Source§

impl Source for Sampler

Source§

impl Source for StreamedFileSource

Source§

impl<Generator> Source for SynthSourceImpl<Generator>
where Generator: SynthSourceGenerator + Send + Sync + 'static,