-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for real time audio streaming #5422
Comments
Turns out this is possible when using |
|
I have several problems with
However, I have been trying to implement |
Assets can be loaded without interacting with the filesystem. (Just call
Try wrapping your
That is pretty inconvenient. However, there's no point in reinventing the wheel when I'll create a PR soon to add those things, but until then, keep working on implementing |
Wrapping the Here are the limitations in audio programming, according to this article:
|
Sorry for the delay! I haven't been able to use my main computer (which is like 20 times faster than the one I'm using right now) for a while, so I couldn't work on implementing that PR. I should have access to it tomorrow, so I can finally work on it then. By the way, here's an interesting idea: What about using |
I don't mind. I've been implementing
The correct thing to use is a single producer single consumer lock-free ring buffer. However, I am currently adding support for This leads to a problem that I am curious on how would |
Have you looked at the |
# Objective - Allow non-`Sync` Decoders - Unblocks #5422. - Unblocks harudagondi/bevy_fundsp#1 ## Solution - Remove `Sync` requirement in `Decodable::Decoder` - This aligns with kira's [`Sound`] and majority of [oddio]'s types (like [`Mixer`]). [`Sound`]: https://docs.rs/kira/latest/kira/sound/trait.Sound.html [oddio]: https://docs.rs/oddio/latest/oddio/index.html [`Mixer`]: https://docs.rs/oddio/latest/oddio/struct.Mixer.html --- ## Changelog ### Changed - `Decodable::Decoder` now no longer requires `Sync` types.
# Objective - Allow non-`Sync` Decoders - Unblocks bevyengine#5422. - Unblocks harudagondi/bevy_fundsp#1 ## Solution - Remove `Sync` requirement in `Decodable::Decoder` - This aligns with kira's [`Sound`] and majority of [oddio]'s types (like [`Mixer`]). [`Sound`]: https://docs.rs/kira/latest/kira/sound/trait.Sound.html [oddio]: https://docs.rs/oddio/latest/oddio/index.html [`Mixer`]: https://docs.rs/oddio/latest/oddio/struct.Mixer.html --- ## Changelog ### Changed - `Decodable::Decoder` now no longer requires `Sync` types.
# Objective - Allow non-`Sync` Decoders - Unblocks bevyengine#5422. - Unblocks harudagondi/bevy_fundsp#1 ## Solution - Remove `Sync` requirement in `Decodable::Decoder` - This aligns with kira's [`Sound`] and majority of [oddio]'s types (like [`Mixer`]). [`Sound`]: https://docs.rs/kira/latest/kira/sound/trait.Sound.html [oddio]: https://docs.rs/oddio/latest/oddio/index.html [`Mixer`]: https://docs.rs/oddio/latest/oddio/struct.Mixer.html --- ## Changelog ### Changed - `Decodable::Decoder` now no longer requires `Sync` types.
Might be useful for someone, I've been update my bevy app to use audio streaming based on Decodable example (previously using an old fork of bevy_kira_audio since the streaming feature was dropped in later version). I am using ringbuffer for communication, which is actually tricky to use in Decodable, so I end up using some unsafe code to bypass the restriction. The usecase is to use fluidlite to produce midi audio, the logic is a bit hacky, esp. around the sample rate (just hard-coded to 44100, and use buffer size to control the timing), but it works fine for now. |
What problem does this solve or what need does it fill?
During the development of my plugin (
bevy_fundsp
, also shameless self promotion lol), I found that bevy_audio (andbevy_kira_audio
, for that matter) is rather limited.To play sounds, one must create an
AudioSource
, which stores the bytes of the sound data, then play it in a system usingRes<Audio>
.This isn't feasible when using DSP (digital signal processing) libraries such as
fundsp
. DSP graphs can be played forever (see example here), so it would be impossible to convert these intoAudioSource
s. A workaround for this is to pass a definite length and convert the graph into wave data bytes, which is then converted to anAudioSource
.This is very hacky, and it does not exploit the full capabilities of DSP libraries, especially
fundsp
.What solution would you like?
I don't know what exact implementation would actually look like, but I would like:
StreamingAudioSource
that holds an iterator whose items is an array of floats (f32 ideally) where its length is the number of channels (usually two for left/right channels).StreamingAudioSource
can only be played (by continuing to iterate), paused (by stopping the iteration), or possibly reset (this is possible withfundsp
specifically).Using this solution would probably need access to
cpal
directly.What alternative(s) have you considered?
Bypass
bevy_audio
and directly usecpal
. This is bad, because audio programming is very hard, and it is better for Bevy to provide its own solution.The text was updated successfully, but these errors were encountered: