-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Audio Filters and Digital Signal Processors #5833
Comments
Hi @harudagondi, I'm interested in this issue and harudagondi/bevy_oddio#31 and have some questions. What is the reasoning behind having Based on what you said, I imagined an API that looks something like impl AudioFilter for AmplifyFilter {
fn filter(&self, sample: &Sample) -> Sample {
--snip--
}
}
impl AudioFilter for DistortionFilter {
fn filter(&self, sample: &Sample) -> Sample {
--snip--
}
}
fn setup(audio: ResMut<Audio>, ...) {
let amplify = AmplifyFilter::new();
let distort = DistortionFilter::new();
audio.insert_filter("Amplify", amplify);
audio.insert_filter("Distort", distort);
--snip--
audio.play(music);
}
fn toggle_filter_system(audio: ResMut<Audio>, ...) {
--snip--
if (toggle_distortion) {
audio.toggle_filter("Distort");
/*
.enable_filter(...);
.disable_filter(...);
.remove_filter(...);
*/
}
} How does this design look? And, did you have any idea as to how the user should define If there's anything else I should now about this issue, lmk! |
This is honestly just arbitrary. Kira's I agree with the toggle system, but for the setup, I imagine a node based system with one input and output. This allows for more flexibility (See fundsp's
I'm not sure I understand. Can you elaborate further on this? |
Also, if you'd like for us to informally discuss this, you could say hi at the #audio-dev channel at the bevy discord 😄 |
This is awesome and something like this for DSP and filtering would be awesome! |
By the way, there are talks in bevy development that there would be a possibility to have a We could also adopt how shaders work in rendering, however I have no experience in that field. |
just want to let you know, there is https://github.com/WeirdConstructor/synfx-dsp-jit a dsp crate that is using cranelift to jit compile an ast for efficiency. |
also want to throw a couple of pennies here:
|
This is nice, however this is licensed as |
Yeah I agree with this.
Yeah this is also one of the things we would like to have. A related issue is #5828, of which we could apply to this one. |
yep, I've paid attention to that too. I did not meant we could use it but rather teach from it. |
Some thoughts based on what I know about signal processing, DSP and real-time audio filtering:
We can take existing audio buffer implementations (the As for the general direction of getting audio processing into bevy: pub trait AudioNode {
fn process(&mut self, context: &AudioContext, data: &mut AudioBuffer) -> ProcessStatus;
}
pub struct AudioBuffer {
data: Vec<f32>,
/// Buffer length in samples, number of channels can be inferred as `data.len() / length`
length: usize,
}
pub struct AudioContext {
buffer_start_samplecount: u64,
samplerate: f32,
}
pub enum ProcessStatus {
Failed,
KeepAlive,
Tail(u64 /* number of samples after which the audio tail of the process drops below noise floor */),
}
That's all that came across my head, as my 2cc on this discussion. |
@SolarLiner have you checked out |
What problem does this solve or what need does it fill?
Imagine you are in a water level, but still above ground. The music plays normally.
Then you go underwater, thus the music becomes all muddied up.
Next, you jump out of the water, and the music returns to normal.
How do you implement that in Bevy?
What solution would you like?
An
AudioFilter
trait, with a single methodfilter(&mut self, input: &[Sample], output: &mut [Sample])
, whereSample
is simply a type that implementsrodio::Sample
.Boxed audio filters are stored in
Audio
, in order, and each can be toggled programmatically. These effects are global (unless #5832 is implemented, then it is local to eachAudioListener
).What alternative(s) have you considered?
Implement an audio filter using
Decodable
and pass the audio source to it. Similar to iterator combinators or fundsp's audio units combinators. Very unergonomic when manually implemented.Additional context
N/A
The text was updated successfully, but these errors were encountered: