silencedetect.h

Go to the documentation of this file.
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  * $Log: silencedetect.h,v $
00026  * Revision 1.4  2005/11/30 13:35:26  csoutheren
00027  * Changed tags for Doxygen
00028  *
00029  * Revision 1.3  2005/07/09 06:52:38  rjongbloed
00030  * Added print (operator<<) of silence detect mode enum.
00031  *
00032  * Revision 1.2  2004/05/24 13:39:26  rjongbloed
00033  * Fixed setting marker bit when silence suppression transitions from
00034  *   silence to signal, thanks Ted Szoczei
00035  * Added a separate structure for the silence suppression paramters to make
00036  *   it easier to set from global defaults in the manager class.
00037  *
00038  * Revision 1.1  2004/05/17 13:24:26  rjongbloed
00039  * Added silence suppression.
00040  *
00041  */
00042 
00043 #ifndef __OPAL_SILENCEDETECT_H
00044 #define __OPAL_SILENCEDETECT_H
00045 
00046 #ifdef P_USE_PRAGMA
00047 #pragma interface
00048 #endif
00049 
00050 
00051 #include <rtp/rtp.h>
00052 
00053 
00055 
00056 class OpalSilenceDetector : public PObject
00057 {
00058     PCLASSINFO(OpalSilenceDetector, PObject);
00059   public:
00060     enum Mode {
00061       NoSilenceDetection,
00062       FixedSilenceDetection,
00063       AdaptiveSilenceDetection,
00064       NumModes
00065     };
00066 
00067     struct Params {
00068       Params(
00069         Mode mode = AdaptiveSilenceDetection, 
00070         unsigned threshold = 0,               
00071         unsigned signalDeadband = 80,         
00072         unsigned silenceDeadband = 3200,      
00073         unsigned adaptivePeriod = 4800        
00074       )
00075         : m_mode(mode),
00076           m_threshold(threshold),
00077           m_signalDeadband(signalDeadband),
00078           m_silenceDeadband(silenceDeadband),
00079           m_adaptivePeriod(adaptivePeriod)
00080         { }
00081 
00082       Mode     m_mode;             
00083       unsigned m_threshold;        
00084       unsigned m_signalDeadband;   
00085       unsigned m_silenceDeadband;  
00086       unsigned m_adaptivePeriod;   
00087     };
00088 
00093     OpalSilenceDetector();
00095 
00098     const PNotifier & GetReceiveHandler() const { return receiveHandler; }
00099 
00104     void SetParameters(
00105       const Params & newParam 
00106     );
00107 
00116     Mode GetStatus(
00117       BOOL * isInTalkBurst,
00118       unsigned * currentThreshold
00119     ) const;
00120 
00129     virtual unsigned GetAverageSignalLevel(
00130       const BYTE * buffer,  
00131       PINDEX size           
00132     ) = 0;
00133 
00134   protected:
00135     PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket);
00136 
00137     PNotifier receiveHandler;
00138 
00139     Params param;
00140 
00141     BOOL     inTalkBurst;           // Currently sending RTP data
00142     unsigned lastTimestamp;         // Last timestamp received
00143     unsigned receivedTime;          // Signal/Silence duration received so far.
00144     unsigned levelThreshold;        // Threshold level for silence/signal
00145     unsigned signalMinimum;         // Minimum of frames above threshold
00146     unsigned silenceMaximum;        // Maximum of frames below threshold
00147     unsigned signalReceivedTime;    // Duration of signal received
00148     unsigned silenceReceivedTime;   // Duration of silence received
00149 };
00150 
00151 
00152 class OpalPCM16SilenceDetector : public OpalSilenceDetector
00153 {
00154     PCLASSINFO(OpalPCM16SilenceDetector, OpalSilenceDetector);
00155   public:
00166     virtual unsigned GetAverageSignalLevel(
00167       const BYTE * buffer,  
00168       PINDEX size           
00169     );
00171 };
00172 
00173 
00174 extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode);
00175 
00176 
00177 #endif // __OPAL_SILENCEDETECT_H
00178 
00179 

Generated on Fri Mar 7 06:33:41 2008 for OPAL by  doxygen 1.5.1