RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.68k stars 217 forks source link

Access `Source` from `Sink` #593

Closed vyfor closed 3 days ago

vyfor commented 2 weeks ago

Hello, I have a question regarding accessing the underlying source of a sink, in my case, I'm using a Decoder. It appears that some functions implemented in Source, such as total_duration(), are not available in Sink (assuming that it's possible to query the currently playing source). I was also wondering if it's possible to modify the source in real-time, for instance, by applying filters? If not, one potential solution I considered is to reconstruct the source and seek it back to the previous position. Though, I am curious if there might be a more efficient approach.

dvdsk commented 2 weeks ago

such as total_duration(), are not available in Sink

correct, I speculate because a sink can have multiple sources in it and it would be unclear what total_duration() should return. That can easily be solved but no one has had the time or need I think. You can easily adress it by checking total_duration before you push something into a Sink.

I was also wondering if it's possible to modify the source in real-time, for instance, by applying filters?

You can certainly build something that does that using rodio. It would be a bit of work. Take a look at the Source trait. Anything implementing Source can be played by a sink. The object implementing Source is free to do whatever it wants in its implementation as long as it can give the Sink a sample when it asks for one.

You can set up some communication to your Source implementing object to control what it does from outside the Sink.

Have you however taken a look at https://crates.io/crates/kira? Its a bit less extensible then rodio but has real time modification of the filters/effects applied to a source as a main goal.

dvdsk commented 2 weeks ago

oh and take a look at periodic_access for an example of how its used open the source for Sink.