pub struct SampleCache { /* private fields */ }Expand description
A sample cache for efficient single-sample access.
This is a lightweight helper that manages sample and channel output caching. Use it when you need to add caching to a player without wrapping it entirely.
§Example
ⓘ
use ym2149_common::SampleCache;
struct MyPlayer {
inner: SomePlayer,
cache: SampleCache,
}
impl MyPlayer {
fn generate_sample(&mut self) -> f32 {
if self.cache.needs_refill() {
// Fill the cache
self.inner.generate_samples_into(self.cache.sample_buffer_mut());
let outputs = self.inner.get_channel_outputs();
self.cache.fill_channel_outputs(outputs);
self.cache.mark_filled();
}
self.cache.next_sample()
}
}Implementations§
Source§impl SampleCache
impl SampleCache
Sourcepub fn needs_refill(&self) -> bool
pub fn needs_refill(&self) -> bool
Check if the cache needs to be refilled.
Sourcepub fn sample_buffer_mut(&mut self) -> &mut [f32]
pub fn sample_buffer_mut(&mut self) -> &mut [f32]
Get a mutable reference to the sample buffer for filling.
Sourcepub fn fill_channel_outputs(&mut self, outputs: [f32; 3])
pub fn fill_channel_outputs(&mut self, outputs: [f32; 3])
Fill all channel output entries with the same value.
Call this after filling samples to set the channel outputs for visualization.
Sourcepub fn mark_filled(&mut self)
pub fn mark_filled(&mut self)
Mark the cache as filled and reset position to start.
Sourcepub fn next_sample(&mut self) -> f32
pub fn next_sample(&mut self) -> f32
Get the next sample from the cache.
Returns 0.0 if the cache is empty.
Sourcepub fn channel_outputs(&self) -> [f32; 3]
pub fn channel_outputs(&self) -> [f32; 3]
Get the channel outputs for the current/last sample.
Trait Implementations§
Source§impl Clone for SampleCache
impl Clone for SampleCache
Source§fn clone(&self) -> SampleCache
fn clone(&self) -> SampleCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SampleCache
impl RefUnwindSafe for SampleCache
impl Send for SampleCache
impl Sync for SampleCache
impl Unpin for SampleCache
impl UnwindSafe for SampleCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more