kira icon indicating copy to clipboard operation
kira copied to clipboard

Getting access to a Frame from a Handle

Open woelper opened this issue 4 years ago • 6 comments

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?

woelper avatar Oct 18 '21 19:10 woelper

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.

tesselode avatar Oct 19 '21 18:10 tesselode

Thanks for your answer! This sounds great and I am very excited for 0.6 then!

woelper avatar Oct 19 '21 18:10 woelper

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 ?

tesselode avatar Apr 16 '22 14:04 tesselode

Thanks, yes, you are correct.

Sorry for derailing this a bit, but would this work with StreamingSounds too?

woelper avatar Apr 19 '22 11:04 woelper

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).

tesselode avatar Apr 19 '22 12:04 tesselode

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.

jakerr avatar Mar 22 '23 17:03 jakerr