BlueGit

ict rusty-teams

Files

rusty-teams / vendor / webrtc-sys / include / livekit / apm.h

apm.h

apm.h 2.7 KiB Download Raw
1/*
2 * Copyright 2025 LiveKit, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
20
21#include "api/scoped_refptr.h"
22#include "api/video_codecs/video_decoder_factory.h"
23#include "api/video_codecs/video_encoder_factory.h"
24#include "modules/audio_processing/aec3/echo_canceller3.h"
25#include "modules/audio_processing/audio_buffer.h"
26
27namespace livekit_ffi {
28
29struct AudioProcessingConfig {
30 bool echo_canceller_enabled;
31 bool gain_controller_enabled;
32 bool high_pass_filter_enabled;
33 bool noise_suppression_enabled;
34
35 webrtc::AudioProcessing::Config ToWebrtcConfig() const {
36 webrtc::AudioProcessing::Config config;
37 config.echo_canceller.enabled = echo_canceller_enabled;
38 config.gain_controller2.enabled = gain_controller_enabled;
39 config.gain_controller2.adaptive_digital.enabled = gain_controller_enabled;
40 // Speech settles near -16 dBFS like Teams instead of AGC2's -22 dBFS; the limiter after the fixed gain keeps peaks below -1 dBFS.
41 config.gain_controller2.adaptive_digital.initial_gain_db = 0.0f;
42 config.gain_controller2.fixed_digital.gain_db = gain_controller_enabled ? 6.0f : 0.0f;
43 config.high_pass_filter.enabled = high_pass_filter_enabled;
44 config.noise_suppression.enabled = noise_suppression_enabled;
45 return config;
46 }
47};
48
49class AudioProcessingModule {
50 public:
51 AudioProcessingModule(const AudioProcessingConfig& config);
52
53 int process_stream(const int16_t* src,
54 size_t src_len,
55 int16_t* dst,
56 size_t dst_len,
57 int sample_rate,
58 int num_channels);
59
60 int process_reverse_stream(const int16_t* src,
61 size_t src_len,
62 int16_t* dst,
63 size_t dst_len,
64 int sample_rate,
65 int num_channels);
66
67 int set_stream_delay_ms(int delay_ms);
68
69 private:
70 webrtc::scoped_refptr<webrtc::AudioProcessing> apm_;
71};
72
73std::unique_ptr<AudioProcessingModule> create_apm(
74 bool echo_canceller_enabled,
75 bool gain_controller_enabled,
76 bool high_pass_filter_enabled,
77 bool noise_suppression_enabled);
78
79} // namespace livekit_ffi