Skip to main content

Synth

Struct Synth 

Source
pub struct Synth { /* private fields */ }
Expand description

The synthesizer: voices, sequencer and a copy of the cart’s audio data.

Implementations§

Source§

impl Synth

Source

pub fn new(sample_rate: f32) -> Self

Source

pub fn load(&mut self, sfx: Vec<Sfx>, music: Vec<MusicPattern>)

Replace the audio data (called when a cart starts or assets change).

Source

pub fn stop_all(&mut self)

Stop all voices and the sequencer.

Source

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.

Source

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.

Source

pub fn stop_music(&mut self)

Source

pub fn playing_pattern(&self) -> Option<usize>

Index of the playing music pattern, if any.

Source

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.

Source

pub fn channel_sfx(&self) -> [Option<usize>; 4]

Which SFX index is playing on each channel (for editor UI).

Source

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.

Auto Trait Implementations§

§

impl Freeze for Synth

§

impl RefUnwindSafe for Synth

§

impl Send for Synth

§

impl Sync for Synth

§

impl Unpin for Synth

§

impl UnsafeUnpin for Synth

§

impl UnwindSafe for Synth

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.