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.11 2006/02/01 09:00:46 csoutheren 00027 * Changes to remove dependencies in Speex code accidentally introduced 00028 * 00029 * Revision 1.10 2006/01/31 10:28:03 csoutheren 00030 * Added detection for variants to speex 1.11.11.1 00031 * 00032 * Revision 1.9 2006/01/31 08:32:34 csoutheren 00033 * Fixed problem with speex includes. Again 00034 * 00035 * Revision 1.8 2006/01/31 03:28:03 csoutheren 00036 * Changed to compile on MSVC 6 00037 * 00038 * Revision 1.7 2006/01/23 23:01:19 dsandras 00039 * Protect internal speex state changes with a mutex. 00040 * 00041 * Revision 1.6 2006/01/07 17:37:50 dsandras 00042 * Updated to speex 1.1.11.2 to fix divergeance issues. 00043 * 00044 * Revision 1.5 2006/01/05 12:02:31 rjongbloed 00045 * Fixed DevStudio compile errors 00046 * 00047 * Revision 1.4 2005/12/29 16:20:53 dsandras 00048 * Added wideband support to the echo canceller. 00049 * 00050 * Revision 1.3 2005/11/25 21:00:38 dsandras 00051 * Remove the DC or the algorithm is puzzled. Added several post-processing filters. Added missing declaration. 00052 * 00053 * Revision 1.2 2005/11/24 20:34:44 dsandras 00054 * Modified copyright. 00055 * 00056 * Revision 1.1 2005/11/24 20:31:54 dsandras 00057 * Added support for echo cancelation using Speex. 00058 * Added possibility to add a filter to an OpalMediaPatch for all patches of a connection. 00059 * 00060 */ 00061 00062 #ifndef __OPAL_ECHOCANCEL_H 00063 #define __OPAL_ECHOCANCEL_H 00064 00065 #ifdef P_USE_PRAGMA 00066 #pragma interface 00067 #endif 00068 00069 #include <rtp/rtp.h> 00070 #include <ptclib/qchannel.h> 00071 00072 #ifndef SPEEX_ECHO_H 00073 struct SpeexEchoState; 00074 #endif 00075 00076 #ifndef SPEEX_PREPROCESS_H 00077 struct SpeexPreprocessState; 00078 #endif 00079 00081 class OpalEchoCanceler : public PObject 00082 { 00083 PCLASSINFO(OpalEchoCanceler, PObject); 00084 public: 00085 enum Mode { 00086 NoCancelation, 00087 Cancelation 00088 }; 00089 00090 struct Params { 00091 Params( 00092 Mode mode = NoCancelation 00093 ) : m_mode (mode) 00094 { } 00095 00096 Mode m_mode; 00097 }; 00098 00103 OpalEchoCanceler(); 00104 ~OpalEchoCanceler(); 00106 00107 00110 const PNotifier & GetReceiveHandler() const { return receiveHandler; } 00111 const PNotifier & GetSendHandler() const {return sendHandler; } 00112 00113 00116 void SetParameters( 00117 const Params & newParam 00118 ); 00119 00120 00123 void SetClockRate( 00124 const int clockRate 00125 ); 00126 00127 protected: 00128 PDECLARE_NOTIFIER(RTP_DataFrame, OpalEchoCanceler, ReceivedPacket); 00129 PDECLARE_NOTIFIER(RTP_DataFrame, OpalEchoCanceler, SentPacket); 00130 00131 PNotifier receiveHandler; 00132 PNotifier sendHandler; 00133 00134 Params param; 00135 00136 private: 00137 00138 double mean; 00139 int clockRate; 00140 PQueueChannel *echo_chan; 00141 PMutex stateMutex; 00142 SpeexEchoState *echoState; 00143 SpeexPreprocessState *preprocessState; 00144 00145 // the following types are all void * to avoid including Speex header files 00146 void * ref_buf; 00147 void * echo_buf; 00148 void * e_buf; 00149 void * noise; 00150 }; 00151 00152 #endif // __OPAL_ECHOCANCEL_H 00153