BandLimited

Struct BandLimited 

Source
pub struct BandLimited<T, O = BandLimWide> { /* private fields */ }
Expand description

Bandwidth-Limited Pulse Buffer implementation with high-pass and low-pass filtering, for an efficient band-limited synthesis.

T specifies pulse step amplitude unit types. Currently, implementations are provided for: f32, i16, and i32.

Implementations§

Source§

impl<T: Copy + Default, O> BandLimited<T, O>

Source

pub fn reset(&mut self)

Clears buffered data and resets frame start to default.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the excessive capacity of the buffer as much as possible.

Source

pub fn set_frame_time(&mut self, frame_time: f64, margin_time: f64)

Ensures the frame buffer length is large enough to fit data for the specified frame_time with additional margin_time.

Sets the duration of the average frame to frame_time which should be specified with as much precision as possible.

margin_time specifies a frame duration fluctuation margin and should be significantly smaller than frame_time.

Both frame_time and margin_time are specified in the sample time units (1.0 = 1 audio sample).

Source

pub fn is_frame_ended(&mut self) -> bool

Returns true if BandLimited::end_frame has been called before the call to BandLimited::next_frame.

It indicates if audio samples can be digitized from the last frame data.

Source

pub fn end_frame(&mut self, time_end: f64) -> usize

Finalizes audio frame.

Returns the number of audio samples, single channel-wise, which are ready to be produced from the frame.

time_end is specified in the sample time units (1.0 = 1 audio sample).

Source§

impl<T, O> BandLimited<T, O>

Source

pub fn new(channels: usize) -> Self

Returns a new instance of BandLimited buffer.

  • channels - specifies the maximum number of audio channels that the sound can be rendered for.

Before any pulse steps are added to the buffer the method BandLimited::set_frame_time or Blep::ensure_frame_time must be called first.

§Panics

Panics if channels equals to 0.

Source

pub fn next_frame(&mut self)

Prepares the buffer for the next audio frame.

This method must be called after the call to BandLimited::end_frame or to Blep::end_frame and optionally after audio data has been produced with BandLimited::sum_iter.

Source§

impl<T, O> BandLimited<T, O>
where T: Copy + MulNorm + FromSample<f32>, O: BandLimOpt,

Source

pub fn sum_iter<'a, S: 'a>( &'a self, channel: usize, ) -> impl Iterator<Item = S> + ExactSizeIterator + 'a
where T: IntoSample<S>,

Returns an iterator that produces audio samples in the specified sample format S from the specified channel.

This method must be called after the call to BandLimited::end_frame or Blep::end_frame and before BandLimited::next_frame.

Trait Implementations§

Source§

impl<T, O> Blep for BandLimited<T, O>

Source§

type SampleDelta = T

A type for sample ∆ amplitudes (pulse height).
Source§

fn ensure_frame_time( &mut self, sample_rate: u32, ts_rate: f64, frame_ts: FTs, margin_ts: FTs, )

This method allows the Blep implementation to reserve enough memory for the audio frame with an additional margin and to set up a sample time rate and other internals. Read more
Source§

fn end_frame(&mut self, timestamp: FTs) -> usize

Finalizes audio frame. Read more
Source§

fn add_step(&mut self, channel: usize, timestamp: FTs, delta: T)

This method is being used to add square-wave pulse steps within a boundary of a single frame. Read more

Auto Trait Implementations§

§

impl<T, O> Freeze for BandLimited<T, O>
where T: Freeze,

§

impl<T, O = BandLimWide> !RefUnwindSafe for BandLimited<T, O>

§

impl<T, O> Send for BandLimited<T, O>
where O: Send, T: Send,

§

impl<T, O = BandLimWide> !Sync for BandLimited<T, O>

§

impl<T, O> Unpin for BandLimited<T, O>
where O: Unpin, T: Unpin,

§

impl<T, O> UnwindSafe for BandLimited<T, O>
where O: UnwindSafe, T: 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> 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<S, T> IntoSample<S> for T
where S: FromSample<T>,

Source§

fn into_sample(self) -> S

Convert to S a sample type from self.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.