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

Description

returns fundamental information about the stream

Description

returns a tight upperbound of bits neeeded to store encoded data

Comments
  • can be used to set filesize limits
Description

encodes samples and returns number of samples encoded

Description

Decodes part of the stream and writes it out into the samples buffer

Returns

Number of samples decoded

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() or dt=SeekFrom::Start(0)
      before encoding. This will reuse the stream memory allocated.
  • Notes about WavCodec:
    • SeekFrom::Start, SeekFrom::Current and SeekFrom::End is implemented
    • there no restrictions on how one should call this after encode/decode

Implementors