sipxmedialib  Version 3.3
MpAudioBuf.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2006 SIPez LLC.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _INCLUDED_MPAUDIOBUF_H /* [ */
12 #define _INCLUDED_MPAUDIOBUF_H
13 
14 // SYSTEM INCLUDES
15 #include <assert.h>
16 
17 // APPLICATION INCLUDES
18 #include "mp/MpDataBuf.h"
19 #include "mp/MpTypes.h"
20 
21 // DEFINES
22 // MACROS
23 // EXTERNAL FUNCTIONS
24 // EXTERNAL VARIABLES
25 // CONSTANTS
26 // STRUCTS
27 // TYPEDEFS
28 // FORWARD DECLARATIONS
29 class MpAudioBufPtr;
30 
32 
36 struct MpAudioBuf : public MpDataBuf
37 {
38  friend class MpAudioBufPtr;
39 
40 /* //////////////////////////// PUBLIC //////////////////////////////////// */
41 public:
42 
44 
45 /* ============================ CREATORS ================================== */
47 
48 
49 
51 
52 /* ============================ MANIPULATORS ============================== */
54 
55 
58 
60 
65  bool setSamplesNumber(int samplesNum)
66  {return mpData->setDataSize(samplesNum*sizeof(MpAudioSample));}
67 
69  void setTimecode(unsigned timecode) {assert(!"MpAudioBuf::setTimecode() is not implemented!");}
70 
72  void setAmplitude(MpAudioSample amplitude) {mParams.mAmplitude = amplitude;}
73 
75  void setClipping(UtlBoolean clipping) {mParams.mIsClipped = clipping;}
76 
78  void setEnergy(int energy) {mParams.mFrameEnergy = energy;}
79 
81  void setSpeechParams(const MpSpeechParams &params) {mParams = params;}
82 
84 
85 /* ============================ ACCESSORS ================================= */
87 
88 
91 
93  const MpAudioSample *getSamplesPtr() const {return (const MpAudioSample*)getDataPtr();}
94 
97 
99  unsigned getSamplesNumber() const {return mpData->getDataSize()/sizeof(MpAudioSample);}
100 
102  unsigned getTimecode() const {assert(!"MpAudioBuf::getTimecode() is not implemented!"); return 0;}
103 
106 
108  UtlBoolean getClipping() const {return mParams.mIsClipped;}
109 
111  int getEnergy() const {return mParams.mFrameEnergy;}
112 
114  const MpSpeechParams &getSpeechParams() const {return mParams;}
115 
118 
120 
121 /* ============================ INQUIRY =================================== */
123 
124 
126  int compareSamples(const MpAudioBufPtr& frame,
127  unsigned int tolerance = 0) const;
137 
138 /* //////////////////////////// PROTECTED ///////////////////////////////// */
139 protected:
140 
142 
144  void init();
145 
146 /* //////////////////////////// PRIVATE /////////////////////////////////// */
147 private:
148 
150  MpAudioBuf(const MpBuf &);
155  MpAudioBuf &operator=(const MpBuf &);
160 };
161 
163 
168 class MpAudioBufPtr : public MpDataBufPtr {
169 
170 /* //////////////////////////// PUBLIC //////////////////////////////////// */
171 public:
172 
173 /* ============================ CREATORS ================================== */
175 
176 
179 
180 
182 
183 
185 
186 
187 
188 /* ============================ MANIPULATORS ============================== */
190 
191 
193 
194 /* ============================ ACCESSORS ================================= */
196 
197 
200 
201 
203 
204 
205 
206 /* ============================ INQUIRY =================================== */
208 
209 
210 
211 
212 
213 /* //////////////////////////// PROTECTED ///////////////////////////////// */
214 protected:
215 
216 
217 /* //////////////////////////// PRIVATE /////////////////////////////////// */
218 private:
219 
220 };
221 
222 /* ============================ INLINE METHODS ============================ */
223 
224 #endif /* ] _INCLUDED_MPAUDIOBUF_H */
MpAudioSample mAmplitude
Amplitude of the audio data in this buffer.
Definition: MpTypes.h:96
MpSpeechType mSpeechType
Whether buffer contains speech.
Definition: MpTypes.h:95
#define MPBUF_TYPECHECKED_COPY(classname, buffer_type, base_classname)
Copy object from base type with type check.
Definition: MpBuf.h:407
MpAudioSample * getSamplesWritePtr()
Get writable pointer to audio data.
Definition: MpAudioBuf.h:96
const MpAudioSample * getSamplesPtr() const
Get pointer to audio data.
Definition: MpAudioBuf.h:93
MpAudioBuf(const MpBuf &)
Disable copy (and other) constructor.
char * getDataWritePtr()
Return pointer to payload data.
Definition: MpDataBuf.cpp:35
void setSpeechParams(const MpSpeechParams &params)
Set all speech parameters at once.
Definition: MpAudioBuf.h:81
Definition: MpTypes.h:74
const char * getDataPtr() const
Return pointer to payload data.
Definition: MpDataBuf.cpp:43
unsigned getTimecode() const
Get time code for this frame.
Definition: MpAudioBuf.h:102
void setTimecode(unsigned timecode)
Set time code for this frame.
Definition: MpAudioBuf.h:69
MpArrayBufPtr mpData
Payload data.
Definition: MpDataBuf.h:93
const MpSpeechParams & getSpeechParams() const
Get speech parameters as a structure (const version)
Definition: MpAudioBuf.h:114
#define MPBUFDATA_FROM_BASE_CONSTRUCTOR(classname, buffer_type, base_classname)
This constructor owns MpBuf object.
Definition: MpDataBuf.h:18
MpAudioBuf & operator=(const MpBuf &)
Disable assignment operator.
void setAmplitude(MpAudioSample amplitude)
Set amplitude of the data in the buffer.
Definition: MpAudioBuf.h:72
void setClipping(UtlBoolean clipping)
Is data in the buffer clipped?
Definition: MpAudioBuf.h:75
int getEnergy() const
Get normalized frame energy.
Definition: MpAudioBuf.h:111
MpSpeechParams mParams
Parameters of the frame data.
Definition: MpAudioBuf.h:141
int16_t MpAudioSample
Definition: MpTypes.h:44
static MpBufPool * smpDefaultPool
Default pool for this type of buffer.
Definition: MpAudioBuf.h:43
void init()
This is called in place of constructor.
Definition: MpAudioBuf.cpp:79
MpSpeechType
Type of audio data.
Definition: MpTypes.h:65
int mFrameEnergy
Definition: MpTypes.h:98
Smart pointer to MpAudioBuf.
Definition: MpAudioBuf.h:168
MpAudioSample getAmplitude() const
Get amplitude of the data in the buffer.
Definition: MpAudioBuf.h:105
bool setSamplesNumber(int samplesNum)
Set current number of samples in audio data.
Definition: MpAudioBuf.h:65
UtlBoolean getClipping() const
Is data in the buffer clipped?
Definition: MpAudioBuf.h:108
#define MPBUF_MEMBER_ACCESS_OPERATOR(classname)
Return pointer to buffer.
Definition: MpBuf.h:417
#define MPBUF_CONST_MEMBER_ACCESS_OPERATOR(classname)
Return readonly pointer to buffer.
Definition: MpBuf.h:422
unsigned getSamplesNumber() const
Get current number of samples in audio data.
Definition: MpAudioBuf.h:99
UtlBoolean mIsClipped
Is data in this buffer clipped or not?
Definition: MpTypes.h:97
void setEnergy(int energy)
Set normalized frame energy level.
Definition: MpAudioBuf.h:78
MpSpeechType getSpeechType() const
Get audio data type.
Definition: MpAudioBuf.h:90
void setSpeechType(MpSpeechType type)
Set audio data type.
Definition: MpAudioBuf.h:57
Smart pointer to MpDataBuf.
Definition: MpDataBuf.h:127
Buffer for raw audio data.
Definition: MpAudioBuf.h:36
int compareSamples(const MpAudioBufPtr &frame, unsigned int tolerance=0) const
compare two frames of audio to see if they are the same or similar
Definition: MpAudioBuf.cpp:32
Base class for all media buffers.
Definition: MpBuf.h:74
Begin of the MpAudioBuf type.
Definition: MpBuf.h:50
#define MPBUF_DEFAULT_CONSTRUCTOR(classname)
Default constructor - construct invalid pointer.
Definition: MpBuf.h:387
MpSpeechParams & getSpeechParams()
Get speech parameters as a structure.
Definition: MpAudioBuf.h:117
Pool of buffers.
Definition: MpBufPool.h:32
Stores data in the external buffer.
Definition: MpDataBuf.h:42