Skip to main content

ClockSource

Trait ClockSource 

Source
pub trait ClockSource:
    Send
    + Sync
    + Debug {
    // Required methods
    fn next_tick(&mut self, block_size: usize) -> ClockTick;
    fn sample_rate(&self) -> f32;

    // Provided methods
    fn start(&mut self) -> Result<(), TimeError> { ... }
    fn stop(&mut self) -> Result<(), TimeError> { ... }
    fn is_running(&self) -> bool { ... }
    fn current_position(&self) -> u64 { ... }
}
Expand description

A source of clock ticks for signal processing

Implementations can be hardware-based (ALSA, JACK) or software-based (SystemClock). The clock source is responsible for providing accurate timing information to the signal graph.

§Example

use rill_core::time::{ClockSource, SystemClock};

let mut clock = SystemClock::with_sample_rate(44100.0);
let tick = clock.next_tick(64);

Required Methods§

Source

fn next_tick(&mut self, block_size: usize) -> ClockTick

Get the next clock tick

§Arguments
  • block_size - Number of samples in the next block
§Returns

A ClockTick containing timing information for the next block

Source

fn sample_rate(&self) -> f32

Get the sample rate of this clock source

Provided Methods§

Source

fn start(&mut self) -> Result<(), TimeError>

Start the clock

This is called when the signal graph starts processing. Default implementation does nothing.

Source

fn stop(&mut self) -> Result<(), TimeError>

Stop the clock

This is called when the signal graph stops processing. Default implementation does nothing.

Source

fn is_running(&self) -> bool

Check if the clock is running

Source

fn current_position(&self) -> u64

Get the current sample position

Default implementation returns the position from the last tick, but hardware clocks may provide more accurate information.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§