Crates.io | audio-gate |
lib.rs | audio-gate |
version | 0.1.1 |
source | src |
created_at | 2024-01-01 19:51:14.173247 |
updated_at | 2024-01-01 19:53:07.225766 |
description | A Simple Noise Gate |
homepage | |
repository | https://github.com/charlesportwoodii/audio-gate |
max_upload_size | |
id | 1085517 |
size | 47,710 |
A simple Noise Gate algorithm written for Rust for handling of streaming audio from CPAL. Noise Gates are extremely useful for cleaning up muddy audio streams: breathing noises, page turns, microphone knocks, keyboard clatter, HVAC hum, fan noises, room reverb, and so forth to help remove unwanted sounds from your stream. While a noise gate won't completely eliminate background noise, it can help make your audio stream sounds much cleaner.
This crate is intended to be used with raw audio streams from CPAL or the like.
cargo add audio-gate
let mut gate = NoiseGate::new(
-36.0, // Open Threshold
-54.0, // Close Treshold
48000.0, // Sample Rate
2, // Channels
150.0, // Release Rate
25.0, // Attack Rate
150.0 // Hold time
);
let stream = match device.build_input_stream(
&config,
move |data: &[f32], _: &cpal::InputCallbackInfo| {
let gated_data = gate.process_frame(&data);
for &sample in gated_data.as_slice() {
producer.push(sample).unwrap_or({});
}
},
move |err| {},
None
) {
Ok(stream) => stream,
Err(e) => {
return Err(anyhow!("{}", e.to_string()));
}
};
A feedback example is provided in the examples directory so that you can hear the difference a noise gate might apply to your audio stream.
To hear your current input with the noise gate applied run the example:
cargo run --example feedback -- --with-gate
To hear your audio with it not applied run the example without the flag:
cargo run --example feedback
This application is licensed under the BSD 3 Clause License