pub struct Synth { /* private fields */ }Expand description
The synthesizer: voices, sequencer and a copy of the cart’s audio data.
Implementations§
Source§impl Synth
impl Synth
pub fn new(sample_rate: f32) -> Self
Sourcepub fn load(&mut self, sfx: Vec<Sfx>, music: Vec<MusicPattern>)
pub fn load(&mut self, sfx: Vec<Sfx>, music: Vec<MusicPattern>)
Replace the audio data (called when a cart starts or assets change).
Sourcepub fn play_sfx(&mut self, n: i32, channel: i32)
pub fn play_sfx(&mut self, n: i32, channel: i32)
Play SFX n. channel < 0 picks a free channel (preferring ones not
used by music); n < 0 with a valid channel stops that channel.
Sourcepub fn play_music(
&mut self,
n: i32,
fade_duration: i32,
channel_mask: i32,
token: i32,
) -> i32
pub fn play_music( &mut self, n: i32, fade_duration: i32, channel_mask: i32, token: i32, ) -> i32
Start music at pattern n (mints and returns a nonzero play-token) or,
when n < 0, stop. A start is refused — returns 0 — while a song is
already playing and not fading out. A stop acts only when token <= 0
(unconditional) or token equals the current song’s play-token.
channel_mask bits 0-3 mark which channels are reserved for music;
auto-routed sfx will skip those channels while music is playing.
pub fn stop_music(&mut self)
Sourcepub fn playing_pattern(&self) -> Option<usize>
pub fn playing_pattern(&self) -> Option<usize>
Index of the playing music pattern, if any.
Sourcepub fn next_sample(&mut self) -> f32
pub fn next_sample(&mut self) -> f32
Render one mono sample at the device rate.
The synth core runs at INTERNAL_RATE; this resamples up to the
device rate with linear interpolation, then applies a two-pole
reconstruction low-pass to suppress interpolation imaging and match
PICO-8’s clean top end. Calling it N times advances device time by
N / sample_rate seconds.
Sourcepub fn channel_sfx(&self) -> [Option<usize>; 4]
pub fn channel_sfx(&self) -> [Option<usize>; 4]
Which SFX index is playing on each channel (for editor UI).
Sourcepub fn channel_step(&self) -> [Option<usize>; 4]
pub fn channel_step(&self) -> [Option<usize>; 4]
Which step each channel’s voice is currently sounding (for editor
playheads); None when the channel is idle.