00001 /* 00002 * echocancel.h 00003 * 00004 * Open Phone Abstraction Library (OPAL) 00005 * Formally known as the Open H323 project. 00006 * 00007 * Copyright (c) 2004 Post Increment 00008 * 00009 * The contents of this file are subject to the Mozilla Public License 00010 * Version 1.0 (the "License"); you may not use this file except in 00011 * compliance with the License. You may obtain a copy of the License at 00012 * http://www.mozilla.org/MPL/ 00013 * 00014 * Software distributed under the License is distributed on an "AS IS" 00015 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00016 * the License for the specific language governing rights and limitations 00017 * under the License. 00018 * 00019 * The Original Code is Open Phone Abstraction Library. 00020 * 00021 * The author of this code is Damien Sandras 00022 * 00023 * Contributor(s): Miguel Rodriguez Perez 00024 * 00025 * $Log: echocancel.h,v $ 00026 * Revision 1.6.2.5 2006/02/01 05:31:22 csoutheren 00027 * Fixed more speex compile problems 00028 * 00029 * Revision 1.6.2.4 2006/01/31 11:00:17 csoutheren 00030 * Backported handling for variants of Speex 1.1.11.1 00031 * 00032 * Revision 1.6.2.3 2006/01/31 08:59:09 csoutheren 00033 * More backports 00034 * 00035 * Revision 1.6.2.2 2006/01/31 08:58:14 csoutheren 00036 * More backports 00037 * 00038 * Revision 1.6.2.1 2006/01/27 05:07:11 csoutheren 00039 * Backports from CVS head 00040 * 00041 * Revision 1.10 2006/01/31 10:28:03 csoutheren 00042 * Added detection for variants to speex 1.11.11.1 00043 * 00044 * Revision 1.9 2006/01/31 08:32:34 csoutheren 00045 * Fixed problem with speex includes. Again 00046 * 00047 * Revision 1.8 2006/01/31 03:28:03 csoutheren 00048 * Changed to compile on MSVC 6 00049 * 00050 * Revision 1.7 2006/01/23 23:01:19 dsandras 00051 * Protect internal speex state changes with a mutex. 00052 * 00053 * Revision 1.6 2006/01/07 17:37:50 dsandras 00054 * Updated to speex 1.1.11.2 to fix divergeance issues. 00055 * 00056 * Revision 1.5 2006/01/05 12:02:31 rjongbloed 00057 * Fixed DevStudio compile errors 00058 * 00059 * Revision 1.4 2005/12/29 16:20:53 dsandras 00060 * Added wideband support to the echo canceller. 00061 * 00062 * Revision 1.3 2005/11/25 21:00:38 dsandras 00063 * Remove the DC or the algorithm is puzzled. Added several post-processing filters. Added missing declaration. 00064 * 00065 * Revision 1.2 2005/11/24 20:34:44 dsandras 00066 * Modified copyright. 00067 * 00068 * Revision 1.1 2005/11/24 20:31:54 dsandras 00069 * Added support for echo cancelation using Speex. 00070 * Added possibility to add a filter to an OpalMediaPatch for all patches of a connection. 00071 * 00072 */ 00073 00074 #ifndef __OPAL_ECHOCANCEL_H 00075 #define __OPAL_ECHOCANCEL_H 00076 00077 #ifdef P_USE_PRAGMA 00078 #pragma interface 00079 #endif 00080 00081 #include <rtp/rtp.h> 00082 #include <ptclib/qchannel.h> 00083 00084 #ifndef SPEEX_ECHO_H 00085 struct SpeexEchoState; 00086 #endif 00087 00088 #ifndef SPEEX_PREPROCESS_H 00089 struct SpeexPreprocessState; 00090 #endif 00091 00092 00094 class OpalEchoCanceler : public PObject 00095 { 00096 PCLASSINFO(OpalEchoCanceler, PObject); 00097 public: 00098 enum Mode { 00099 NoCancelation, 00100 Cancelation 00101 }; 00102 00103 struct Params { 00104 Params( 00105 Mode mode = NoCancelation 00106 ) : m_mode (mode) 00107 { } 00108 00109 Mode m_mode; 00110 }; 00111 00116 OpalEchoCanceler(); 00117 ~OpalEchoCanceler(); 00119 00120 00123 const PNotifier & GetReceiveHandler() const { return receiveHandler; } 00124 const PNotifier & GetSendHandler() const {return sendHandler; } 00125 00126 00129 void SetParameters( 00130 const Params & newParam 00131 ); 00132 00133 00136 void SetClockRate( 00137 const int clockRate 00138 ); 00139 00140 protected: 00141 PDECLARE_NOTIFIER(RTP_DataFrame, OpalEchoCanceler, ReceivedPacket); 00142 PDECLARE_NOTIFIER(RTP_DataFrame, OpalEchoCanceler, SentPacket); 00143 00144 PNotifier receiveHandler; 00145 PNotifier sendHandler; 00146 00147 Params param; 00148 00149 private: 00150 00151 double mean; 00152 int clockRate; 00153 PQueueChannel *echo_chan; 00154 PMutex stateMutex; 00155 SpeexEchoState *echoState; 00156 SpeexPreprocessState *preprocessState; 00157 00158 // the following types are all void * to avoid including Speex header files 00159 void * ref_buf; 00160 void * echo_buf; 00161 void * e_buf; 00162 void * noise; 00163 }; 00164 00165 #endif // __OPAL_ECHOCANCEL_H 00166