Skip to content

Commit 330f6fe

Browse files
committed
Upgrade webrtc-audio-processing lib to v1.0
1 parent 6b184d6 commit 330f6fe

14 files changed

+698
-930
lines changed

.gitmodules

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "webrtc-audio-processing-sys/webrtc-audio-processing"]
22
path = webrtc-audio-processing-sys/webrtc-audio-processing
3-
url = https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing.git
3+
url = https://gitlab.freedesktop.org/skywhale/webrtc-audio-processing.git
4+
[submodule "webrtc-audio-processing-sys/abseil-cpp"]
5+
path = webrtc-audio-processing-sys/abseil-cpp
6+
url = https://github.com/abseil/abseil-cpp

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bundled = ["webrtc-audio-processing-sys/bundled"]
2020

2121
[dependencies]
2222
serde = { version = "1", features = ["derive"], optional = true }
23-
webrtc-audio-processing-sys = { path = "webrtc-audio-processing-sys", version = "0.3.2" }
23+
webrtc-audio-processing-sys = { path = "webrtc-audio-processing-sys", version = "0.4.0" }
2424

2525
[dev-dependencies]
2626
portaudio = "0.7"

examples/karaoke.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,17 @@ const SAMPLE_RATE: f64 = 48_000.0;
2121
const FRAMES_PER_BUFFER: u32 = 480;
2222

2323
fn create_processor(
24-
num_capture_channels: i32,
25-
num_render_channels: i32,
24+
num_capture_channels: usize,
25+
num_render_channels: usize,
2626
) -> Result<Processor, Error> {
2727
let mut processor = Processor::new(&InitializationConfig {
2828
num_capture_channels,
2929
num_render_channels,
30-
..InitializationConfig::default()
30+
sample_rate_hz: SAMPLE_RATE as u32,
3131
})?;
3232

33-
// High pass filter is a prerequisite to running echo cancellation.
34-
let config = Config {
35-
echo_cancellation: Some(EchoCancellation {
36-
suppression_level: EchoCancellationSuppressionLevel::Low,
37-
stream_delay_ms: Some(0),
38-
enable_delay_agnostic: false,
39-
enable_extended_filter: false,
40-
}),
41-
enable_high_pass_filter: true,
42-
..Config::default()
43-
};
33+
// The default AEC configuration enables HPF, too.
34+
let config = Config { echo_canceller: Some(EchoCanceller::default()), ..Config::default() };
4435
processor.set_config(config);
4536

4637
Ok(processor)
@@ -74,8 +65,8 @@ fn main() -> Result<(), Error> {
7465
let pa = portaudio::PortAudio::new()?;
7566

7667
let stream_settings = pa.default_duplex_stream_settings(
77-
input_channels,
78-
output_channels,
68+
input_channels as i32,
69+
output_channels as i32,
7970
SAMPLE_RATE,
8071
FRAMES_PER_BUFFER,
8172
)?;

examples/simple.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,17 @@ fn main() {
44
let config = InitializationConfig {
55
num_capture_channels: 2, // Stereo mic input
66
num_render_channels: 2, // Stereo speaker output
7-
..InitializationConfig::default()
7+
sample_rate_hz: 48_000, // The maximum processing rate
88
};
99

1010
let mut ap = Processor::new(&config).unwrap();
1111

12-
let config = Config {
13-
echo_cancellation: Some(EchoCancellation {
14-
suppression_level: EchoCancellationSuppressionLevel::High,
15-
enable_delay_agnostic: false,
16-
enable_extended_filter: false,
17-
stream_delay_ms: None,
18-
}),
19-
..Config::default()
20-
};
12+
let config = Config { echo_canceller: Some(EchoCanceller::default()), ..Default::default() };
2113
ap.set_config(config);
2214

2315
// The render_frame is what is sent to the speakers, and
2416
// capture_frame is audio captured from a microphone.
25-
let (render_frame, capture_frame) = sample_stereo_frames();
17+
let (render_frame, capture_frame) = sample_stereo_frames(&ap);
2618

2719
let mut render_frame_output = render_frame.clone();
2820
ap.process_render_frame(&mut render_frame_output).unwrap();
@@ -43,8 +35,8 @@ fn main() {
4335

4436
/// Generate example stereo frames that simulates a situation where the
4537
/// microphone (capture) would be picking up the speaker (render) output.
46-
fn sample_stereo_frames() -> (Vec<f32>, Vec<f32>) {
47-
let num_samples_per_frame = NUM_SAMPLES_PER_FRAME as usize;
38+
fn sample_stereo_frames(processor: &Processor) -> (Vec<f32>, Vec<f32>) {
39+
let num_samples_per_frame = processor.num_samples_per_frame();
4840

4941
let mut render_frame = Vec::with_capacity(num_samples_per_frame * 2);
5042
let mut capture_frame = Vec::with_capacity(num_samples_per_frame * 2);

0 commit comments

Comments
 (0)