RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.78k stars 231 forks source link

Use a separate thread for decoding #96

Open tomaka opened 7 years ago

tomaka commented 7 years ago

Right now the engine loads samples "lazily" when the cpal backend requests them.

In other words, cpal tells rodio that samples are needed, and then only the samples are loaded from the audio file, converted, etc.

This is bad because passing samples to cpal should be the top priority in order to avoid a potential underflow.

I think we should add a PrebufferedFilter type that wraps around a Source and allows pre-buffering some of the input. The engine would automatically wrap any source sent to it around a PrebufferedFilter, and call preload(...) on the sources during downtimes.

However this design requires some modifications in cpal in order to allow executing stuff during downtimes.

tomaka commented 7 years ago

After some discussion this is a bad design. The decoding should be performed in an entirely separate thread in order to avoid problems if the harddrive isn't fast enough.

tomaka commented 7 years ago

Of course we could also load data from the disk asynchronously, but that would be an enormous change.