kira/sound/streaming/
decoder.rs

1#[cfg(test)]
2pub(crate) mod mock;
3#[cfg(feature = "symphonia")]
4pub(crate) mod symphonia;
5
6use crate::frame::Frame;
7
8/// Decodes chunks of audio.
9pub trait Decoder: Send {
10	/// Errors that can occur when decoding audio.
11	type Error;
12
13	/// Returns the sample rate of the audio (in Hz).
14	#[must_use]
15	fn sample_rate(&self) -> u32;
16
17	/// Returns the total number of samples of audio.
18	#[must_use]
19	fn num_frames(&self) -> usize;
20
21	/// Decodes the next chunk of audio.
22	fn decode(&mut self) -> Result<Vec<Frame>, Self::Error>;
23
24	/// Seeks to an audio sample.
25	///
26	/// The `index` is the _requested_ sample to seek to. It's OK if the decoder
27	/// seeks to an earlier sample than the one requested.
28	///
29	/// This should return the sample index that was _actually_ seeked to.
30	fn seek(&mut self, index: usize) -> Result<SeekedToIndex, Self::Error>;
31}
32
33type SeekedToIndex = usize;