4 * Open Phone Abstraction Library (OPAL)
5 * Formally known as the Open H323 project.
7 * Copyright (c) 2004 Post Increment
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/
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
19 * The Original Code is Open Phone Abstraction Library.
21 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23 * Contributor(s): ______________________________________.
26 * Revision 1.4 2005/11/30 13:35:26 csoutheren
27 * Changed tags for Doxygen
29 * Revision 1.3 2005/07/09 06:52:38 rjongbloed
30 * Added print (operator<<) of silence detect mode enum.
32 * Revision 1.2 2004/05/24 13:39:26 rjongbloed
33 * Fixed setting marker bit when silence suppression transitions from
34 * silence to signal, thanks Ted Szoczei
35 * Added a separate structure for the silence suppression paramters to make
36 * it easier to set from global defaults in the manager class.
38 * Revision 1.1 2004/05/17 13:24:26 rjongbloed
39 * Added silence suppression.
43 #ifndef __OPAL_SILENCEDETECT_H
44 #define __OPAL_SILENCEDETECT_H
54 ///////////////////////////////////////////////////////////////////////////////
56 class OpalSilenceDetector
: public PObject
58 PCLASSINFO(OpalSilenceDetector
, PObject
);
62 FixedSilenceDetection
,
63 AdaptiveSilenceDetection
,
69 Mode mode
= AdaptiveSilenceDetection
, ///< New silence detection mode
70 unsigned threshold
= 0, ///< Threshold value if FixedSilenceDetection
71 unsigned signalDeadband
= 80, ///< 10 milliseconds of signal needed
72 unsigned silenceDeadband
= 3200, ///< 400 milliseconds of silence needed
73 unsigned adaptivePeriod
= 4800 ///< 600 millisecond window for adaptive threshold
76 m_threshold(threshold
),
77 m_signalDeadband(signalDeadband
),
78 m_silenceDeadband(silenceDeadband
),
79 m_adaptivePeriod(adaptivePeriod
)
82 Mode m_mode
; /// Silence detection mode
83 unsigned m_threshold
; /// Threshold value if FixedSilenceDetection
84 unsigned m_signalDeadband
; /// 10 milliseconds of signal needed
85 unsigned m_silenceDeadband
; /// 400 milliseconds of silence needed
86 unsigned m_adaptivePeriod
; /// 600 millisecond window for adaptive threshold
89 /**@name Construction */
91 /**Create a new connection.
93 OpalSilenceDetector();
96 /**@name Basic operations */
98 const PNotifier
& GetReceiveHandler() const { return receiveHandler
; }
100 /**Set the silence detector parameters.
101 This enables, disables the silence detector as well as adjusting its
102 "agression". The deadband periods are in audio samples of 8kHz.
105 const Params
& newParam
///< New parameters for silence detector
108 /**Get silence detection status
110 The inTalkBurst value is TRUE if packet transmission is enabled and
111 FALSE if it is being suppressed due to silence.
113 The currentThreshold value is the value from 0 to 32767 which is used
114 as the threshold value for 16 bit PCM data.
117 BOOL
* isInTalkBurst
,
118 unsigned * currentThreshold
121 /**Get the average signal level in the stream.
122 This is called from within the silence detection algorithm to
123 calculate the average signal level of the last data frame read from
126 The default behaviour returns UINT_MAX which indicates that the
127 average signal has no meaning for the stream.
129 virtual unsigned GetAverageSignalLevel(
130 const BYTE
* buffer
, ///< RTP payload being detected
131 PINDEX size
///< Size of payload buffer
135 PDECLARE_NOTIFIER(RTP_DataFrame
, OpalSilenceDetector
, ReceivedPacket
);
137 PNotifier receiveHandler
;
141 BOOL inTalkBurst
; // Currently sending RTP data
142 unsigned lastTimestamp
; // Last timestamp received
143 unsigned receivedTime
; // Signal/Silence duration received so far.
144 unsigned levelThreshold
; // Threshold level for silence/signal
145 unsigned signalMinimum
; // Minimum of frames above threshold
146 unsigned silenceMaximum
; // Maximum of frames below threshold
147 unsigned signalReceivedTime
; // Duration of signal received
148 unsigned silenceReceivedTime
; // Duration of silence received
152 class OpalPCM16SilenceDetector
: public OpalSilenceDetector
154 PCLASSINFO(OpalPCM16SilenceDetector
, OpalSilenceDetector
);
156 /**@name Overrides from OpalSilenceDetector */
158 /**Get the average signal level in the stream.
159 This is called from within the silence detection algorithm to
160 calculate the average signal level of the last data frame read from
163 The default behaviour returns UINT_MAX which indicates that the
164 average signal has no meaning for the stream.
166 virtual unsigned GetAverageSignalLevel(
167 const BYTE
* buffer
, ///< RTP payload being detected
168 PINDEX size
///< Size of payload buffer
174 extern ostream
& operator<<(ostream
& strm
, OpalSilenceDetector::Mode mode
);
177 #endif // __OPAL_SILENCEDETECT_H
180 /////////////////////////////////////////////////////////////////////////////