OPAL
Version 3.14.3
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
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: 30051 $
26
* $Author: rjongbloed $
27
* $Date: 2013-06-25 16:11:08 +1000 (Tue, 25 Jun 2013) $
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_config.h
>
38
#include <
rtp/rtp.h
>
39
40
42
43
class
OpalSilenceDetector
:
public
PObject
44
{
45
PCLASSINFO(
OpalSilenceDetector
, PObject);
46
public
:
47
P_DECLARE_STREAMABLE_ENUM
(Modes,
48
NoSilenceDetection,
49
FixedSilenceDetection,
50
AdaptiveSilenceDetection
51
);
52
typedef
Modes
Mode
;
// Backward compatibility
53
54
struct
Params
{
55
Params
(
56
Modes
mode
= AdaptiveSilenceDetection,
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),
64
m_signalDeadband
(
signalDeadband
),
65
m_silenceDeadband
(
silenceDeadband
),
66
m_adaptivePeriod
(
adaptivePeriod
)
67
{ }
68
69
PString
AsString
()
const
;
70
void
FromString
(
const
PString & str);
71
72
Modes
m_mode
;
73
unsigned
m_threshold
;
74
unsigned
m_signalDeadband
;
75
unsigned
m_silenceDeadband
;
76
unsigned
m_adaptivePeriod
;
77
};
78
83
OpalSilenceDetector
(
84
const
Params
& newParam
85
);
87
90
const
PNotifier &
GetReceiveHandler
()
const
{
return
receiveHandler
; }
91
99
void
SetParameters
(
100
const
Params & params,
101
const
int
clockRate
= 0
102
);
103
106
void
GetParameters
(
107
Params & params
108
);
109
115
void
SetClockRate
(
116
unsigned
clockRate
117
);
118
121
unsigned
GetClockRate
()
const
{
return
clockRate
; }
122
131
Mode
GetStatus
(
132
PBoolean * isInTalkBurst,
133
unsigned
* currentThreshold
134
)
const
;
135
144
virtual
unsigned
GetAverageSignalLevel
(
145
const
BYTE * buffer,
146
PINDEX size
147
) = 0;
148
149
private
:
152
void
AdaptiveReset();
153
154
protected
:
155
PDECLARE_NOTIFIER
(
RTP_DataFrame
,
OpalSilenceDetector
, ReceivedPacket);
156
157
PNotifier
receiveHandler
;
158
159
Mode
mode
;
160
unsigned
signalDeadband
;
// #samples of signal needed
161
unsigned
silenceDeadband
;
// #samples of silence needed
162
unsigned
adaptivePeriod
;
// #samples window for adaptive threshold
163
unsigned
clockRate
;
// audio sampling rate
164
165
unsigned
lastTimestamp
;
// Last timestamp received
166
unsigned
receivedTime
;
// Signal/Silence duration received so far.
167
unsigned
levelThreshold
;
// Threshold level for silence/signal
168
unsigned
signalMinimum
;
// Minimum of frames above threshold
169
unsigned
silenceMaximum
;
// Maximum of frames below threshold
170
unsigned
signalReceivedTime
;
// Duration of signal received
171
unsigned
silenceReceivedTime
;
// Duration of silence received
172
bool
inTalkBurst
;
// Currently sending RTP data
173
PMutex
inUse
;
// Protects values to allow change while running
174
};
175
176
177
class
OpalPCM16SilenceDetector
:
public
OpalSilenceDetector
178
{
179
PCLASSINFO(
OpalPCM16SilenceDetector
,
OpalSilenceDetector
);
180
public
:
183
OpalPCM16SilenceDetector
(
184
const
Params
& newParam
185
) :
OpalSilenceDetector
(newParam) { }
186
197
virtual
unsigned
GetAverageSignalLevel
(
198
const
BYTE * buffer,
199
PINDEX size
200
);
202
};
203
204
205
extern
ostream &
operator<<
(ostream & strm,
OpalSilenceDetector::Mode
mode);
206
207
208
#endif // OPAL_CODEC_SILENCEDETECT_H
209
210
include
codec
silencedetect.h
Generated on Fri Oct 10 2014 21:36:58 for OPAL by
1.8.3.1