pub struct Nco { /* private fields */ }Expand description
A numerically controlled oscillator.
Implementations§
Source§impl Nco
impl Nco
Sourcepub fn new(frequency_hz: f64, sample_rate: f64) -> Result<Nco, ErrorsJSL>
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.
Sourcepub fn from_period(period: u64) -> Result<Nco, ErrorsJSL>
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.
Sourcepub fn with_phase_turns(self, turns: f64) -> Nco
pub fn with_phase_turns(self, turns: f64) -> Nco
Sets the starting phase (and the phase that reset returns to), in turns.
Sourcepub fn set_frequency(&mut self, frequency_hz: f64) -> Result<(), ErrorsJSL>
pub fn set_frequency(&mut self, frequency_hz: f64) -> Result<(), ErrorsJSL>
Changes the frequency without disturbing the phase.
Sourcepub fn frequency(&self) -> f64
pub fn frequency(&self) -> f64
The frequency actually realised by the tuning word, in Hz (negative if running backwards).
pub fn sample_rate(&self) -> f64
Sourcepub fn phase(&self) -> Phase
pub fn phase(&self) -> Phase
The phase that the next call to next_phase will return.
Sourcepub fn set_phase_turns(&mut self, turns: f64)
pub fn set_phase_turns(&mut self, turns: f64)
Jumps to the given phase (in turns).
Sourcepub fn next_phase(&mut self) -> Phase
pub fn next_phase(&mut self) -> Phase
Returns the current phase and then advances by one sample.
Sourcepub fn next_phase_modulated(&mut self, offset_hz: f64) -> Phase
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.