Skip to main content

Nco

Struct Nco 

Source
pub struct Nco { /* private fields */ }
Expand description

A numerically controlled oscillator.

Implementations§

Source§

impl Nco

Source

pub fn new(frequency_hz: f64, sample_rate: f64) -> Result<Nco, ErrorsJSL>

An oscillator at frequency_hz for the given sampling rate. The frequency may be negative (the phase runs backwards) and must not exceed Nyquist, sample_rate / 2, in magnitude.

Source

pub fn from_period(period: u64) -> Result<Nco, ErrorsJSL>

An oscillator that completes exactly one cycle every period samples (period >= 2).

The tuning word is rounded up, so samples that fall exactly on a waveform edge (for example the 4th sample of a 6-sample square wave) always land on the late side of it.

Source

pub fn with_phase_turns(self, turns: f64) -> Nco

Sets the starting phase (and the phase that reset returns to), in turns.

Source

pub fn set_frequency(&mut self, frequency_hz: f64) -> Result<(), ErrorsJSL>

Changes the frequency without disturbing the phase.

Source

pub fn frequency(&self) -> f64

The frequency actually realised by the tuning word, in Hz (negative if running backwards).

Source

pub fn sample_rate(&self) -> f64

Source

pub fn phase(&self) -> Phase

The phase that the next call to next_phase will return.

Source

pub fn set_phase_turns(&mut self, turns: f64)

Jumps to the given phase (in turns).

Source

pub fn next_phase(&mut self) -> Phase

Returns the current phase and then advances by one sample.

Source

pub fn next_phase_modulated(&mut self, offset_hz: f64) -> Phase

Like next_phase, but this step advances at the oscillator frequency plus offset_hz (frequency modulation). The configured frequency is unchanged.

Source

pub fn reset(&mut self)

Returns to the starting phase.

Trait Implementations§

Source§

impl Clone for Nco

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Nco

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Nco

§

impl RefUnwindSafe for Nco

§

impl Send for Nco

§

impl Sync for Nco

§

impl Unpin for Nco

§

impl UnsafeUnpin for Nco

§

impl UnwindSafe for Nco

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.