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§
Sourcefn state(&self) -> PlaybackState
fn state(&self) -> PlaybackState
Get current playback state.
Sourcefn generate_samples_into(&mut self, buffer: &mut [f32])
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§
Sourcefn is_playing(&self) -> bool
fn is_playing(&self) -> bool
Check if currently playing.
Sourcefn generate_samples(&mut self, count: usize) -> Vec<f32>
fn generate_samples(&mut self, count: usize) -> Vec<f32>
Generate samples into a new buffer.
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Get the output sample rate in Hz.
Typical value is 44100 Hz.
Sourcefn 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).
Default implementation does nothing. Override if the player supports channel muting.
Sourcefn is_channel_muted(&self, _channel: usize) -> bool
fn is_channel_muted(&self, _channel: usize) -> bool
Check if a channel is muted.
Default returns false. Override if the player supports channel muting.
Sourcefn playback_position(&self) -> f32
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.
Sourcefn subsong_count(&self) -> usize
fn subsong_count(&self) -> usize
Get the number of subsongs in this file.
Default returns 1. Override for formats with multiple subsongs.
Sourcefn current_subsong(&self) -> usize
fn current_subsong(&self) -> usize
Get the current subsong index (1-based).
Default returns 1. Override for formats with multiple subsongs.
Sourcefn set_subsong(&mut self, _index: usize) -> bool
fn set_subsong(&mut self, _index: usize) -> bool
Switch to a different subsong by 1-based index.
Returns true if successful. Default returns false.
Sourcefn has_subsongs(&self) -> bool
fn has_subsongs(&self) -> bool
Check if this player supports multiple subsongs.
Sourcefn psg_count(&self) -> usize
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.
Sourcefn channel_count(&self) -> usize
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.