OPAL  Version 3.10.10
silencedetect.h
Go to the documentation of this file.
1 /*
2  * silencedetect.h
3  *
4  * Open Phone Abstraction Library (OPAL)
5  * Formally known as the Open H323 project.
6  *
7  * Copyright (c) 2004 Post Increment
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.0 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16  * the License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * The Original Code is Open Phone Abstraction Library.
20  *
21  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
22  *
23  * Contributor(s): ______________________________________.
24  *
25  * $Revision: 24320 $
26  * $Author: csoutheren $
27  * $Date: 2010-05-06 10:20:51 -0500 (Thu, 06 May 2010) $
28  */
29 
30 #ifndef OPAL_CODEC_SILENCEDETECT_H
31 #define OPAL_CODEC_SILENCEDETECT_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #include <opal/buildopts.h>
38 #include <rtp/rtp.h>
39 
40 
42 
43 class OpalSilenceDetector : public PObject
44 {
45  PCLASSINFO(OpalSilenceDetector, PObject);
46  public:
47  enum Mode {
52  };
53 
54  struct Params {
57  unsigned threshold = 0,
58  unsigned signalDeadband = 10,
59  unsigned silenceDeadband = 400,
60  unsigned adaptivePeriod = 600
61  )
62  : m_mode(mode),
63  m_threshold(threshold),
67  { }
68 
70  unsigned m_threshold;
71  unsigned m_signalDeadband;
72  unsigned m_silenceDeadband;
73  unsigned m_adaptivePeriod;
74  };
75 
81  const Params & newParam
82  );
84 
87  const PNotifier & GetReceiveHandler() const { return receiveHandler; }
88 
96  void SetParameters(
97  const Params & params,
98  const int clockRate = 0
99  );
100 
106  void SetClockRate(
107  const int clockRate
108  );
109 
112  int GetClockRate() const { return clockRate; }
113 
122  Mode GetStatus(
123  PBoolean * isInTalkBurst,
124  unsigned * currentThreshold
125  ) const;
126 
135  virtual unsigned GetAverageSignalLevel(
136  const BYTE * buffer,
137  PINDEX size
138  ) = 0;
139 
140  private:
143  void AdaptiveReset();
144 
145  protected:
147 
148  PNotifier receiveHandler;
149 
151  unsigned signalDeadband; // #samples of signal needed
152  unsigned silenceDeadband; // #samples of silence needed
153  unsigned adaptivePeriod; // #samples window for adaptive threshold
154  int clockRate; // audio sampling rate
155 
156  unsigned lastTimestamp; // Last timestamp received
157  unsigned receivedTime; // Signal/Silence duration received so far.
158  unsigned levelThreshold; // Threshold level for silence/signal
159  unsigned signalMinimum; // Minimum of frames above threshold
160  unsigned silenceMaximum; // Maximum of frames below threshold
161  unsigned signalReceivedTime; // Duration of signal received
162  unsigned silenceReceivedTime; // Duration of silence received
163  bool inTalkBurst; // Currently sending RTP data
164  PMutex inUse; // Protects values to allow change while running
165 };
166 
167 
169 {
171  public:
175  const Params & newParam
176  ) : OpalSilenceDetector(newParam) { }
177 
188  virtual unsigned GetAverageSignalLevel(
189  const BYTE * buffer,
190  PINDEX size
191  );
193 };
194 
195 
196 extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode);
197 
198 
199 #endif // OPAL_CODEC_SILENCEDETECT_H
200 
201 
Mode m_mode
Definition: silencedetect.h:69
Definition: silencedetect.h:54
Definition: silencedetect.h:168
void SetClockRate(const int clockRate)
PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket)
unsigned levelThreshold
Definition: silencedetect.h:158
unsigned m_silenceDeadband
milliseconds of signal needed
Definition: silencedetect.h:72
int GetClockRate() const
Definition: silencedetect.h:112
Definition: silencedetect.h:49
void SetParameters(const Params &params, const int clockRate=0)
virtual unsigned GetAverageSignalLevel(const BYTE *buffer, PINDEX size)=0
PMutex inUse
Definition: silencedetect.h:164
unsigned m_adaptivePeriod
milliseconds of silence needed
Definition: silencedetect.h:73
unsigned silenceReceivedTime
Definition: silencedetect.h:162
unsigned lastTimestamp
Definition: silencedetect.h:156
Definition: silencedetect.h:43
Definition: rtp.h:71
unsigned signalReceivedTime
Definition: silencedetect.h:161
Mode
Definition: silencedetect.h:47
unsigned signalDeadband
Definition: silencedetect.h:151
unsigned silenceDeadband
Definition: silencedetect.h:152
Mode mode
Definition: silencedetect.h:150
unsigned silenceMaximum
Definition: silencedetect.h:160
ostream & operator<<(ostream &strm, OpalSilenceDetector::Mode mode)
int clockRate
Definition: silencedetect.h:154
OpalPCM16SilenceDetector(const Params &newParam)
Definition: silencedetect.h:174
OpalSilenceDetector(const Params &newParam)
Definition: silencedetect.h:48
bool inTalkBurst
Definition: silencedetect.h:163
unsigned signalMinimum
Definition: silencedetect.h:159
virtual unsigned GetAverageSignalLevel(const BYTE *buffer, PINDEX size)
Mode GetStatus(PBoolean *isInTalkBurst, unsigned *currentThreshold) const
Definition: silencedetect.h:50
unsigned receivedTime
Definition: silencedetect.h:157
Definition: silencedetect.h:51
unsigned m_signalDeadband
Threshold value if FixedSilenceDetection.
Definition: silencedetect.h:71
const PNotifier & GetReceiveHandler() const
Definition: silencedetect.h:87
Params(Mode mode=AdaptiveSilenceDetection, unsigned threshold=0, unsigned signalDeadband=10, unsigned silenceDeadband=400, unsigned adaptivePeriod=600)
Definition: silencedetect.h:55
unsigned adaptivePeriod
Definition: silencedetect.h:153
unsigned m_threshold
Silence detection mode.
Definition: silencedetect.h:70
PNotifier receiveHandler
Definition: silencedetect.h:148