pub struct MidiDecoder { /* private fields */ }Expand description
Soft-synth decoder: SMF in, interleaved S16 stereo PCM out.
Stateful — accepts exactly one SMF blob via send_packet and then
streams audio frames out of receive_frame until both the event
scheduler and the voice pool have run dry, at which point
Error::Eof is returned. Calling send_packet again replaces the
scheduler with a fresh one (re-priming for a new file).
State that survives across receive_frame calls:
Implementations§
Source§impl MidiDecoder
impl MidiDecoder
Sourcepub const TAIL_CHUNK_CAP: usize = 32
pub const TAIL_CHUNK_CAP: usize = 32
Hard cap on how many extra audio chunks we’ll emit after the last SMF event has fired. Voice release tails (50–100 ms with the round-2/3 envelopes) live inside this budget; without it, a malformed or never-releasing voice could keep the decoder emitting forever.
Sourcepub fn new(instrument: Arc<dyn Instrument>, sample_rate: u32) -> Self
pub fn new(instrument: Arc<dyn Instrument>, sample_rate: u32) -> Self
Build a decoder bound to a specific instrument and sample rate.
Use this directly when you have a SoundFont 2 bank loaded and
want to drive the synth with it; the [make_decoder] factory
(called by the codec registry) builds one with the pure-tone
fallback because there’s no instrument-discovery plumbing in
the factory signature yet.
Sourcepub fn with_instrument(instrument: Arc<dyn Instrument>) -> Self
pub fn with_instrument(instrument: Arc<dyn Instrument>) -> Self
Convenience constructor: same as new but takes a
concrete Instrument by value and wraps it in an Arc.
Sourcepub fn with_instrument_source(source: InstrumentSource) -> Result<Self>
pub fn with_instrument_source(source: InstrumentSource) -> Result<Self>
Build a decoder bound to an instrument loaded from a path on
disk. The format is dispatched by InstrumentSource so the
caller picks SFZ / SF2 / DLS explicitly (file extensions are
not always reliable indicators).
Source§impl MidiDecoder
impl MidiDecoder
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Sample rate the decoder is rendering at. Equal to whatever was
passed to new (default OUTPUT_SAMPLE_RATE when
constructed via the registry).
Trait Implementations§
Source§impl Decoder for MidiDecoder
impl Decoder for MidiDecoder
fn codec_id(&self) -> &CodecId
Source§fn send_packet(&mut self, packet: &Packet) -> Result<()>
fn send_packet(&mut self, packet: &Packet) -> Result<()>
receive_frame in a loop afterwards.Source§fn receive_frame(&mut self) -> Result<Frame>
fn receive_frame(&mut self) -> Result<Frame>
Error::NeedMore when the
decoder needs another packet.Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
receive_frame will drain buffered
frames and eventually return Error::Eof.Source§fn reset(&mut self) -> Result<()>
fn reset(&mut self) -> Result<()>
Source§fn receive_arena_frame(&mut self) -> Result<Arc<FrameInner>, Error>
fn receive_arena_frame(&mut self) -> Result<Arc<FrameInner>, Error>
arena::sync::Frame. Read moreSource§fn set_execution_context(&mut self, _ctx: &ExecutionContext)
fn set_execution_context(&mut self, _ctx: &ExecutionContext)
send_packet. Default no-op; codecs that want to run
slice-/GOP-/tile-parallel override this to capture the budget.
Ignoring the hint is always safe — callers must still work with
a decoder that runs serial.