sipxmedialib  Version 3.3
MprToneDetect.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2015 SIPez LLC. All rights reserved.
3 //
4 // $$
6 
7 #ifndef _MprToneDetect_h_
8 #define _MprToneDetect_h_
9 
10 // SYSTEM INCLUDES
11 
12 // APPLICATION INCLUDES
13 #include <mp/MpFlowGraphMsg.h>
14 #include <mp/MpResourceMsg.h>
15 #include <mp/MpAudioResource.h>
16 
17 // DEFINES
18 // MACROS
19 // EXTERNAL FUNCTIONS
20 // EXTERNAL VARIABLES
21 // CONSTANTS
22 // STRUCTS
23 // TYPEDEFS
24 // FORWARD DECLARATIONS
25 
31 {
32 /* //////////////////////////// PUBLIC //////////////////////////////////// */
33 public:
34 
35 /* ============================ CREATORS ================================== */
37 
38 
40  MprToneDetect(const UtlString& rName);
41 
43  virtual ~MprToneDetect();
44 
46 
47 /* ============================ MANIPULATORS ============================== */
49 
50 
51  static OsStatus changeTargetFrequency(const UtlString& namedResource,
52  OsMsgQ& fgQ,
53  int targetFreq);
54 
55  static OsStatus changeDetectionThreshold(const UtlString& namedResource,
56  OsMsgQ& fgQ,
57  int threshold);
59 
60 /* ============================ ACCESSORS ================================= */
62 
63  // ideally this should do a lookup on the named resource and
64  // return the value for that
65  double getAvgMagnitude(const UtlString& resName);
66 
68 
69 /* ============================ INQUIRY =================================== */
71 
72 
74 
75 /* //////////////////////////// PROTECTED ///////////////////////////////// */
76 protected:
77 
78 /* //////////////////////////// PRIVATE /////////////////////////////////// */
79 private:
80 
81  enum
82  {
85  };
86 
87  typedef enum
88  {
91  } AddlMsgTypes;
92 
93  virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[],
94  MpBufPtr outBufs[],
95  int inBufsSize,
96  int outBufsSize,
97  UtlBoolean isEnabled,
98  int samplesPerFrame,
99  int samplesPerSecond);
100 
102  virtual UtlBoolean handleMessage(MpFlowGraphMsg& fgMsg);
103 
105  virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);
106 
108  OsStatus setFlowGraph(MpFlowGraphBase* pFlowGraph);
116  MprToneDetect(const MprToneDetect& rMprToneDetect);
118 
121 
122  double getAvgMag() const;
123 
124  static const double DEFAULT_TARGET_FREQ;
125  static const double DEFAULT_SAMPLING_RATE;
126  static const double DEFAULT_THRESHOLD;
127  static const unsigned DEFAULT_BLOCK_SIZE;
128  static const int DEFAULT_WINDOW_SIZE;
129 
130  double mCoeff;
131  double mQ1;
132  double mQ2;
133  double mThreshold;
134  double mTargetFreq;
135  unsigned mBlockCnt;
136  bool mCurTd;
138  double mAvg3Mag;
139  double mSampleRate;
140  unsigned mBlockSize;
143 
144  double *mFilterData;
145  void resetGoertzel(void);
146  void initGoertzel(void);
147  void processSample(MpAudioSample sample);
148  double getMagnitudeSquared(void);
149  void initFilter();
150  double filterSample(MpAudioSample sample, uint32_t n);
151 };
152 
153 /* ============================ INLINE METHODS ============================ */
154 
155 #endif // _MprToneDetect_h_
Message object used to communicate with the media processing task.
Definition: MpFlowGraphMsg.h:33
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
unsigned mBlockSize
Definition: MprToneDetect.h:140
int samplesPerFrame
static OsStatus changeTargetFrequency(const UtlString &namedResource, OsMsgQ &fgQ, int targetFreq)
Definition: MprToneDetect.cpp:280
Definition: MpResourceMsg.h:56
static const double DEFAULT_TARGET_FREQ
Definition: MprToneDetect.h:124
bool mToneSignaled
Definition: MprToneDetect.h:137
MpFlowGraphBase * mpFlowGraph
Definition: MprToneDetect.h:142
double mTargetFreq
Definition: MprToneDetect.h:134
Definition: MprToneDetect.h:84
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
double getAvgMagnitude(const UtlString &resName)
Definition: MprToneDetect.cpp:306
double mCoeff
Definition: MprToneDetect.h:130
double mQ2
Definition: MprToneDetect.h:132
Definition: MprToneDetect.h:89
int samplesPerSecond
virtual ~MprToneDetect()
Destructor.
Definition: MprToneDetect.cpp:70
void initFilter()
Definition: MprToneDetect.cpp:260
int16_t MpAudioSample
Definition: MpTypes.h:44
Definition: MprToneDetect.h:83
virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond)
This method does the real work for the media processing resource and must be defined in each class de...
Definition: MprToneDetect.cpp:84
Abstract base class for all audio processing objects.
Definition: MpAudioResource.h:38
double filterSample(MpAudioSample sample, uint32_t n)
Definition: MprToneDetect.cpp:275
virtual UtlBoolean handleMessage(MpFlowGraphMsg &fgMsg)
Handle flowgraph messages for this resource.
Definition: MprToneDetect.cpp:147
unsigned mBlockCnt
Definition: MprToneDetect.h:135
AddlMsgTypes
Definition: MprToneDetect.h:87
bool mCurTd
Definition: MprToneDetect.h:136
double mAvg3Mag
Definition: MprToneDetect.h:138
double mThreshold
Definition: MprToneDetect.h:133
MprToneDetect & operator=(const MprToneDetect &rhs)
Assignment operator (not implemented for this class)
double * mFilterData
Definition: MprToneDetect.h:144
The "Tone Detector" media processing resource.
Definition: MprToneDetect.h:30
void initGoertzel(void)
Definition: MprToneDetect.cpp:218
int mWindowSize
Definition: MprToneDetect.h:141
double getAvgMag() const
Definition: MprToneDetect.cpp:301
MprToneDetect(const UtlString &rName)
Constructor.
Definition: MprToneDetect.cpp:48
double mSampleRate
Definition: MprToneDetect.h:139
void processSample(MpAudioSample sample)
Definition: MprToneDetect.cpp:240
Smart pointer to MpBuf.
Definition: MpBuf.h:160
OsStatus setFlowGraph(MpFlowGraphBase *pFlowGraph)
Associates this resource with the indicated flow graph.
Definition: MprToneDetect.cpp:197
Definition: MprToneDetect.h:90
static OsStatus changeDetectionThreshold(const UtlString &namedResource, OsMsgQ &fgQ, int threshold)
Definition: MprToneDetect.cpp:291
static const double DEFAULT_THRESHOLD
Definition: MprToneDetect.h:126
double mQ1
Definition: MprToneDetect.h:131
static const int DEFAULT_WINDOW_SIZE
Definition: MprToneDetect.h:128
static const double DEFAULT_SAMPLING_RATE
Definition: MprToneDetect.h:125
void resetGoertzel(void)
Definition: MprToneDetect.cpp:209
static const unsigned DEFAULT_BLOCK_SIZE
Definition: MprToneDetect.h:127
double getMagnitudeSquared(void)
Definition: MprToneDetect.cpp:249
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
start of resource-specific messages
Definition: MpFlowGraphMsg.h:67