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  * $Revision: 19279 $
00026  * $Author: rjongbloed $
00027  * $Date: 2008-01-17 04:08:34 +0000 (Thu, 17 Jan 2008) $
00028  */
00029 
00030 #ifndef __OPAL_SILENCEDETECT_H
00031 #define __OPAL_SILENCEDETECT_H
00032 
00033 #ifdef P_USE_PRAGMA
00034 #pragma interface
00035 #endif
00036 
00037 
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 = 80,         
00059         unsigned silenceDeadband = 3200,      
00060         unsigned adaptivePeriod = 4800        
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();
00082 
00085     const PNotifier & GetReceiveHandler() const { return receiveHandler; }
00086 
00091     void SetParameters(
00092       const Params & newParam 
00093     );
00094 
00103     Mode GetStatus(
00104       PBoolean * isInTalkBurst,
00105       unsigned * currentThreshold
00106     ) const;
00107 
00116     virtual unsigned GetAverageSignalLevel(
00117       const BYTE * buffer,  
00118       PINDEX size           
00119     ) = 0;
00120 
00121   protected:
00122     PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket);
00123 
00124     PNotifier receiveHandler;
00125 
00126     Params param;
00127 
00128     PBoolean     inTalkBurst;           // Currently sending RTP data
00129     unsigned lastTimestamp;         // Last timestamp received
00130     unsigned receivedTime;          // Signal/Silence duration received so far.
00131     unsigned levelThreshold;        // Threshold level for silence/signal
00132     unsigned signalMinimum;         // Minimum of frames above threshold
00133     unsigned silenceMaximum;        // Maximum of frames below threshold
00134     unsigned signalReceivedTime;    // Duration of signal received
00135     unsigned silenceReceivedTime;   // Duration of silence received
00136 };
00137 
00138 
00139 class OpalPCM16SilenceDetector : public OpalSilenceDetector
00140 {
00141     PCLASSINFO(OpalPCM16SilenceDetector, OpalSilenceDetector);
00142   public:
00153     virtual unsigned GetAverageSignalLevel(
00154       const BYTE * buffer,  
00155       PINDEX size           
00156     );
00158 };
00159 
00160 
00161 extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode);
00162 
00163 
00164 #endif // __OPAL_SILENCEDETECT_H
00165 
00166 

Generated on Fri Mar 7 07:36:39 2008 for OPAL by  doxygen 1.5.1