Skip to main content

NcoSource

Struct NcoSource 

Source
pub struct NcoSource<W: Waveform> { /* private fields */ }
Expand description

A signal source: an Nco driving a Waveform, scaled by amplitude and shifted by offset.

Implementations§

Source§

impl<W: Waveform> NcoSource<W>

Source

pub fn from_parts(nco: Nco, waveform: W) -> Self

Builds a unit-amplitude, zero-offset source from an oscillator and a waveform.

Source

pub fn with_amplitude(self, amplitude: f64) -> Self

Sets the output amplitude (a multiplier on the waveform).

Source

pub fn with_offset(self, offset: W::Output) -> Self

Sets a constant added to every output sample (a complex constant for complex sources).

Source

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

Sets the starting phase in turns (a quarter turn turns a sine into a cosine).

Source

pub fn nco(&self) -> &Nco

Access to the oscillator, e.g. to retune it.

Source

pub fn nco_mut(&mut self) -> &mut Nco

Source

pub fn waveform(&self) -> &W

Access to the waveform.

Source

pub fn waveform_mut(&mut self) -> &mut W

Source

pub fn next_sample(&mut self) -> W::Output

Produces the next output sample.

Source

pub fn next_sample_modulated(&mut self, offset_hz: f64) -> W::Output

Produces the next output sample with the frequency offset by offset_hz for this step.

Source

pub fn generate(&mut self, count: usize) -> Vec<W::Output>

Produces the next count samples.

Source§

impl NcoSource<PulseTrainWave>

Source

pub fn pulse_train( frequency_hz: f64, sample_rate: f64, duty: f64, ) -> Result<Self, ErrorsJSL>

Pulses at frequency_hz with the given duty cycle.

Source

pub fn pulse_train_with_period( period: u64, width: u64, ) -> Result<Self, ErrorsJSL>

Pulses repeating every period samples, each width samples long (width <= period).

Source§

impl NcoSource<RampWave>

Source

pub fn ramp(frequency_hz: f64, sample_rate: f64) -> Result<Self, ErrorsJSL>

A rising sawtooth at frequency_hz. A negative frequency gives a falling sawtooth.

Source

pub fn ramp_with_period(period: u64) -> Result<Self, ErrorsJSL>

A rising sawtooth with an integer period in samples (>= 2).

Source§

impl NcoSource<TriangleWave>

Source

pub fn triangle(frequency_hz: f64, sample_rate: f64) -> Result<Self, ErrorsJSL>

A triangle wave at frequency_hz.

Source

pub fn triangle_with_period(period: u64) -> Result<Self, ErrorsJSL>

A triangle wave with an integer period in samples (>= 2).

Source§

impl NcoSource<SineWave>

Source

pub fn sinusoid(frequency_hz: f64, sample_rate: f64) -> Result<Self, ErrorsJSL>

A sine source at frequency_hz for the given sampling rate (starting at phase 0).

Source

pub fn sinusoid_cordic( frequency_hz: f64, sample_rate: f64, iterations: u32, ) -> Result<Self, ErrorsJSL>

Like sinusoid but evaluating the sine with iterations (1 to 30) integer CORDIC steps.

Source

pub fn sinusoid_cordic64( frequency_hz: f64, sample_rate: f64, iterations: u32, ) -> Result<Self, ErrorsJSL>

Like sinusoid but evaluating the sine with iterations (1 to 62) 64-bit integer CORDIC steps; 52 or more reaches double-precision accuracy.

Source§

impl NcoSource<SquareWave>

Source

pub fn square(frequency_hz: f64, sample_rate: f64) -> Result<Self, ErrorsJSL>

A symmetric square wave at frequency_hz.

Source

pub fn square_with_duty( frequency_hz: f64, sample_rate: f64, duty: f64, ) -> Result<Self, ErrorsJSL>

A square wave at frequency_hz with an arbitrary duty cycle.

Source

pub fn square_with_period(period: u64, high: u64) -> Result<Self, ErrorsJSL>

A square wave with an integer period in samples and high samples of every period at +1.

Source§

impl NcoSource<NoiseWave>

Source

pub fn white_noise(kind: NoiseKind, seed: u64) -> Self

White noise: an independent value every sample.

Source

pub fn sample_and_hold_noise( kind: NoiseKind, seed: u64, rate_hz: f64, sample_rate: f64, ) -> Result<Self, ErrorsJSL>

Sample-and-hold noise that draws a new value rate_hz times per second.

Source§

impl NcoSource<QuadratureWave>

Source

pub fn quadrature( frequency_hz: f64, sample_rate: f64, polarity: Polarity, ) -> Result<Self, ErrorsJSL>

A quadrature source at frequency_hz using floating-point sin/cos.

Source

pub fn quadrature_cordic( frequency_hz: f64, sample_rate: f64, polarity: Polarity, iterations: u32, ) -> Result<Self, ErrorsJSL>

A quadrature source whose sine and cosine come from a single 32-bit integer CORDIC pass with iterations (1 to 30) micro-rotations (accurate to about 1e-8).

Source

pub fn quadrature_cordic64( frequency_hz: f64, sample_rate: f64, polarity: Polarity, iterations: u32, ) -> Result<Self, ErrorsJSL>

Like quadrature_cordic but with the 64-bit CORDIC (iterations 1 to 62; 52 or more reaches double-precision accuracy) driven by the oscillator’s full 64-bit phase.

Source

pub fn polarity(&self) -> Polarity

The current polarity.

Source

pub fn set_polarity(&mut self, polarity: Polarity)

Changes the polarity; the phase continues without a jump.

Trait Implementations§

Source§

impl<W: Clone + Waveform> Clone for NcoSource<W>
where W::Output: Clone,

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<W: Debug + Waveform> Debug for NcoSource<W>
where W::Output: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W: Waveform> StreamOperator<(), <W as Waveform>::Output> for NcoSource<W>

Free-running operation: the number of input items is the number of samples produced.

Source§

fn process( &mut self, data_in: &[()], ) -> Result<Option<Vec<W::Output>>, ErrorsJSL>

Processes a chunk of input data and produces a corresponding chunk of output data. The input and output types can be defined based on the specific requirements of the application, such as audio samples, video frames, or other types of data. This method is called repeatedly as new data becomes available in the stream.
Source§

fn flush(&mut self) -> Result<Option<Vec<W::Output>>, ErrorsJSL>

Flushes any remaining data in the operator’s internal buffers and produces any final output data. This method is typically called at the end of a stream or when the operator needs to be shut down, allowing it to perform any necessary cleanup or final computations before the stream is terminated.
Source§

impl<W: Waveform> StreamOperator<f64, <W as Waveform>::Output> for NcoSource<W>

Frequency-modulated operation: each input is a frequency offset in Hz for that sample.

Source§

fn process( &mut self, data_in: &[f64], ) -> Result<Option<Vec<W::Output>>, ErrorsJSL>

Processes a chunk of input data and produces a corresponding chunk of output data. The input and output types can be defined based on the specific requirements of the application, such as audio samples, video frames, or other types of data. This method is called repeatedly as new data becomes available in the stream.
Source§

fn flush(&mut self) -> Result<Option<Vec<W::Output>>, ErrorsJSL>

Flushes any remaining data in the operator’s internal buffers and produces any final output data. This method is typically called at the end of a stream or when the operator needs to be shut down, allowing it to perform any necessary cleanup or final computations before the stream is terminated.
Source§

impl<W: Waveform> StreamOperatorManagement for NcoSource<W>

Source§

fn reset(&mut self) -> Result<(), ErrorsJSL>

Resets the internal state of the operator, preparing it for a new stream of data. This method is typically called at the beginning of a new stream or when the operator needs to be reinitialized.
Source§

fn finalize(&mut self) -> Result<(), ErrorsJSL>

Finalizes the processing of the stream, performing any necessary cleanup or final computations. This method is typically called at the end of a stream or when the operator needs to be shut down.

Auto Trait Implementations§

§

impl<W> Freeze for NcoSource<W>
where W: Freeze, <W as Waveform>::Output: Freeze,

§

impl<W> RefUnwindSafe for NcoSource<W>

§

impl<W> Send for NcoSource<W>
where W: Send, <W as Waveform>::Output: Send,

§

impl<W> Sync for NcoSource<W>
where W: Sync, <W as Waveform>::Output: Sync,

§

impl<W> Unpin for NcoSource<W>
where W: Unpin, <W as Waveform>::Output: Unpin,

§

impl<W> UnsafeUnpin for NcoSource<W>

§

impl<W> UnwindSafe for NcoSource<W>
where W: UnwindSafe, <W as Waveform>::Output: UnwindSafe,

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.