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: 20186 $
00026  * $Author: rjongbloed $
00027  * $Date: 2008-05-06 11:13:11 +0000 (Tue, 06 May 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(
00081       const Params & newParam 
00082     );
00084 
00087     const PNotifier & GetReceiveHandler() const { return receiveHandler; }
00088 
00093     void SetParameters(
00094       const Params & newParam 
00095     );
00096 
00105     Mode GetStatus(
00106       PBoolean * isInTalkBurst,
00107       unsigned * currentThreshold
00108     ) const;
00109 
00118     virtual unsigned GetAverageSignalLevel(
00119       const BYTE * buffer,  
00120       PINDEX size           
00121     ) = 0;
00122 
00123   protected:
00124     PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket);
00125 
00126     PNotifier receiveHandler;
00127 
00128     Params param;
00129 
00130     bool     inTalkBurst;           // Currently sending RTP data
00131     unsigned lastTimestamp;         // Last timestamp received
00132     unsigned receivedTime;          // Signal/Silence duration received so far.
00133     unsigned levelThreshold;        // Threshold level for silence/signal
00134     unsigned signalMinimum;         // Minimum of frames above threshold
00135     unsigned silenceMaximum;        // Maximum of frames below threshold
00136     unsigned signalReceivedTime;    // Duration of signal received
00137     unsigned silenceReceivedTime;   // Duration of silence received
00138 };
00139 
00140 
00141 class OpalPCM16SilenceDetector : public OpalSilenceDetector
00142 {
00143     PCLASSINFO(OpalPCM16SilenceDetector, OpalSilenceDetector);
00144   public:
00147     OpalPCM16SilenceDetector(
00148       const Params & newParam 
00149     ) : OpalSilenceDetector(newParam) { }
00150 
00161     virtual unsigned GetAverageSignalLevel(
00162       const BYTE * buffer,  
00163       PINDEX size           
00164     );
00166 };
00167 
00168 
00169 extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode);
00170 
00171 
00172 #endif // __OPAL_SILENCEDETECT_H
00173 
00174 

Generated on Mon Sep 15 11:49:15 2008 for OPAL by  doxygen 1.5.1