how to play the same sound at a list of intervals
this not an issue, sorry, but didn't find where to ask about it, this is my use case: I have a small sound in a wav file, and a list of intervals, e.g.
let file = std::fs::File::open("data/beat.wav").unwrap();
let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
let intervals: Vec<u64> = vec![400, 400, 401]; // in milliseconds
I need to play beat after each interval, it is also possible to have a Vec with the actual timestamps in which the sounds most play.
any hints will be appreciated
this is what I ended up doing, but I wonder if there is a better way, and/or what at the trade offs of this approach, I really don't like the source.clone() part...
fn play_beats(sink: &Sink, intervals: Vec<u64>) {
let file = std::fs::File::open("data/beat.wav").unwrap();
let source = rodio::Decoder::new(BufReader::new(file))
.unwrap()
.buffered();
intervals.iter().for_each(|interval| {
let s = source.clone().delay(Duration::from_millis(*interval));
sink.append(s);
});
}
someone in discord suggested this:
can you decode the wave to a vec of samples and use a slice reference as your source?
but it is not clear to me how to do this... any pointers?
I have a question. does source have clone function?
I'm new to this crate, thanks.
I know that. Thanks.