sipxmedialib  Version 3.3
MpBridgeAlgBase.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2008 SIPez LLC.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>
12 
13 #ifndef _MpBridgeAlgBase_h_
14 #define _MpBridgeAlgBase_h_
15 
16 // SYSTEM INCLUDES
17 // APPLICATION INCLUDES
18 #include "mp/MpTypes.h"
19 #include "mp/MpAudioBuf.h"
20 #include "mp/MpDspUtils.h"
21 
22 // DEFINES
23 // MACROS
24 
25 // Use Q5.10 (signed) values when fixed point is enabled.
26 #define MP_BRIDGE_INT_LENGTH INT16_C(5)
27 #define MP_BRIDGE_FRAC_LENGTH INT16_C(10)
28 #define MPF_BRIDGE_FLOAT(num) ((MpBridgeGain)MPF_FLOAT((num), MP_BRIDGE_INT_LENGTH, MP_BRIDGE_FRAC_LENGTH))
29 #define MPF_BRIDGE_MAX ((MpBridgeGain)MPF_MAX(MP_BRIDGE_INT_LENGTH, MP_BRIDGE_FRAC_LENGTH))
30 #define MPF_BRIDGE_STEP ((MpBridgeGain)MPF_STEP(MP_BRIDGE_INT_LENGTH, MP_BRIDGE_FRAC_LENGTH))
31 
32 #define MP_BRIDGE_GAIN_UNDEFINED INT16_MAX
33 #define MP_BRIDGE_GAIN_MAX MPF_BRIDGE_MAX
34 #define MP_BRIDGE_GAIN_MIN MPF_BRIDGE_FLOAT(0.0f)
35 #define MP_BRIDGE_GAIN_STEP MPF_BRIDGE_STEP
36 #define MP_BRIDGE_GAIN_MUTED MP_BRIDGE_GAIN_MIN
37 #define MP_BRIDGE_GAIN_PASSTHROUGH MPF_BRIDGE_FLOAT(1.0f)
38 
39 #define MAX_AMPLITUDE_ROUND (1<<(MP_AUDIO_SAMPLE_SIZE-1))
40 
41 // EXTERNAL FUNCTIONS
42 // EXTERNAL VARIABLES
43 // STRUCTS
44 // TYPEDEFS
45 #ifdef MP_FIXED_POINT // [
46  typedef int32_t MpBridgeAccum;
47 #else // MP_FIXED_POINT ][
48  typedef float MpBridgeAccum;
49 #endif // MP_FIXED_POINT ]
50 
51 #ifdef MP_FIXED_POINT // [
52  typedef int16_t MpBridgeGain;
53 #else // MP_FIXED_POINT ][
54  typedef float MpBridgeGain;
55 #endif // MP_FIXED_POINT ]
56 
57 // FORWARD DECLARATIONS
58 
63 {
64 /* //////////////////////////////// PUBLIC //////////////////////////////// */
65 public:
66 
67 /* =============================== CREATORS =============================== */
69 
70 
72  MpBridgeAlgBase(int maxInputs, int maxOutputs, UtlBoolean mixSilence)
73  : mMaxInputs(maxInputs)
74  , mMaxOutputs(maxOutputs)
75  , mMixSilence(mixSilence)
77  {
78  // Save magic value to the array to tell that it hasn't been initialized yet.
79  for (int i=0; i<mMaxInputs; i++)
80  {
81  mpPrevAmplitudes[i]= -1;
82  }
83  }
84 
86  virtual ~MpBridgeAlgBase()
87  {
88  delete[] mpPrevAmplitudes;
89  };
90 
92 
93 /* ============================= MANIPULATORS ============================= */
95 
96 
98  virtual UtlBoolean doMix(MpBufPtr inBufs[], int inBufsSize,
99  MpBufPtr outBufs[], int outBufsSize,
100  int samplesPerFrame) =0;
101 
103  virtual void setGainMatrixValue(int column, int row, MpBridgeGain val) =0;
104 
106  virtual void setGainMatrixRow(int row, int numValues, const MpBridgeGain val[]) =0;
107 
109  virtual void setGainMatrixColumn(int column, int numValues, const MpBridgeGain val[]) =0;
110 
112  inline void saveAmplitudes(MpBufPtr inBufs[], int inBufsSize);
113 
115 
116 /* ============================== ACCESSORS =============================== */
118 
119 
121  inline
122  int maxInputs() const;
123 
125  inline
126  int maxOutputs() const;
127 
129 
130 /* =============================== INQUIRY ================================ */
132 
133 
134 
136 
137 /* ////////////////////////////// PROTECTED /////////////////////////////// */
138 protected:
139 
142  UtlBoolean mMixSilence;
144 
146 /* /////////////////////////////// PRIVATE //////////////////////////////// */
147 private:
148 
149 
150 };
151 
152 /* ============================ INLINE METHODS ============================ */
153 
155 {
156  return mMaxInputs;
157 }
158 
160 {
161  return mMaxOutputs;
162 }
163 
164 void MpBridgeAlgBase::saveAmplitudes(MpBufPtr inBufs[], int inBufsSize)
165 {
166  assert(inBufsSize <= mMaxInputs);
167  for (int i=0; i<inBufsSize; i++)
168  {
169  if (inBufs[i].isValid())
170  {
171  MpAudioBufPtr pAudioBuf = inBufs[i];
172  MpAudioSample amplitude = pAudioBuf->getAmplitude();
173  mpPrevAmplitudes[i] = amplitude == 0 ? 1 : amplitude;
174  }
175  }
176 }
177 
178 #endif // _MpBridgeAlgBase_h_
virtual void setGainMatrixValue(int column, int row, MpBridgeGain val)=0
Set selected gain to the given value.
virtual ~MpBridgeAlgBase()
Destructor.
Definition: MpBridgeAlgBase.h:86
MpAudioSample * mpPrevAmplitudes
the previous frame processing interval.
Definition: MpBridgeAlgBase.h:143
int samplesPerFrame
int mMaxInputs
Number of possible bridge inputs.
Definition: MpBridgeAlgBase.h:140
int maxOutputs() const
Get maximum number of outputs.
Definition: MpBridgeAlgBase.h:159
void saveAmplitudes(MpBufPtr inBufs[], int inBufsSize)
Save buffers amplitudes to internal array.
Definition: MpBridgeAlgBase.h:164
float MpBridgeAccum
Definition: MpBridgeAlgBase.h:48
virtual void setGainMatrixColumn(int column, int numValues, const MpBridgeGain val[])=0
Set selected gain column to the given value.
virtual void setGainMatrixRow(int row, int numValues, const MpBridgeGain val[])=0
Set selected gain row to the given value.
int16_t MpAudioSample
Definition: MpTypes.h:44
MpBridgeAlgBase(int maxInputs, int maxOutputs, UtlBoolean mixSilence)
Constructor.
Definition: MpBridgeAlgBase.h:72
Smart pointer to MpAudioBuf.
Definition: MpAudioBuf.h:168
UtlBoolean mMixSilence
Should Bridge ignore or mix frames marked as silence?
Definition: MpBridgeAlgBase.h:142
int maxInputs() const
Get maximum number of inputs.
Definition: MpBridgeAlgBase.h:154
int mMaxOutputs
Number of possible bridge outputs.
Definition: MpBridgeAlgBase.h:141
virtual UtlBoolean doMix(MpBufPtr inBufs[], int inBufsSize, MpBufPtr outBufs[], int outBufsSize, int samplesPerFrame)=0
Mix together inputs onto outputs according to mpGainMatrix matrix.
Smart pointer to MpBuf.
Definition: MpBuf.h:160
float MpBridgeGain
Definition: MpBridgeAlgBase.h:54
Base class for the Bridge mixing algorithms.
Definition: MpBridgeAlgBase.h:62