pub struct CachedPlayer<P: CacheablePlayer> { /* private fields */ }Expand description
A cached wrapper around a chiptune player.
This wrapper maintains a sample cache and channel output cache, reducing the overhead of single-sample generation for CPU-emulated players.
§Example
ⓘ
use ym2149_common::{CachedPlayer, CacheablePlayer, DEFAULT_CACHE_SIZE};
let player = SomePlayer::new();
let mut cached = CachedPlayer::new(player, DEFAULT_CACHE_SIZE);
// Generate samples one at a time (efficient due to caching)
let sample = cached.generate_sample();
let channels = cached.cached_channel_outputs();Implementations§
Source§impl<P: CacheablePlayer> CachedPlayer<P>
impl<P: CacheablePlayer> CachedPlayer<P>
Sourcepub fn new(player: P, cache_size: usize) -> Self
pub fn new(player: P, cache_size: usize) -> Self
Create a new cached player with the specified cache size.
Sourcepub fn with_default_cache(player: P) -> Self
pub fn with_default_cache(player: P) -> Self
Create a new cached player with the default cache size (512 samples).
Sourcepub fn into_inner(self) -> P
pub fn into_inner(self) -> P
Consume the wrapper and return the underlying player.
Sourcepub fn generate_sample(&mut self) -> f32
pub fn generate_sample(&mut self) -> f32
Generate a single sample, using the cache.
If the cache is exhausted, it will be refilled automatically.
Sourcepub fn cached_channel_outputs(&self) -> [f32; 3]
pub fn cached_channel_outputs(&self) -> [f32; 3]
Get the channel outputs corresponding to the last generated sample.
This returns the channel outputs that were captured when the cache was last filled. Not sample-accurate, but provides reasonable visualization data.
Sourcepub fn reset_cache(&mut self)
pub fn reset_cache(&mut self)
Reset the cache, forcing a refill on the next sample request.
Trait Implementations§
Source§impl<P: CacheablePlayer> ChiptunePlayerBase for CachedPlayer<P>
impl<P: CacheablePlayer> ChiptunePlayerBase for CachedPlayer<P>
Source§fn state(&self) -> PlaybackState
fn state(&self) -> PlaybackState
Get current playback state.
Source§fn generate_samples_into(&mut self, buffer: &mut [f32])
fn generate_samples_into(&mut self, buffer: &mut [f32])
Generate samples into an existing buffer. Read more
Source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Get the output sample rate in Hz. Read more
Source§fn set_channel_mute(&mut self, channel: usize, mute: bool)
fn set_channel_mute(&mut self, channel: usize, mute: bool)
Mute or unmute a specific channel (0-2). Read more
Source§fn playback_position(&self) -> f32
fn playback_position(&self) -> f32
Get playback position as a percentage (0.0 to 1.0). Read more
Source§fn subsong_count(&self) -> usize
fn subsong_count(&self) -> usize
Get the number of subsongs in this file. Read more
Source§fn current_subsong(&self) -> usize
fn current_subsong(&self) -> usize
Get the current subsong index (1-based). Read more
Source§fn set_subsong(&mut self, index: usize) -> bool
fn set_subsong(&mut self, index: usize) -> bool
Switch to a different subsong by 1-based index. Read more
Source§fn is_playing(&self) -> bool
fn is_playing(&self) -> bool
Check if currently playing.
Source§fn has_subsongs(&self) -> bool
fn has_subsongs(&self) -> bool
Check if this player supports multiple subsongs.
Source§fn channel_count(&self) -> usize
fn channel_count(&self) -> usize
Get the total number of audio channels. Read more
Auto Trait Implementations§
impl<P> Freeze for CachedPlayer<P>where
P: Freeze,
impl<P> RefUnwindSafe for CachedPlayer<P>where
P: RefUnwindSafe,
impl<P> Send for CachedPlayer<P>
impl<P> Sync for CachedPlayer<P>where
P: Sync,
impl<P> Unpin for CachedPlayer<P>where
P: Unpin,
impl<P> UnwindSafe for CachedPlayer<P>where
P: UnwindSafe,
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