The so-called acoustic echo cancellation is to solve the problem of VoIP (Internet telephony), that is, A and B calls, a-side microphone and speakers are used to collect a sound and play B sound, B-side microphone and speakers are used to collect the sound of B and play a sound, it is obvious, due to the characteristics of sound propagation , a end of the microphone in the acquisition of a sound, but also collected a-side speaker from the sound from B, that is, a-end of the sound is a mixed sound, the sound is sent to B through the network, B can not only hear a voice, but also can hear a few seconds before B's own voice, This is the B-end to hear B's own echoes, the same can be heard on the A-side echo, which is obviously not what we want.
Acoustic echo cancellation can be implemented by hardware and software, at present, the hardware implementation is relatively simple, the software implementation is difficult, the difficulty here is not to say that the echo cancellation algorithm is difficult, but in the application of the algorithm when the real-time synchronization problem is difficult, the current software to achieve better should be Microsoft, but it seems to have hardware configuration and operating system requirements Speex provides an acoustic echo cancellation algorithm library, this article simply uses the Speex to echo the sound of a recording, of course, this is not real-time processing.
The Speex Echo cancellation API is encapsulated in the speech processing API, which encapsulates the speech processing-related APIs into LIBSPEEXDSP in the latest version of Speex.
The application of the Speex Echo cancellation API process is simple: contains the relevant header file-Create an echo canceller state-echo cancellation per frame-destroys the Echo Canceller state. Generally can be used with the preprocessor in the Speex, has achieved good sound effect, the application of the preprocessor API process is also very simple: including the relevant header file-create preprocessor state-preprocessing per frame-destroy the preprocessor state. Of course you can set the preprocessor state, where we use the default settings. You can see that the two processes are the same, and thus write a cspeexec class, an open source echo canceller that makes a slight modification to the two function calls. In the original, see http://www.360doc.com/content/11/1008/18/11192_154383516.shtml, The Speex version used in the original is 1.1.9, and we are using SPEEX-1.2BETA3-WIN32, which performs preprocessing and echo cancellation functions that are updated.
1, SpeexEC.h
1
2
3
4
5
6
7
8
9
Ten
-
16 All in all, as
of
31 |
#ifndef speex_ec_h #define SPEEX_EC_H #include <stdio.h> #include <stdlib.h>/* Set VC + + in Project properties The catalog contains directories and library directories for include and Lib in the Speex library, and I use speex-1.2beta3-win32*/#include <speex/speex_echo.h> #include < Speex/speex_preprocess.h> class Cspeexec {public:cspeexec (); ~ cspeexec (); void Init (int frame_size = n, int f Ilter_length = 1280x720, int sampling_rate = 8000); void DOAEC (Short * mic, short * ref, short * out); Protected:void Reset (); Private:bool M_bhasinit; Speexechostate * m_pstate; Speexpreprocessstate * m_ppreprocessorstate; int m_nframesize; int M_nfilterlen; int m_nsamplerate; spx_int32_t * m_pfnoise; }; #endif |
code slices from codesSpeexEC.h
2, SpeexEC.cpp
1
2
3
4
5
6
7
8
9
30 of each of the above. The all-in-a
-
------
57 All-in-a
-
The
77 |
#include "stdafx.h" #include "SpeexEC.h" Cspeexec:: Cspeexec () {m_bhasinit = false; m_pstate = NULL; m_pprepr Ocessorstate = NULL; M_nframesize = 160; M_nfilterlen = 160 * 8; M_nsamplerate = 8000; M_pfnoise = NULL; } cspeexec:: ~ cspeexec () {Reset ()} void Cspeexec:: Init (int frame_size, int filter_length, int sampling_rate) {Reset (); if (frame_size <= 0 | | filter_length <= 0 | | sampling_rate <= 0) {m_nframesize =; M_nfilterle n = 160 * 8; M_nsamplerate = 8000; } else {m_nframesize = frame_size; m_nfilterlen = filter_length; m_nsamplerate = sampling_rate; |