anthumchris / opus-stream-decoder

Instantly decode Ogg Opus audio streams in chunks with JavaScript & WebAssembly (Wasm)
125 stars 21 forks source link

Allow reuse of decoder for subsequent files #7

Open anthumchris opened 4 years ago

anthumchris commented 4 years ago

Allow for the use case where the same decoder is used to play/decode multiple files, similar to a streaming music player like Spotify or iTunes. The decoder should be able to be "reset" and re-used for new/subsequent files, avoiding re-instantiation of the WebAssembly module and any potential side-effects.

Currently, the decode buffer would contain un-decoded Ogg bytes form the previous file if reused. An observed side note: when tested, the decoder still works (due to Opus' recoverability from loss) and recovers from re-starting the decoding of the same file, but this probably won't succeed work for files that contain different bitrates and headers.

A formal reset method would allow a new file's header page to be read and would clear any bytes from previous files.