You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Playing the same sound several times requires allocating a new buffer each time #141
I've been looking at the various Rodio sources for a while and I'm unable to find any sources that allow reusing a buffer of sound.
The closest solution appears to be using SamplesBuffer and cloning the vector each time, but this is inefficient as it requires an allocation and deallocation for each played sound.
I believe this crate should contain a source that wraps a vector of samples in an Arc, allowing the allocated memory to be reused.
I've attached a sample implementation of such a source: main.rs.
@Darksonn Hey! We had a similar problem in the Amethyst game engine. What I chose to do was create an Arc of the raw encoded file data (Arc<Vec<u8>>) and then implement std::convert::AsRef<[u8]> for a wrapper structure over that Arc, then when I needed to play the sound I'd initialize a new std::io::Cursor over that structure and feed it into a new rodio::Decoder. I like this approach because it allows the in-memory representation to stay compressed with the original audio compression algorithm, audio compression algorithms can reduce the memory footprint of a sound by up to 10x in some instances.
Reacted by Joe Higton, Foo Yong Jie, Sathwik Matsa, Raz-Hemo, TanTanDev, Rafael Merlin, TonalidadeHidrica, Philippe Aucazou, Arthur Franco Moreira, Heraclito-Q-Saldanha and 6 more
Reacted by Arthur Franco Moreira, Aurélien Bertron and dest1yo
Activity
Xaeroxe commentedon Oct 12, 2017
@Darksonn Hey! We had a similar problem in the Amethyst game engine. What I chose to do was create an Arc of the raw encoded file data (
Arc<Vec<u8>>) and then implementstd::convert::AsRef<[u8]>for a wrapper structure over that Arc, then when I needed to play the sound I'd initialize a newstd::io::Cursorover that structure and feed it into a newrodio::Decoder. I like this approach because it allows the in-memory representation to stay compressed with the original audio compression algorithm, audio compression algorithms can reduce the memory footprint of a sound by up to 10x in some instances.sinesc commentedon Apr 22, 2018
I think this is a minimal example of the above approach. Thanks @Xaeroxe
HastagGuigui commentedon Aug 25, 2025
This example snippet doesn't work in latest crate (especially
play_raw)... Is there any alternative way to do this?roderickvd commentedon Aug 25, 2025
In #786 I will implement
TryFrom<Arc<Vec<T>>> for DecoderandBox<Vec<T>>to make this easier.feat(decoders)!: implement comprehensive seeking and bit depth detect…
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types
feat: add Decoder support for Bytes, Arc, Box, and Vec types