silencedetect.h
Go to the documentation of this file.
/*
* silencedetect.h
*
* Open Phone Abstraction Library (OPAL)
* Formally known as the Open H323 project.
*
* Copyright (c) 2004 Post Increment
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open Phone Abstraction Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24320 $
* $Author: csoutheren $
* $Date: 2010-05-06 10:20:51 -0500 (Thu, 06 May 2010) $
*/
#ifndef OPAL_CODEC_SILENCEDETECT_H
#define OPAL_CODEC_SILENCEDETECT_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#include <rtp/rtp.h>
class OpalSilenceDetector : public PObject
{
PCLASSINFO(OpalSilenceDetector, PObject);
public:
enum Mode {
NoSilenceDetection,
FixedSilenceDetection,
AdaptiveSilenceDetection,
NumModes
};
struct Params {
Params(
Mode mode = AdaptiveSilenceDetection,
unsigned threshold = 0,
unsigned signalDeadband = 10,
unsigned silenceDeadband = 400,
unsigned adaptivePeriod = 600
)
: m_mode(mode),
m_threshold(threshold),
m_signalDeadband(signalDeadband),
m_silenceDeadband(silenceDeadband),
m_adaptivePeriod(adaptivePeriod)
{ }
Mode m_mode;
unsigned m_threshold;
unsigned m_signalDeadband;
unsigned m_silenceDeadband;
unsigned m_adaptivePeriod;
};
OpalSilenceDetector(
const Params & newParam
);
const PNotifier & GetReceiveHandler() const { return receiveHandler; }
void SetParameters(
const Params & params,
const int clockRate = 0
);
void SetClockRate(
const int clockRate
);
int GetClockRate() const { return clockRate; }
Mode GetStatus(
PBoolean * isInTalkBurst,
unsigned * currentThreshold
) const;
virtual unsigned GetAverageSignalLevel(
const BYTE * buffer,
PINDEX size
) = 0;
private:
void AdaptiveReset();
protected:
PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket);
PNotifier receiveHandler;
Mode mode;
unsigned signalDeadband; // #samples of signal needed
unsigned silenceDeadband; // #samples of silence needed
unsigned adaptivePeriod; // #samples window for adaptive threshold
int clockRate; // audio sampling rate
unsigned lastTimestamp; // Last timestamp received
unsigned receivedTime; // Signal/Silence duration received so far.
unsigned levelThreshold; // Threshold level for silence/signal
unsigned signalMinimum; // Minimum of frames above threshold
unsigned silenceMaximum; // Maximum of frames below threshold
unsigned signalReceivedTime; // Duration of signal received
unsigned silenceReceivedTime; // Duration of silence received
bool inTalkBurst; // Currently sending RTP data
PMutex inUse; // Protects values to allow change while running
};
class OpalPCM16SilenceDetector : public OpalSilenceDetector
{
PCLASSINFO(OpalPCM16SilenceDetector, OpalSilenceDetector);
public:
OpalPCM16SilenceDetector(
const Params & newParam
) : OpalSilenceDetector(newParam) { }
virtual unsigned GetAverageSignalLevel(
const BYTE * buffer,
PINDEX size
);
};
extern ostream & operator<<(ostream & strm, OpalSilenceDetector::Mode mode);
#endif // OPAL_CODEC_SILENCEDETECT_H
OpalSilenceDetector::Params::m_mode
Mode m_mode
Definition: silencedetect.h:69
OpalSilenceDetector::Params
Definition: silencedetect.h:54
OpalPCM16SilenceDetector
Definition: silencedetect.h:168
OpalSilenceDetector::SetClockRate
void SetClockRate(const int clockRate)
OpalSilenceDetector::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(RTP_DataFrame, OpalSilenceDetector, ReceivedPacket)
buildopts.h
OpalSilenceDetector::levelThreshold
unsigned levelThreshold
Definition: silencedetect.h:158
OpalSilenceDetector::Params::m_silenceDeadband
unsigned m_silenceDeadband
milliseconds of signal needed
Definition: silencedetect.h:72
OpalSilenceDetector::GetClockRate
int GetClockRate() const
Definition: silencedetect.h:112
OpalSilenceDetector::FixedSilenceDetection
Definition: silencedetect.h:49
OpalSilenceDetector::SetParameters
void SetParameters(const Params &params, const int clockRate=0)
OpalSilenceDetector::GetAverageSignalLevel
virtual unsigned GetAverageSignalLevel(const BYTE *buffer, PINDEX size)=0
OpalSilenceDetector::inUse
PMutex inUse
Definition: silencedetect.h:164
OpalSilenceDetector::Params::m_adaptivePeriod
unsigned m_adaptivePeriod
milliseconds of silence needed
Definition: silencedetect.h:73
OpalSilenceDetector::silenceReceivedTime
unsigned silenceReceivedTime
Definition: silencedetect.h:162
OpalSilenceDetector::lastTimestamp
unsigned lastTimestamp
Definition: silencedetect.h:156
OpalSilenceDetector
Definition: silencedetect.h:43
RTP_DataFrame
Definition: rtp.h:71
OpalSilenceDetector::signalReceivedTime
unsigned signalReceivedTime
Definition: silencedetect.h:161
OpalSilenceDetector::Mode
Mode
Definition: silencedetect.h:47
OpalSilenceDetector::signalDeadband
unsigned signalDeadband
Definition: silencedetect.h:151
OpalSilenceDetector::silenceDeadband
unsigned silenceDeadband
Definition: silencedetect.h:152
OpalSilenceDetector::mode
Mode mode
Definition: silencedetect.h:150
OpalSilenceDetector::silenceMaximum
unsigned silenceMaximum
Definition: silencedetect.h:160
operator<<
ostream & operator<<(ostream &strm, OpalSilenceDetector::Mode mode)
OpalSilenceDetector::clockRate
int clockRate
Definition: silencedetect.h:154
OpalPCM16SilenceDetector::OpalPCM16SilenceDetector
OpalPCM16SilenceDetector(const Params &newParam)
Definition: silencedetect.h:174
OpalSilenceDetector::OpalSilenceDetector
OpalSilenceDetector(const Params &newParam)
OpalSilenceDetector::NoSilenceDetection
Definition: silencedetect.h:48
OpalSilenceDetector::inTalkBurst
bool inTalkBurst
Definition: silencedetect.h:163
OpalSilenceDetector::signalMinimum
unsigned signalMinimum
Definition: silencedetect.h:159
OpalPCM16SilenceDetector::GetAverageSignalLevel
virtual unsigned GetAverageSignalLevel(const BYTE *buffer, PINDEX size)
OpalSilenceDetector::GetStatus
Mode GetStatus(PBoolean *isInTalkBurst, unsigned *currentThreshold) const
OpalSilenceDetector::AdaptiveSilenceDetection
Definition: silencedetect.h:50
OpalSilenceDetector::receivedTime
unsigned receivedTime
Definition: silencedetect.h:157
OpalSilenceDetector::NumModes
Definition: silencedetect.h:51
rtp.h
OpalSilenceDetector::Params::m_signalDeadband
unsigned m_signalDeadband
Threshold value if FixedSilenceDetection.
Definition: silencedetect.h:71
OpalSilenceDetector::GetReceiveHandler
const PNotifier & GetReceiveHandler() const
Definition: silencedetect.h:87
OpalSilenceDetector::Params::Params
Params(Mode mode=AdaptiveSilenceDetection, unsigned threshold=0, unsigned signalDeadband=10, unsigned silenceDeadband=400, unsigned adaptivePeriod=600)
Definition: silencedetect.h:55
OpalSilenceDetector::adaptivePeriod
unsigned adaptivePeriod
Definition: silencedetect.h:153
OpalSilenceDetector::Params::m_threshold
unsigned m_threshold
Silence detection mode.
Definition: silencedetect.h:70
OpalSilenceDetector::receiveHandler
PNotifier receiveHandler
Definition: silencedetect.h:148