21#include <webrtc/modules/audio_processing/include/audio_processing.h>
28 return (
size_t) (webrtc::AudioProcessing::kChunkSizeMs * format.
sample_rate / 1000);
36 JAMI_LOG(
"[webrtc-ap] WebRTCAudioProcessor, frame size = {:d} (={:d} ms), channels = {:d}",
40 webrtc::Config config;
41 config.Set<webrtc::ExtendedFilter>(
new webrtc::ExtendedFilter(
true));
42 config.Set<webrtc::DelayAgnostic>(
new webrtc::DelayAgnostic(
true));
44 apm.reset(webrtc::AudioProcessing::Create(config));
47 webrtc::ProcessingConfig
pconfig = {
55 JAMI_ERROR(
"[webrtc-ap] Error initialising audio processing module");
62 JAMI_LOG(
"[webrtc-ap] enableNoiseSuppression {}", enabled);
63 if (apm->noise_suppression()->Enable(enabled) !=
webrtcNoError) {
64 JAMI_ERROR(
"[webrtc-ap] Error enabling noise suppression");
66 if (apm->noise_suppression()->set_level(webrtc::NoiseSuppression::kVeryHigh) !=
webrtcNoError) {
67 JAMI_ERROR(
"[webrtc-ap] Error setting noise suppression level");
69 if (apm->high_pass_filter()->Enable(enabled) !=
webrtcNoError) {
70 JAMI_ERROR(
"[webrtc-ap] Error enabling high pass filter");
77 JAMI_LOG(
"[webrtc-ap] enableAutomaticGainControl {}", enabled);
79 JAMI_ERROR(
"[webrtc-ap] Error enabling automatic gain control");
81 if (apm->gain_control()->set_analog_level_limits(0, 255) !=
webrtcNoError) {
82 JAMI_ERROR(
"[webrtc-ap] Error setting automatic gain control analog level limits");
84 if (apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveAnalog) !=
webrtcNoError) {
85 JAMI_ERROR(
"[webrtc-ap] Error setting automatic gain control mode");
92 JAMI_LOG(
"[webrtc-ap] enableEchoCancel {}", enabled);
94 if (apm->echo_cancellation()->Enable(enabled) !=
webrtcNoError) {
95 JAMI_ERROR(
"[webrtc-ap] Error enabling echo cancellation");
97 if (apm->echo_cancellation()->set_suppression_level(
98 webrtc::EchoCancellation::SuppressionLevel::kHighSuppression)
100 JAMI_ERROR(
"[webrtc-ap] Error setting echo cancellation level");
102 if (apm->echo_cancellation()->enable_drift_compensation(
true) !=
webrtcNoError) {
103 JAMI_ERROR(
"[webrtc-ap] Error enabling echo cancellation drift compensation");
110 JAMI_LOG(
"[webrtc-ap] enableVoiceActivityDetection {}", enabled);
111 if (apm->voice_detection()->Enable(enabled) !=
webrtcNoError) {
112 JAMI_ERROR(
"[webrtc-ap] Error enabling voice activation detection");
114 if (apm->voice_detection()->set_likelihood(webrtc::VoiceDetection::kVeryLowLikelihood)
116 JAMI_ERROR(
"[webrtc-ap] Error setting voice detection likelihood");
119 if (apm->voice_detection()->set_frame_size_ms(10) !=
webrtcNoError) {
120 JAMI_ERROR(
"[webrtc-ap] Error setting voice detection frame size");
124std::shared_ptr<AudioFrame>
135 if (!playback || !
record) {
141 float**
playData = (
float**) playback->pointer()->extended_data;
143 JAMI_ERR(
"[webrtc-ap] ProcessReverseStream failed");
151 JAMI_ERR(
"[webrtc-ap] set_stream_delay_ms failed");
154 if (apm->gain_control()->set_stream_analog_level(analogLevel_) !=
webrtcNoError) {
155 JAMI_ERR(
"[webrtc-ap] set_stream_analog_level failed");
157 apm->echo_cancellation()->set_stream_drift_samples(
driftSamples);
160 float**
recData = (
float**)
record->pointer()->extended_data;
162 JAMI_ERR(
"[webrtc-ap] ProcessStream failed");
165 analogLevel_ = apm->gain_control()->stream_analog_level();
166 record->has_voice = apm->voice_detection()->is_enabled()
int samples() const
Gets the numbers of samples available for reading.
std::shared_ptr< AudioFrame > dequeue()
Notifies owner of a new frame.
unsigned int frameDurationMs_
AudioFrameResizer playbackQueue_
bool tidyQueues()
Helper method for audio processors, should be called at start of getProcessed() Pops frames from audi...
bool getStabilizedVoiceActivity(bool voiceStatus)
Stablilizes voice activity.
AudioFrameResizer recordQueue_
std::shared_ptr< AudioFrame > getProcessed() override
Process and return a single AudioFrame.
void enableEchoCancel(bool enabled) override
Set the status of echo cancellation.
WebRTCAudioProcessor(AudioFormat format, unsigned frameSize)
void enableNoiseSuppression(bool enabled) override
Set the status of noise suppression includes de-reverb, de-noise, high pass filter,...
void enableVoiceActivityDetection(bool enabled) override
Set the status of voice activity detection.
void enableAutomaticGainControl(bool enabled) override
Set the status of automatic gain control.
#define JAMI_ERROR(formatstr,...)
#define JAMI_LOG(formatstr,...)
void emitSignal(Args... args)
constexpr int webrtcNoError
size_t webrtcFrameSize(AudioFormat format)