fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

Théo Monnomadd AudioProcessingModule (#580)7e51858

livekit/livekit-ffi@0.13.0
1.8 KiB49 linesraw
1#include "livekit/apm.h"
2
3#include <iostream>
4#include <memory>
5
6namespace livekit {
7
8AudioProcessingModule::AudioProcessingModule(
9    const AudioProcessingConfig& config) {
10  apm_ = webrtc::AudioProcessingBuilder().Create();
11
12  apm_->ApplyConfig(config.ToWebrtcConfig());
13  apm_->Initialize();
14}
15
16int AudioProcessingModule::process_stream(const int16_t* src,
17                                          size_t src_len,
18                                          int16_t* dst,
19                                          size_t dst_len,
20                                          int sample_rate,
21                                          int num_channels) {
22  webrtc::StreamConfig stream_cfg(sample_rate, num_channels);
23  return apm_->ProcessStream(src, stream_cfg, stream_cfg, dst);
24}
25
26int AudioProcessingModule::process_reverse_stream(const int16_t* src,
27                                                  size_t src_len,
28                                                  int16_t* dst,
29                                                  size_t dst_len,
30                                                  int sample_rate,
31                                                  int num_channels) {
32  webrtc::StreamConfig stream_cfg(sample_rate, num_channels);
33  return apm_->ProcessReverseStream(src, stream_cfg, stream_cfg, dst);
34}
35
36std::unique_ptr<AudioProcessingModule> create_apm(
37    bool echo_canceller_enabled,
38    bool gain_controller_enabled,
39    bool high_pass_filter_enabled,
40    bool noise_suppression_enabled) {
41  AudioProcessingConfig config;
42  config.echo_canceller_enabled = echo_canceller_enabled;
43  config.gain_controller_enabled = gain_controller_enabled;
44  config.high_pass_filter_enabled = high_pass_filter_enabled;
45  config.noise_suppression_enabled = noise_suppression_enabled;
46  return std::make_unique<AudioProcessingModule>(config);
47}
48
49}  // namespace livekit