2017-02-02 17:24:40 +01:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "EchoCanceller.h"
|
|
|
|
#include "audio/AudioOutput.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include <string.h>
|
2017-03-30 16:06:59 +02:00
|
|
|
#include <stdio.h>
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifndef TGVOIP_NO_DSP
|
|
|
|
#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-04-09 18:14:33 +02:00
|
|
|
#include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h"
|
2017-04-17 20:57:07 +02:00
|
|
|
#include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
|
|
|
|
#else
|
|
|
|
#include "webrtc/modules/audio_processing/aec/echo_cancellation.h"
|
|
|
|
//#include "webrtc/modules/audio_processing/ns/noise_suppression.h"
|
|
|
|
#include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
|
|
|
|
#endif
|
2017-04-09 18:14:33 +02:00
|
|
|
#include "webrtc/modules/audio_processing/splitting_filter.h"
|
|
|
|
#include "webrtc/common_audio/channel_buffer.h"
|
|
|
|
#include "webrtc/modules/audio_processing/agc/legacy/gain_control.h"
|
|
|
|
#endif
|
|
|
|
|
2017-02-02 17:24:40 +01:00
|
|
|
#define AEC_FRAME_SIZE 160
|
|
|
|
#define OFFSET_STEP AEC_FRAME_SIZE*2
|
|
|
|
|
|
|
|
//#define CLAMP(x, min, max) (x<max ? (x>min ? x : min) : max)
|
|
|
|
#define CLAMP(x, min, max) x
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
using namespace tgvoip;
|
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifdef TGVOIP_USE_DESKTOP_DSP
|
|
|
|
namespace webrtc{
|
2017-02-02 17:24:40 +01:00
|
|
|
void WebRtcAec_enable_delay_agnostic(AecCore* self, int enable);
|
2017-04-17 20:57:07 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
|
2017-03-30 16:06:59 +02:00
|
|
|
this->enableAEC=enableAEC;
|
|
|
|
this->enableAGC=enableAGC;
|
|
|
|
this->enableNS=enableNS;
|
2017-04-09 18:14:33 +02:00
|
|
|
|
|
|
|
#ifndef TGVOIP_NO_DSP
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-09 18:14:33 +02:00
|
|
|
splittingFilter=new webrtc::SplittingFilter(1, 3, 960);
|
|
|
|
splittingFilterFarend=new webrtc::SplittingFilter(1, 3, 960);
|
|
|
|
|
|
|
|
splittingFilterIn=new webrtc::IFChannelBuffer(960, 1, 1);
|
|
|
|
splittingFilterFarendIn=new webrtc::IFChannelBuffer(960, 1, 1);
|
|
|
|
splittingFilterOut=new webrtc::IFChannelBuffer(960, 1, 3);
|
|
|
|
splittingFilterFarendOut=new webrtc::IFChannelBuffer(960, 1, 3);
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-03-30 16:06:59 +02:00
|
|
|
if(enableAEC){
|
|
|
|
init_mutex(aecMutex);
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-03-30 16:06:59 +02:00
|
|
|
aec=WebRtcAecm_Create();
|
|
|
|
WebRtcAecm_Init(aec, 16000);
|
|
|
|
AecmConfig cfg;
|
|
|
|
cfg.cngMode=AecmFalse;
|
|
|
|
cfg.echoMode=1;
|
|
|
|
WebRtcAecm_set_config(aec, cfg);
|
2017-04-17 20:57:07 +02:00
|
|
|
#else
|
|
|
|
aec=webrtc::WebRtcAec_Create();
|
|
|
|
webrtc::WebRtcAec_Init(aec, 48000, 48000);
|
|
|
|
webrtc::WebRtcAec_enable_delay_agnostic(webrtc::WebRtcAec_aec_core(aec), 1);
|
|
|
|
webrtc::AecConfig config;
|
|
|
|
config.metricsMode=webrtc::kAecFalse;
|
|
|
|
config.nlpMode=webrtc::kAecNlpAggressive;
|
|
|
|
config.skewMode=webrtc::kAecFalse;
|
|
|
|
config.delay_logging=webrtc::kAecFalse;
|
|
|
|
webrtc::WebRtcAec_set_config(aec, config);
|
|
|
|
#endif
|
2017-03-30 16:06:59 +02:00
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
farendQueue=new BlockingQueue(11);
|
|
|
|
farendBufferPool=new BufferPool(960*2, 10);
|
2017-03-30 16:06:59 +02:00
|
|
|
running=true;
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
start_thread(bufferFarendThread, EchoCanceller::StartBufferFarendThread, this);
|
2017-03-30 16:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(enableNS){
|
2017-04-17 20:57:07 +02:00
|
|
|
//#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-03-30 16:06:59 +02:00
|
|
|
ns=WebRtcNsx_Create();
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Init((NsxHandle*)ns, 48000);
|
|
|
|
WebRtcNsx_set_policy((NsxHandle*)ns, 2);
|
2017-04-17 20:57:07 +02:00
|
|
|
/*#else
|
|
|
|
ns=WebRtcNs_Create();
|
|
|
|
WebRtcNs_Init((NsHandle*)ns, 48000);
|
|
|
|
WebRtcNs_set_policy((NsHandle*)ns, 1);
|
|
|
|
#endif*/
|
2017-03-30 16:06:59 +02:00
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-03-30 16:06:59 +02:00
|
|
|
if(enableAGC){
|
|
|
|
agc=WebRtcAgc_Create();
|
|
|
|
WebRtcAgcConfig agcConfig;
|
|
|
|
agcConfig.compressionGaindB = 9;
|
|
|
|
agcConfig.limiterEnable = 1;
|
|
|
|
agcConfig.targetLevelDbfs = 3;
|
|
|
|
WebRtcAgc_Init(agc, 0, 255, kAgcModeAdaptiveAnalog, 48000);
|
|
|
|
WebRtcAgc_set_config(agc, agcConfig);
|
|
|
|
agcMicLevel=128;
|
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-03-30 16:06:59 +02:00
|
|
|
/*state=webrtc::WebRtcAec_Create();
|
|
|
|
webrtc::WebRtcAec_Init(state, 16000, 16000);
|
|
|
|
webrtc::WebRtcAec_enable_delay_agnostic(webrtc::WebRtcAec_aec_core(state), 1);*/
|
2017-04-09 18:14:33 +02:00
|
|
|
#endif
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
EchoCanceller::~EchoCanceller(){
|
2017-03-30 16:06:59 +02:00
|
|
|
if(enableAEC){
|
|
|
|
running=false;
|
|
|
|
farendQueue->Put(NULL);
|
|
|
|
join_thread(bufferFarendThread);
|
|
|
|
delete farendQueue;
|
|
|
|
delete farendBufferPool;
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-03-30 16:06:59 +02:00
|
|
|
WebRtcAecm_Free(aec);
|
2017-04-17 20:57:07 +02:00
|
|
|
#else
|
|
|
|
webrtc::WebRtcAec_Free(aec);
|
|
|
|
#endif
|
2017-03-30 16:06:59 +02:00
|
|
|
}
|
|
|
|
if(enableNS){
|
2017-04-17 20:57:07 +02:00
|
|
|
//#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Free((NsxHandle*)ns);
|
2017-04-17 20:57:07 +02:00
|
|
|
/*#else
|
|
|
|
WebRtcNs_Free((NsHandle*)ns);
|
|
|
|
#endif*/
|
2017-03-30 16:06:59 +02:00
|
|
|
}
|
|
|
|
if(enableAGC){
|
|
|
|
WebRtcAgc_Free(agc);
|
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
//webrtc::WebRtcAec_Free(state);
|
2017-04-09 18:14:33 +02:00
|
|
|
|
|
|
|
delete (webrtc::SplittingFilter*)splittingFilter;
|
|
|
|
delete (webrtc::SplittingFilter*)splittingFilterFarend;
|
|
|
|
|
|
|
|
delete (webrtc::IFChannelBuffer*)splittingFilterIn;
|
|
|
|
delete (webrtc::IFChannelBuffer*)splittingFilterOut;
|
|
|
|
delete (webrtc::IFChannelBuffer*)splittingFilterFarendIn;
|
|
|
|
delete (webrtc::IFChannelBuffer*)splittingFilterFarendOut;
|
|
|
|
|
2017-03-30 16:06:59 +02:00
|
|
|
if (this->enableAEC) {
|
|
|
|
free_mutex(aecMutex);
|
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::Start(){
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::Stop(){
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::SpeakerOutCallback(unsigned char* data, size_t len){
|
2017-03-30 16:06:59 +02:00
|
|
|
if(len!=960*2 || !enableAEC)
|
2017-02-02 17:24:40 +01:00
|
|
|
return;
|
|
|
|
/*size_t offset=0;
|
|
|
|
while(offset<len){
|
|
|
|
WebRtcAecm_BufferFarend(state, (int16_t*)(data+offset), AEC_FRAME_SIZE);
|
|
|
|
offset+=OFFSET_STEP;
|
|
|
|
}*/
|
|
|
|
unsigned char* buf=farendBufferPool->Get();
|
|
|
|
if(buf){
|
|
|
|
memcpy(buf, data, 960*2);
|
|
|
|
farendQueue->Put(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void *EchoCanceller::StartBufferFarendThread(void *arg){
|
|
|
|
((EchoCanceller*)arg)->RunBufferFarendThread();
|
2017-02-02 17:24:40 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::RunBufferFarendThread(){
|
2017-02-02 17:24:40 +01:00
|
|
|
while(running){
|
|
|
|
int16_t* samplesIn=(int16_t *) farendQueue->GetBlocking();
|
|
|
|
if(samplesIn){
|
2017-04-09 18:14:33 +02:00
|
|
|
webrtc::IFChannelBuffer* bufIn=(webrtc::IFChannelBuffer*) splittingFilterFarendIn;
|
|
|
|
webrtc::IFChannelBuffer* bufOut=(webrtc::IFChannelBuffer*) splittingFilterFarendOut;
|
|
|
|
memcpy(bufIn->ibuf()->bands(0)[0], samplesIn, 960*2);
|
2017-02-02 17:24:40 +01:00
|
|
|
farendBufferPool->Reuse((unsigned char *) samplesIn);
|
2017-04-09 18:14:33 +02:00
|
|
|
((webrtc::SplittingFilter*)splittingFilterFarend)->Analysis(bufIn, bufOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
lock_mutex(aecMutex);
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcAecm_BufferFarend(aec, bufOut->ibuf_const()->bands(0)[0], 160);
|
|
|
|
WebRtcAecm_BufferFarend(aec, bufOut->ibuf_const()->bands(0)[0]+160, 160);
|
2017-04-17 20:57:07 +02:00
|
|
|
#else
|
|
|
|
webrtc::WebRtcAec_BufferFarend(aec, bufOut->fbuf_const()->bands(0)[0], 160);
|
|
|
|
webrtc::WebRtcAec_BufferFarend(aec, bufOut->fbuf_const()->bands(0)[0]+160, 160);
|
|
|
|
#endif
|
2017-03-30 16:06:59 +02:00
|
|
|
unlock_mutex(aecMutex);
|
2017-02-02 17:24:40 +01:00
|
|
|
didBufferFarend=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::Enable(bool enabled){
|
2017-03-30 16:06:59 +02:00
|
|
|
//isOn=enabled;
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
void EchoCanceller::ProcessInput(unsigned char* data, unsigned char* out, size_t len){
|
2017-02-02 17:24:40 +01:00
|
|
|
int i;
|
2017-03-30 16:06:59 +02:00
|
|
|
if(!enableAEC && !enableAGC && !enableNS){
|
2017-02-02 17:24:40 +01:00
|
|
|
memcpy(out, data, len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int16_t* samplesIn=(int16_t*)data;
|
|
|
|
int16_t* samplesOut=(int16_t*)out;
|
2017-04-09 18:14:33 +02:00
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
webrtc::IFChannelBuffer* bufIn=(webrtc::IFChannelBuffer*) splittingFilterIn;
|
|
|
|
webrtc::IFChannelBuffer* bufOut=(webrtc::IFChannelBuffer*) splittingFilterOut;
|
2017-04-09 18:14:33 +02:00
|
|
|
|
|
|
|
memcpy(bufIn->ibuf()->bands(0)[0], samplesIn, 960*2);
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-09 18:14:33 +02:00
|
|
|
((webrtc::SplittingFilter*)splittingFilter)->Analysis(bufIn, bufOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
|
|
|
|
if(enableAGC){
|
|
|
|
int16_t _agcOut[3][320];
|
|
|
|
int16_t* agcIn[3];
|
|
|
|
int16_t* agcOut[3];
|
|
|
|
for(i=0;i<3;i++){
|
2017-04-09 18:14:33 +02:00
|
|
|
agcIn[i]=(int16_t*)bufOut->ibuf_const()->bands(0)[i];
|
2017-03-30 16:06:59 +02:00
|
|
|
agcOut[i]=_agcOut[i];
|
|
|
|
}
|
|
|
|
uint8_t saturation;
|
|
|
|
WebRtcAgc_AddMic(agc, agcIn, 3, 160);
|
|
|
|
WebRtcAgc_Process(agc, (const int16_t *const *) agcIn, 3, 160, agcOut, agcMicLevel, &agcMicLevel, 0, &saturation);
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
agcOut[i]+=160;
|
|
|
|
agcIn[i]+=160;
|
|
|
|
}
|
|
|
|
WebRtcAgc_AddMic(agc, agcIn, 3, 160);
|
|
|
|
WebRtcAgc_Process(agc, (const int16_t *const *) agcIn, 3, 160, agcOut, agcMicLevel, &agcMicLevel, 0, &saturation);
|
|
|
|
//LOGV("AGC mic level %d", agcMicLevel);
|
2017-04-09 18:14:33 +02:00
|
|
|
memcpy(bufOut->ibuf()->bands(0)[0], _agcOut[0], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[1], _agcOut[1], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[2], _agcOut[2], 320*2);
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
2017-03-30 16:06:59 +02:00
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
#ifndef TGVOIP_USE_DESKTOP_DSP
|
2017-03-30 16:06:59 +02:00
|
|
|
if(enableAEC && enableNS){
|
|
|
|
int16_t _nsOut[3][320];
|
|
|
|
int16_t* nsIn[3];
|
|
|
|
int16_t* nsOut[3];
|
|
|
|
for(i=0;i<3;i++){
|
2017-04-09 18:14:33 +02:00
|
|
|
nsIn[i]=(int16_t*)bufOut->ibuf_const()->bands(0)[i];
|
2017-03-30 16:06:59 +02:00
|
|
|
nsOut[i]=_nsOut[i];
|
|
|
|
}
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *) nsIn, 3, nsOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsOut[i]+=160;
|
|
|
|
nsIn[i]+=160;
|
|
|
|
}
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *) nsIn, 3, nsOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
|
2017-04-09 18:14:33 +02:00
|
|
|
memcpy(bufOut->ibuf()->bands(0)[1], _nsOut[1], 320*2*2);
|
2017-03-30 16:06:59 +02:00
|
|
|
|
|
|
|
lock_mutex(aecMutex);
|
2017-04-28 13:17:56 +02:00
|
|
|
WebRtcAecm_Process(aec, bufOut->ibuf()->bands(0)[0], _nsOut[0], samplesOut, AEC_FRAME_SIZE, (int16_t) tgvoip::audio::AudioOutput::GetEstimatedDelay());
|
|
|
|
WebRtcAecm_Process(aec, bufOut->ibuf()->bands(0)[0]+160, _nsOut[0]+160, samplesOut+160, AEC_FRAME_SIZE, (int16_t) tgvoip::audio::AudioOutput::GetEstimatedDelay());
|
2017-03-30 16:06:59 +02:00
|
|
|
unlock_mutex(aecMutex);
|
2017-04-09 18:14:33 +02:00
|
|
|
memcpy(bufOut->ibuf()->bands(0)[0], samplesOut, 320*2);
|
2017-03-30 16:06:59 +02:00
|
|
|
}else if(enableAEC){
|
|
|
|
lock_mutex(aecMutex);
|
2017-04-28 13:17:56 +02:00
|
|
|
WebRtcAecm_Process(aec, bufOut->ibuf()->bands(0)[0], NULL, samplesOut, AEC_FRAME_SIZE, (int16_t) tgvoip::audio::AudioOutput::GetEstimatedDelay());
|
|
|
|
WebRtcAecm_Process(aec, bufOut->ibuf()->bands(0)[0]+160, NULL, samplesOut+160, AEC_FRAME_SIZE, (int16_t) tgvoip::audio::AudioOutput::GetEstimatedDelay());
|
2017-03-30 16:06:59 +02:00
|
|
|
unlock_mutex(aecMutex);
|
2017-04-09 18:14:33 +02:00
|
|
|
memcpy(bufOut->ibuf()->bands(0)[0], samplesOut, 320*2);
|
2017-03-30 16:06:59 +02:00
|
|
|
}else if(enableNS){
|
|
|
|
int16_t _nsOut[3][320];
|
|
|
|
int16_t* nsIn[3];
|
|
|
|
int16_t* nsOut[3];
|
|
|
|
for(i=0;i<3;i++){
|
2017-04-09 18:14:33 +02:00
|
|
|
nsIn[i]=(int16_t*)bufOut->ibuf_const()->bands(0)[i];
|
2017-03-30 16:06:59 +02:00
|
|
|
nsOut[i]=_nsOut[i];
|
|
|
|
}
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *) nsIn, 3, nsOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsOut[i]+=160;
|
|
|
|
nsIn[i]+=160;
|
|
|
|
}
|
2017-04-09 18:14:33 +02:00
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *) nsIn, 3, nsOut);
|
2017-03-30 16:06:59 +02:00
|
|
|
|
2017-04-09 18:14:33 +02:00
|
|
|
memcpy(bufOut->ibuf()->bands(0)[0], _nsOut[0], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[1], _nsOut[1], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[2], _nsOut[2], 320*2);
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
2017-04-17 20:57:07 +02:00
|
|
|
#else
|
|
|
|
/*if(enableNS){
|
|
|
|
float _nsOut[3][320];
|
|
|
|
const float* nsIn[3];
|
|
|
|
float* nsOut[3];
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsIn[i]=bufOut->fbuf_const()->bands(0)[i];
|
|
|
|
nsOut[i]=_nsOut[i];
|
|
|
|
}
|
|
|
|
WebRtcNs_Process((NsHandle*)ns, nsIn, 3, nsOut);
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsOut[i]+=160;
|
|
|
|
nsIn[i]+=160;
|
|
|
|
}
|
|
|
|
WebRtcNs_Process((NsHandle*)ns, nsIn, 3, nsOut);
|
|
|
|
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[0], _nsOut[0], 320*4);
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[1], _nsOut[1], 320*4);
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[2], _nsOut[2], 320*4);
|
|
|
|
}*/
|
|
|
|
if(enableNS){
|
|
|
|
int16_t _nsOut[3][320];
|
|
|
|
int16_t* nsIn[3];
|
|
|
|
int16_t* nsOut[3];
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsIn[i]=(int16_t*)bufOut->ibuf_const()->bands(0)[i];
|
|
|
|
nsOut[i]=_nsOut[i];
|
|
|
|
}
|
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *)nsIn, 3, nsOut);
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
nsOut[i]+=160;
|
|
|
|
nsIn[i]+=160;
|
|
|
|
}
|
|
|
|
WebRtcNsx_Process((NsxHandle*)ns, (const short *const *)nsIn, 3, nsOut);
|
|
|
|
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[0], _nsOut[0], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[1], _nsOut[1], 320*2);
|
|
|
|
memcpy(bufOut->ibuf()->bands(0)[2], _nsOut[2], 320*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(enableAEC){
|
|
|
|
const float* aecIn[3];
|
|
|
|
float* aecOut[3];
|
|
|
|
float _aecOut[3][320];
|
|
|
|
for(i=0;i<3;i++){
|
|
|
|
aecIn[i]=bufOut->fbuf_const()->bands(0)[i];
|
|
|
|
aecOut[i]=_aecOut[i];
|
|
|
|
}
|
2017-04-28 13:17:56 +02:00
|
|
|
webrtc::WebRtcAec_Process(aec, aecIn, 3, aecOut, AEC_FRAME_SIZE, audio::AudioOutput::GetEstimatedDelay(), 0);
|
2017-04-17 20:57:07 +02:00
|
|
|
for(i=0;i<3;i++){
|
|
|
|
aecOut[i]+=160;
|
|
|
|
aecIn[i]+=160;
|
|
|
|
}
|
2017-04-28 13:17:56 +02:00
|
|
|
webrtc::WebRtcAec_Process(aec, aecIn, 3, aecOut, AEC_FRAME_SIZE, audio::AudioOutput::GetEstimatedDelay(), 0);
|
2017-04-17 20:57:07 +02:00
|
|
|
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[0], _aecOut[0], 320*4);
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[1], _aecOut[1], 320*4);
|
|
|
|
memcpy(bufOut->fbuf()->bands(0)[2], _aecOut[2], 320*4);
|
|
|
|
}
|
|
|
|
#endif
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-09 18:14:33 +02:00
|
|
|
((webrtc::SplittingFilter*)splittingFilter)->Synthesis(bufOut, bufIn);
|
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
memcpy(samplesOut, bufIn->ibuf_const()->bands(0)[0], 960*2);
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|