Trait adhoc_audio::codec::Streamable
source · [−]pub trait Streamable {
fn info(&self) -> StreamInfo;
fn filesize_upperbound(&self) -> u64;
fn encode(&mut self, samples: &[f32]) -> Option<usize>;
fn decode(&mut self, samples: &mut [f32]) -> Option<usize>;
fn seek(&mut self, dt: SeekFrom);
}
Expand description
all codecs in this crate implement this trait to expose the encode(..)
,decode(..)
and seek(..)
routines
Description
Designed for use in the browser so all audio data is assumed to be PCM INTERLEAVED with IEE754 values ranging from -1.0 to 1.0
Comments
- Some people may think it unusual to do audio stuff in f32 but WEBAUDIO API pretty much forces me to use them
Required Methods
sourcefn info(&self) -> StreamInfo
fn info(&self) -> StreamInfo
Description
returns fundamental information about the stream
sourcefn filesize_upperbound(&self) -> u64
fn filesize_upperbound(&self) -> u64
Description
returns a tight upperbound of bits neeeded to store encoded data
Comments
- can be used to set filesize limits
sourcefn encode(&mut self, samples: &[f32]) -> Option<usize>
fn encode(&mut self, samples: &[f32]) -> Option<usize>
Description
encodes samples
and returns number of samples encoded
sourcefn decode(&mut self, samples: &mut [f32]) -> Option<usize>
fn decode(&mut self, samples: &mut [f32]) -> Option<usize>
Description
Decodes part of the stream and writes it out into the samples
buffer
Returns
Number of samples decoded
sourcefn seek(&mut self, dt: SeekFrom)
fn seek(&mut self, dt: SeekFrom)
Description
Seeks to a certain spot in the stream
Parameters
dt
is change in time in milliseconds
Comments
- Notes about
AdhocCodec
:- Currently only
SeekFrom::Start
is implemented - Intented to be used ONLY AFTER you’ve completely finished encoding
audio, or you have just loaded the codec for the first time - with
AdhocCodec
you can’t just seek to a random spot and start encoding - If you want to reuse the memory allocated call
AdhocCodec::init()
ordt=SeekFrom::Start(0)
before encoding. This will reuse the stream memory allocated.
- Currently only
- Notes about
WavCodec
:SeekFrom::Start
,SeekFrom::Current
andSeekFrom::End
is implemented- there no restrictions on how one should call this after encode/decode