OPAL Version 3.10.2
|
00001 /* 00002 * silencedetect.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 Initial Developer of the Original Code is Equivalence Pty. Ltd. 00022 * 00023 * Contributor(s): ______________________________________. 00024 * 00025 * $Revision: 24320 $ 00026 * $Author: csoutheren $ 00027 * $Date: 2010-05-06 10:20:51 -0500 (Thu, 06 May 2010) $ 00028 */ 00029 00030 #ifndef OPAL_CODEC_SILENCEDETECT_H 00031 #define OPAL_CODEC_SILENCEDETECT_H 00032 00033 #ifdef P_USE_PRAGMA 00034 #pragma interface 00035 #endif 00036 00037 #include <opal/buildopts.h> 00038 #include <rtp/rtp.h> 00039 00040 00042 00043 class OpalSilenceDetector : public PObject 00044 { 00045 PCLASSINFO(OpalSilenceDetector, PObject); 00046 public: 00047 enum Mode { 00048 NoSilenceDetection, 00049 FixedSilenceDetection, 00050 AdaptiveSilenceDetection, 00051 NumModes 00052 }; 00053 00054 struct Params { 00055 Params( 00056 Mode mode = AdaptiveSilenceDetection, 00057 unsigned threshold = 0, 00058 unsigned signalDeadband = 10, 00059 unsigned silenceDeadband = 400, 00060 unsigned adaptivePeriod = 600 00061 ) 00062 : m_mode(mode), 00063 m_threshold(threshold), 00064 m_signalDeadband(signalDeadband), 00065 m_silenceDeadband(silenceDeadband), 00066 m_adaptivePeriod(adaptivePeriod) 00067 { } 00068 00069 Mode m_mode; 00070 unsigned m_threshold; 00071 unsigned m_signalDeadband; 00072 unsigned m_silenceDeadband; 00073 unsigned m_adaptivePeriod; 00074 }; 00075 00080 OpalSilenceDetector( 00081 const Params & newParam 00082 ); 00084 00087 const PNotifier & GetReceiveHandler() const { return receiveHandler; } 00088 00096 void SetParameters( 00097 const Params & params, 00098 const int clockRate = 0 00099 ); 00100 00106 void SetClockRate( 00107 const int clockRate 00108 ); 00109 00112 int GetClockRate() const { return clockRate; } 00113 00122 Mode GetStatus( 00123 PBoolean * isInTalkBurst, 00124 unsigned * currentThreshold 00125 ) const; 00126 00135 virtual unsigned GetAverageSignalLevel( 00136 const BYTE * buffer, 00137 PINDEX size 00138 ) = 0; 00139 00140 private: 00143 void AdaptiveReset(); 00144 00145 protected: 00146 PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket); 00147 00148 PNotifier receiveHandler; 00149 00150 Mode mode; 00151 unsigned signalDeadband; // #samples of signal needed 00152 unsigned silenceDeadband; // #samples of silence needed 00153 unsigned adaptivePeriod; // #samples window for adaptive threshold 00154 int clockRate; // audio sampling rate 00155 00156 unsigned lastTimestamp; // Last timestamp received 00157 unsigned receivedTime; // Signal/Silence duration received so far. 00158 unsigned levelThreshold; // Threshold level for silence/signal 00159 unsigned signalMinimum; // Minimum of frames above threshold 00160 unsigned silenceMaximum; // Maximum of frames below threshold 00161 unsigned signalReceivedTime; // Duration of signal received 00162 unsigned silenceReceivedTime; // Duration of silence received 00163 bool inTalkBurst; // Currently sending RTP data 00164 PMutex inUse; // Protects values to allow change while running 00165 }; 00166 00167 00168 class OpalPCM16SilenceDetector : public OpalSilenceDetector 00169 { 00170 PCLASSINFO(OpalPCM16SilenceDetector, OpalSilenceDetector); 00171 public: 00174 OpalPCM16SilenceDetector( 00175 const Params & newParam 00176 ) : OpalSilenceDetector(newParam) { } 00177 00188 virtual unsigned GetAverageSignalLevel( 00189 const BYTE * buffer, 00190 PINDEX size 00191 ); 00193 }; 00194 00195 00196 extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode); 00197 00198 00199 #endif // OPAL_CODEC_SILENCEDETECT_H 00200 00201