Getting access to a Frame from a Handle
Hi, and thanks for this great library!
I am experimenting with Kira and bevy, as well as building a super simple audio player for fun. I think it would be great to access a Frame at a time, for example to have a game entity react to the sound or add visualization to audio. I see that there is get_frame_at_position, but this is not implemented for the Handle. Would this be reasonable to add or am I missing a way to make this work with the current state maybe?
SoundHandles don't have direct access to the Sound they represent. I'm changing Sounds to be a trait in kira v0.6, so you would be able to write a Sound implementor that stores its data in an Arc. v0.6 will also have a StaticSound struct which is essentially what the current Sound struct is, and I may end up storing the frames in an Arc, although I'm not sure if there would be any performance or usability drawbacks to doing so.
Thanks for your answer! This sounds great and I am very excited for 0.6 then!
After re-reading this issue, I thin what you were requesting is a way to see the frame a sound is currently outputting, right, @woelper ?
Thanks, yes, you are correct.
Sorry for derailing this a bit, but would this work with StreamingSounds too?
Yes. While you still can't get the currently playing frame from a handle, you can create an effect that sends the frames (or information about the frames, like the average amplitude) to an effect handle. I may do a write-up on how to implement this (or maybe even add it as a default effect).
you can create an effect that sends the frames (or information about the frames, like the average amplitude) to an effect handle.
I made a demo that does exactly this in my kira wrapper for Bevy.
See: https://github.com/jakerr/bevy_mod_kira/blob/main/examples/effects/level_monitor/mod.rs and it's usage https://github.com/jakerr/bevy_mod_kira/blob/main/examples/level_monitor.rs
I realize it's been a year since the last comment here but thought for posterity's sake I'd share.