-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathapm.cpp
More file actions
70 lines (59 loc) · 2.51 KB
/
apm.cpp
File metadata and controls
70 lines (59 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "livekit/apm.h"
#include <iostream>
#include <memory>
namespace livekit {
AudioProcessingModule::AudioProcessingModule(
const AudioProcessingConfig& config) {
apm_ = webrtc::AudioProcessingBuilder().Create();
apm_->ApplyConfig(config.ToWebrtcConfig());
apm_->Initialize();
}
int AudioProcessingModule::process_stream(const int16_t* src,
size_t src_len,
int16_t* dst,
size_t dst_len,
int sample_rate,
int num_channels) {
webrtc::StreamConfig stream_cfg(sample_rate, num_channels);
return apm_->ProcessStream(src, stream_cfg, stream_cfg, dst);
}
int AudioProcessingModule::process_reverse_stream(const int16_t* src,
size_t src_len,
int16_t* dst,
size_t dst_len,
int sample_rate,
int num_channels) {
webrtc::StreamConfig stream_cfg(sample_rate, num_channels);
return apm_->ProcessReverseStream(src, stream_cfg, stream_cfg, dst);
}
int AudioProcessingModule::set_stream_delay_ms(int delay_ms) {
return apm_->set_stream_delay_ms(delay_ms);
}
std::unique_ptr<AudioProcessingModule> create_apm(
bool echo_canceller_enabled,
bool gain_controller_enabled,
bool high_pass_filter_enabled,
bool noise_suppression_enabled) {
AudioProcessingConfig config;
config.echo_canceller_enabled = echo_canceller_enabled;
config.gain_controller_enabled = gain_controller_enabled;
config.high_pass_filter_enabled = high_pass_filter_enabled;
config.noise_suppression_enabled = noise_suppression_enabled;
return std::make_unique<AudioProcessingModule>(config);
}
bool AudioProcessingModule::create_and_attach_aec_dump(rust::Str file_name,
int64_t max_log_size_bytes) {
if (!aec_dump_queue_) {
aec_dump_queue_ = GetGlobalTaskQueueFactory()->CreateTaskQueue(
"aec-dump", webrtc::TaskQueueFactory::Priority::LOW);
}
return apm_->CreateAndAttachAecDump(
absl::string_view(file_name.data(), file_name.size()),
max_log_size_bytes,
aec_dump_queue_.get());
}
void AudioProcessingModule::detach_aec_dump() {
apm_->DetachAecDump();
aec_dump_queue_.reset();
}
} // namespace livekit