资源简介
回音消除,经典的源码,国外很多著名的voip程序都是用这个的
代码片段和文件信息
/***************************************************************
A.2 aec.cxx
***************************************************************/
/* aec.cxx
* Acoustic Echo Cancellation NLMS-pw algorithm
* Author: Andre Adrian DFS Deutsche Flugsicherung
*
*
* Version 1.1
* Copyright (C) DFS Deutsche Flugsicherung (2004). All Rights Reserved.
* (C) Mbdsys SARL (2004).
*
* You are allowed to use this source code in any open source or closed source
* software you want. You are allowed to use the algorithms for a hardware
* solution. You are allowed to modify the source code.
* You are not allowed to remove the name of the author from this memo or from
* the source code files. You are not allowed to monopolize the source code or
* the algorithms behind the source code as your intellectual property.
* This source code is free of royalty and comes with no warranty.
*/
#include
#include
# ifdef WIN32
# define _USE_MATH_DEFINES
# include
# define roundf(x) floorf((x) + 0.5f)
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif /* !M_PI */
# else /* !WIN32 */
# include
# endif /* !WIN32 */
#include
#include “aec.h“
IIR_HP6::IIR_HP6()
{
memset(this 0 sizeof(IIR_HP6));
}
/* Vector Dot Product */
float dotp(float a[] float b[]) {
float sum0 = 0.0 sum1 = 0.0;
int j;
for (j = 0; j < NLMS_LEN; j+= 2) {
// optimize: partial loop unrolling
sum0 += a[j] * b[j];
sum1 += a[j+1] * b[j+1];
}
return sum0+sum1;
}
/*
* Algorithm: Recursive single pole FIR high-pass filter
*
* Reference: The Scientist and Engineer‘s Guide to Digital Processing
*/
FIR1::FIR1()
{
}
void FIR1::init(float preWhiteTransferAlpha)
{
float x = exp(-2.0 * M_PI * preWhiteTransferAlpha);
a0 = (1.0f + x) / 2.0f;
a1 = -(1.0f + x) / 2.0f;
b1 = x;
last_in = 0.0f;
last_out = 0.0f;
}
AEC::AEC()
{
hp1.init(0.01f); /* 10Hz */
Fx.init(PreWhiteAlphaTF);
Fe.init(PreWhiteAlphaTF);
max_max_x = 0.0f;
hangover = 0;
memset(max_x 0 sizeof(max_x));
dtdCnt = dtdNdx = 0;
memset(x 0 sizeof(x));
memset(xf 0 sizeof(xf));
memset(w 0 sizeof(w));
j = NLMS_EXT;
lastupdate = 0;
dotp_xf_xf = 0.0f;
}
float AEC::nlms_pw(float mic float spk int update)
{
float d = mic; // desired signal
x[j] = spk;
xf[j] = Fx.highpass(spk); // pre-whitening of x
// calculate error value (mic signal - estimated mic signal from spk signal)
float e = d - dotp(w x + j);
float ef = Fe.highpass(e); // pre-whitening of e
if (update) {
if
评论
共有 条评论