ChiptunePlayerBase

Trait ChiptunePlayerBase 

Source
pub trait ChiptunePlayerBase: Send {
Show 17 methods // Required methods fn play(&mut self); fn pause(&mut self); fn stop(&mut self); fn state(&self) -> PlaybackState; fn generate_samples_into(&mut self, buffer: &mut [f32]); // Provided methods fn is_playing(&self) -> bool { ... } fn generate_samples(&mut self, count: usize) -> Vec<f32> { ... } fn sample_rate(&self) -> u32 { ... } fn set_channel_mute(&mut self, _channel: usize, _mute: bool) { ... } fn is_channel_muted(&self, _channel: usize) -> bool { ... } fn playback_position(&self) -> f32 { ... } fn subsong_count(&self) -> usize { ... } fn current_subsong(&self) -> usize { ... } fn set_subsong(&mut self, _index: usize) -> bool { ... } fn has_subsongs(&self) -> bool { ... } fn psg_count(&self) -> usize { ... } fn channel_count(&self) -> usize { ... }
}
Expand description

Object-safe base trait for chiptune players.

This trait provides all playback functionality without the associated Metadata type, making it usable as a trait object (Box<dyn ChiptunePlayerBase>).

All types implementing ChiptunePlayer automatically implement this trait.

§Example

use ym2149_common::{ChiptunePlayerBase, PlaybackState};

fn play_any(player: &mut dyn ChiptunePlayerBase) {
    player.play();
    while player.state() == PlaybackState::Playing {
        let mut buffer = vec![0.0; 1024];
        player.generate_samples_into(&mut buffer);
        // ... send buffer to audio device
    }
}

Required Methods§

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.

Fills the entire buffer with audio samples. If playback is stopped or paused, the buffer is filled with silence (zeros).

Provided Methods§

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 sample_rate(&self) -> u32

Get the output sample rate in Hz.

Typical value is 44100 Hz.

Source

fn set_channel_mute(&mut self, _channel: usize, _mute: bool)

Mute or unmute a specific channel (0-2).

Default implementation does nothing. Override if the player supports channel muting.

Source

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

Check if a channel is muted.

Default returns false. Override if the player supports channel muting.

Source

fn playback_position(&self) -> f32

Get playback position as a percentage (0.0 to 1.0).

Default returns 0.0. Override if position tracking is available.

Source

fn subsong_count(&self) -> usize

Get the number of subsongs in this file.

Default returns 1. Override for formats with multiple subsongs.

Source

fn current_subsong(&self) -> usize

Get the current subsong index (1-based).

Default returns 1. Override for formats with multiple subsongs.

Source

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

Switch to a different subsong by 1-based index.

Returns true if successful. Default returns false.

Source

fn has_subsongs(&self) -> bool

Check if this player supports multiple subsongs.

Source

fn psg_count(&self) -> usize

Get the number of PSG chips used by this player.

Most players use a single chip (returns 1). Arkos Tracker songs can use multiple PSGs for 6+ channel music.

Source

fn channel_count(&self) -> usize

Get the total number of audio channels.

Each PSG chip has 3 channels (A, B, C), so this returns psg_count() * 3.

Implementors§