rodio icon indicating copy to clipboard operation
rodio copied to clipboard

Add Elapsed filter

Open PaddyCo opened this issue 5 years ago • 6 comments

as discussed in #192, a way to get the current elapsed time is almost required for things that are supposed to be synced to the audio (rhythm games for example)

I tried solving this by making a filter, and it appears to work pretty well!

I'm not sure this is the most idiomatic approach to the problem (I'll be honest, not super familiar with rodio, or audio in general for that matter) so if you have any suggestions or better ways to solve this, shoot :smile:

PaddyCo avatar Mar 01 '20 14:03 PaddyCo

I think this implementation has several problems:

  • The duration updates only when next iteration of a chunk occurs. This is a problem when we want more precise timestamp than the chunk size.
  • Audio timer is not necessarily synchronized with system timer, and nor is the timing when the next called. Fortunately, now that the new feature of tracking precise playing/recording position is introduced in RustAudio/cpal#397, we should make use of this instead.

TonalidadeHidrica avatar Sep 01 '20 14:09 TonalidadeHidrica

Hello, any progress on this? Currently implementing a rhythm game using rodio and I'm hitting on this roadblock. Should I go ahead and open a PR utilising RustAudio/cpal#397 instead?

ghost avatar Jan 02 '21 06:01 ghost

@JackRedstonia Although there's no direct way to get the elapsed time info, current API already enables us getting it. I'm developing a rhythm game too and already succeeded in implemented precise a/v sync feature. You can see my code in my repository: TonalidadeHidrica/taiko-untitled . By the way if you want to implement this feature you can go ahead, I think. (I'm not an owner of this repo though)

TonalidadeHidrica avatar Jan 02 '21 07:01 TonalidadeHidrica

@TonalidadeHidrica I looked through the code and it seems that it only works for one music track at a time, which isn't exactly what I need, I think. I also tried to add the functionality into the rodio crate for the PR but ended up nuking it all as it was too complex.

I believe I should leave this up to someone with better understanding of rodio and cpal.

ghost avatar Jan 02 '21 14:01 ghost

@JackRedstonia I agree that current rodio interface is, although quite easy when performing "fuzzy" playback like music player, not really cut out for precise, framewise playback, when you want to build rhythm game or DTM software for example. That's why I only used rodio for decoding several audio data, and write to audio stream with cpal directly by myself.

Just for curiosity, what is your specific usecase you thought that my code lacks? (Should I refrain from discussing here?)

TonalidadeHidrica avatar Jan 02 '21 16:01 TonalidadeHidrica

@TonalidadeHidrica I'm making a game framework (which the rhythm game is built on) and I'm looking to have the ability to have any (reasonable) number of tracks playing and to be able to get their playing positions, so I'll have to change quite a lot of things to get that working. Nevertheless, the information about RustAudio/cpal#397 was quite useful, so much thanks for that. Hopefully I'll come up with a decent way to get the above idea into decent code, but for now I'll experiment with another library called BASS. (not that rodio and cpal is bad of course, I just want to see what the available options are, and I'll likely not use BASS anyways due to its horrendous licensing)

ghost avatar Jan 02 '21 17:01 ghost