Skip to main content

BlipBuf

Struct BlipBuf 

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

Streaming BLEP decimator + filter chain that feeds host-rate samples to the frontend’s audio thread.

Implementations§

Source§

impl BlipBuf

Source

pub fn new(sample_rate: u32, cpu_rate: f64) -> Self

Create a new band-limited buffer.

sample_rate is the host audio rate in Hz (typically 44 100). cpu_rate is the NES CPU rate in Hz (CPU_HZ_NTSC or CPU_HZ_PAL).

Source

pub fn set_filter_model(&mut self, model: FilterModel)

v2.1.3 — swap the analog output-filter model (see crate::mixer::FilterModel), rebuilding the filter chain at the current sample rate. This resets the filter’s IIR state, so switching while audio is playing (the Settings selector applies it live) produces a brief transient — as with any live filter swap. The frontend also applies it at ROM load / power-cycle, where there is no audible discontinuity.

Source

pub fn reset(&mut self)

Reset to silence. Empties the input ring, the pending output queue, and the filter chain state.

Source

pub fn add_sample(&mut self, value: f32)

Add one mixed sample at CPU resolution. The buffer accumulates host-rate samples internally; drain via Self::drain or Self::drain_all.

The mixer’s output is approximately in [-0.5, 0.5] for the 2A03 alone, with on-cart audio expansions pushing the absolute range up somewhat. We clamp value defensively so a stray NaN/Inf or runaway mapper can’t propagate non-finite values into the FIR state. The clamp range is far outside any sane mixer output, so the gate is purely a saturation backstop, not a normal-operation limiter.

Source

pub fn drain(&mut self, out: &mut [f32]) -> usize

Drain finalized samples into out. Returns the number written. Excess pending samples are kept; if out.len() < self.samples.len() the remainder waits for the next drain.

Source

pub fn drain_all(&mut self) -> Vec<f32>

Drain all finalized samples into a new Vec.

Source

pub fn len(&self) -> usize

Number of samples currently buffered, awaiting drain.

Source

pub fn is_empty(&self) -> bool

Whether the pending-output queue is empty.

Trait Implementations§

Source§

impl Clone for BlipBuf

Source§

fn clone(&self) -> BlipBuf

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BlipBuf

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 = 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.