CachedPlayer

Struct CachedPlayer 

Source
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>

Source

pub fn new(player: P, cache_size: usize) -> Self

Create a new cached player with the specified cache size.

Source

pub fn with_default_cache(player: P) -> Self

Create a new cached player with the default cache size (512 samples).

Source

pub fn inner(&self) -> &P

Get a reference to the underlying player.

Source

pub fn inner_mut(&mut self) -> &mut P

Get a mutable reference to the underlying player.

Source

pub fn into_inner(self) -> P

Consume the wrapper and return the underlying player.

Source

pub fn generate_sample(&mut self) -> f32

Generate a single sample, using the cache.

If the cache is exhausted, it will be refilled automatically.

Source

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.

Source

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>

Source§

fn play(&mut self)

Start or resume playback.
Source§

fn pause(&mut self)

Pause playback (keeps position).
Source§

fn stop(&mut self)

Stop playback and reset to beginning.
Source§

fn state(&self) -> PlaybackState

Get current playback state.
Source§

fn generate_samples_into(&mut self, buffer: &mut [f32])

Generate samples into an existing buffer. Read more
Source§

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)

Mute or unmute a specific channel (0-2). Read more
Source§

fn is_channel_muted(&self, channel: usize) -> bool

Check if a channel is muted. Read more
Source§

fn playback_position(&self) -> f32

Get playback position as a percentage (0.0 to 1.0). Read more
Source§

fn subsong_count(&self) -> usize

Get the number of subsongs in this file. Read more
Source§

fn current_subsong(&self) -> usize

Get the current subsong index (1-based). Read more
Source§

fn set_subsong(&mut self, index: usize) -> bool

Switch to a different subsong by 1-based index. Read more
Source§

fn psg_count(&self) -> usize

Get the number of PSG chips used by this player. Read more
Source§

fn is_playing(&self) -> bool

Check if currently playing.
Source§

fn generate_samples(&mut self, count: usize) -> Vec<f32>

Generate samples into a new buffer.
Source§

fn has_subsongs(&self) -> bool

Check if this player supports multiple subsongs.
Source§

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