This file is indexed.

/usr/include/sipxtapi/mp/MpDspUtils.h is in libsipxtapi-dev 3.3.0~test17-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
//  
// Copyright (C) 2007-2012 SIPez LLC.  All rights reserved.
//  
// Copyright (C) 2007-2008 SIPfoundry Inc. 
// Licensed by SIPfoundry under the LGPL license. 
//  
// $$ 
////////////////////////////////////////////////////////////////////////////// 

// Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>

#ifndef _MpDspUtils_h_
#define _MpDspUtils_h_

/// Switch between fixed and floating point math.
#define MP_FIXED_POINT
//#undef  MP_FIXED_POINT

/// Switch between inlining and non-inlining of vector operations
#define MP_DSP_INLINE_VECTOR_FUNCTIONS
//#undef MP_DSP_INLINE_VECTOR_FUNCTIONS
#ifdef MP_DSP_INLINE_VECTOR_FUNCTIONS // [
#  define MP_DSP_VECTOR_API inline
#else // MP_DSP_INLINE_VECTOR_FUNCTIONS ][
#  define MP_DSP_VECTOR_API
#endif // MP_DSP_INLINE_VECTOR_FUNCTIONS ]

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include <os/OsStatus.h>
#include <os/OsIntTypes.h>
#ifdef MP_FIXED_POINT // [
#  include <math.h>
#endif // MP_FIXED_POINT ]

// DEFINES
#define MPF_SIGN_BIT16  (1<<15)
#define MPF_SIGN_BIT32  (1<<31)

// MACROS
#ifdef MP_FIXED_POINT // [
#  define MPF_FLOAT(num, intLength, fracLength) (floor((num)*(float)(1<<(fracLength))))
#else  // MP_FIXED_POINT ][
#  define MPF_FLOAT(num, intLength, fracLength) (num)
#endif // MP_FIXED_POINT ]

#define MPF_STEP(intLength, fracLength)    MPF_FLOAT(1.0/(1<<(fracLength)), (intLength), (fracLength))
#define MPF_MAX(intLength, fracLength)     MPF_FLOAT((1<<(intLength))-1.0/(1<<(fracLength)), (intLength), (fracLength))

  /// Saturate \p val to [-maxval;maxval] range.
  /**
  *  @note This does not touch type of the data.
  *  @note DSPs are usually saturate to [-maxval-1;maxval] range, but this will
  *        lead to problems when negating negative saturated value. That is
  *        -(-maxval-1) may wrap to 0. So, we saturate to [-maxval;maxval] range.
  */
#define MPF_SATURATE(val, maxval) ((val)>=(maxval) ? (maxval) : (val)<-(maxval) ? -(maxval) : (val))
  /// Saturate \p val to fit 16-bit signed integer.
  /**
  *  @see MPF_SATURATE()
  */
#define MPF_SATURATE16(val) MPF_SATURATE(val, INT16_MAX)
  /// Saturate \p val to fit 32-bit signed integer. This does not touch type of the data.
  /**
  *  @see MPF_SATURATE()
  */
#define MPF_SATURATE32(val) MPF_SATURATE(val, INT32_MAX)

  /// Return 16 bit integer.
  /**
  *  In debug mode this will be used to check values. So, use it when appropriate.
  */
#define MPF_EXTRACRT16(val) ((int16_t)(val))

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STRUCTS
// TYPEDEFS
// FORWARD DECLARATIONS

/**
*  @brief Class for generic DSP functions.
*
*  This is utils class, containing only static functions. It provide all DSP
*  processing primitives we need, and meant to be good optimized. In fact,
*  we want this to be only place, which will contain hardware specific
*  speed optimizations. If you could not find what you need here - feel free
*  to add it. But do not forget to add generic C-version of each function,
*  so it will be available if there is no optimized version.
*
*  <H3>Namig conventions.</H3>
*
*  If function ends with \c I it is in-place function. That is its destination
*  is one of source vectors (usually second). If function ends with \c Gain or 
*  \c Att and its source is integers, it is scaling function. That is it scale
*  source vector up or down (gain or attenuate, respectively) before operation.
*  Functions, where source vector is float never scale values, even with \c Gain
*  or \c Att suffix. Their \c Gain and \c Att versions are provided to simplify
*  writing of universal floating/fixed-point code.
*
*  <H3>Saturation.</H3>
*
*  All arithmetic functions saturate result if destination is integer value
*  (that is for 8-bit unsigned data type <tt>200+200=255</tt>). Functions do not
*  saturate result if destination is floating point.
*
*  <H3>Unittest coverage.</H3>
*
*  All functions should be covered by unittests. If you implemented optimized
*  version of some function, run unittests to check does your optimized version
*  behave as expected. If unittests does not cover all paths inside your
*  optimized function, add or modify unittests to cover all of them and check
*  does your function behave the same as original one. If optimized version
*  behave differently from original function and this is wanted behaviour,
*  this is different function in fact. And so you should give it different name.
*  When creating new function, do not forget to provide clean C implementation
*  for convenience.
*
*  @warning Please, keep all methods of this class static and stateless!
*/
class MpDspUtils
{
/* //////////////////////////////// PUBLIC //////////////////////////////// */
public:

/* ========================= Arithmetic Functions ========================= */
///@name Arithmetic Functions
//@{

     /// Return (a+b) saturated (16-bit).
   static inline
   int16_t add(int16_t a, int16_t b);

     /// Perform (a+=b) saturated (16-bit).
   static inline
   void add_I(int16_t &a, int16_t b);

     /// Return (a+b) saturated (32-bit).
   static inline
   int32_t add(int32_t a, int32_t b);

     /// Perform (a+=b) saturated (32-bit).
   static inline
   void add_I(int32_t &a, int32_t b);

     /// Perform (a+=b*c) saturated (32-bit accumulator, 16-bit operands).
   static inline
   void addMul_I(int32_t &a, int16_t b, int16_t c);

#ifndef MP_FIXED_POINT // [

     /// Return (a+b) NOT saturated (float).
   static inline
   float add(float a, float b);

     /// Perform (a+=b) NOT saturated (float).
   static inline
   void add_I(float &a, float b);

     /// Perform (a+=b*c) saturated (float).
   static inline
   void addMul_I(float &a, float b, float c);

#endif // !MP_FIXED_POINT ]

     /// Perform absolute value calculation with saturation
   static inline
   int16_t abs(int16_t a);
     /**<
     *  This function differs from usual ::abs() because it saturates INT16_MIN
     *  value. This is essential in DSP calculations, because -INT16_MIN equals
     *  to 0 in IEEE format. Thus with this implementation
     *  abs(INT16_MIN) = INT16_MAX
     */

     /// Perform minimum value calculation
   static inline
   int16_t minimum(int16_t a, int16_t b);

     /// Perform maximum value calculation
   static inline
   int16_t maximum(int16_t a, int16_t b);

     /// Perform absolute value calculation with saturation
   static inline
   int32_t abs(int32_t a);
     /**<
     *  This function differs from usual ::abs() because it saturates INT32_MIN
     *  value. This is essential in DSP calculations, because -INT32_MIN equals
     *  to 0 in IEEE format. Thus with this implementation
     *  abs(INT32_MIN) = INT32_MAX
     */

     /// Perform minimum value calculation
   static inline
   int32_t minimum(int32_t a, int32_t b);

     /// Perform maximum value calculation
   static inline
   int32_t maximum(int32_t a, int32_t b);

     /// Integer square root.
   static inline
   uint32_t sqrt(uint32_t val);

//@}

/* ======================= Serial Number Arithmetic ======================= */
///@name Serial Number Arithmetic (Arithmetic with Overflow)
//@{

      /// Is \p val1 bigger, equal or lesser then \p val2.
   static inline
   int compareSerials(uint32_t val1, uint32_t val2);
      /**<
      *  This function should be used when comparing two values that may
      *  overflow. It assume that values could not differ by more then half
      *  of their maximum value. See RFC1982 Serial Number Arithmetic
      *  for better description and rules of use.
      *
      *  @retval  0 if val1 == val2
      *  @retval  1 if val1 \> val2
      *  @retval -1 if val1 \< val2
      *
      *  @todo Write unittest!!!
      */

      /// @copydoc compareSerials(uint32_t,uint32_t)
   static inline
   int compareSerials(uint16_t val1, uint16_t val2);

//@}

/* ================== Vector Logical and Shift Functions ================== */
///@name Vector Logical and Shift Functions
//@{

   static inline
   void shl16_I(int32_t &a, unsigned scale);
     /**<
     *  @todo Write unittest!!!
     */

   static inline
   int32_t shl16(int32_t a, unsigned scale);
     /**<
     *  @todo Write unittest!!!
     */

   static inline
   void shl32_I(int32_t &a, unsigned scale);
     /**<
     *  @todo Write unittest!!!
     */

   static inline
   int32_t shl32(int32_t a, unsigned scale);
     /**<
     *  @todo Write unittest!!!
     */

//@}

/* ====================== Vector Arithmetic Functions ===================== */
///@name Vector Arithmetic Functions
//@{

#ifdef MP_FIXED_POINT // [

     /// Add source vector to accumulator.
   static MP_DSP_VECTOR_API
   OsStatus add_I(const int16_t *pSrc1, int32_t *pSrc2Dst, int dataLength);

     /// Gain source vector by 2^src1ScaleFactor factor and add it to accumulator.
   static MP_DSP_VECTOR_API
   OsStatus add_IGain(const int16_t *pSrc1, int32_t *pSrc2Dst, int dataLength, unsigned src1ScaleFactor);

     /// Attenuate source vector by 2^src1ScaleFactor factor and add it to accumulator.
   static MP_DSP_VECTOR_API
   OsStatus add_IAtt(const int16_t *pSrc1, int32_t *pSrc2Dst, int dataLength, unsigned src1ScaleFactor);

     /// Add two vectors.
   static MP_DSP_VECTOR_API
   OsStatus add(const int32_t *pSrc1, const int32_t *pSrc2, int32_t *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Multiply source vector by given \p val and add it to accumulator vector.
   static MP_DSP_VECTOR_API
   OsStatus addMul_I(const int16_t *pSrc1, int16_t val, int32_t *pSrc2Dst, int dataLength);

     /// @brief Multiply source vector by values linearly changing from
     /// \p valStart to \p valEnd and add it to accumulator vector.
   static MP_DSP_VECTOR_API
   OsStatus addMulLinear_I(const int16_t *pSrc1, int16_t valStart, int16_t valEnd,
                           int32_t *pSrc2Dst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     *  @note Current implementation works correctly only when
     *        (dataLength << (valStart - valEnd)). See implementation for
     *        further discussion.
     */

     /// Multiply vector by constant.
   static MP_DSP_VECTOR_API
   OsStatus mul(const int16_t *pSrc, const int16_t val, int32_t *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Multiply vector by constant with saturation.
   static MP_DSP_VECTOR_API
   OsStatus mul_I(int16_t *pSrcDst, const int16_t val, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// @brief Multiply source vector by values linearly changing from
     /// \p valStart to \p valEnd and add it to accumulator vector.
   static MP_DSP_VECTOR_API
   OsStatus mulLinear(const int16_t *pSrc, int16_t valStart, int16_t valEnd,
                      int32_t *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     *  @note Current implementation works correctly only when
     *        (dataLength << (valStart - valEnd)). See implementation for
     *        further discussion.
     */

#else  // MP_FIXED_POINT ][

     /// Add source vector to accumulator.
   static MP_DSP_VECTOR_API
   OsStatus add_I(const int16_t *pSrc1, float *pSrc2Dst, int dataLength);

     /// Stub for fixed-point mode compatibility. It DOES NOT gain values.
   static inline
   OsStatus add_IGain(const int16_t *pSrc1, float *pSrc2Dst, int dataLength, unsigned src1ScaleFactor)
   {
      return add_I(pSrc1, pSrc2Dst, dataLength);
   }

     /// Stub for fixed-point mode compatibility. It DOES NOT attenuate values.
   static inline
   OsStatus add_IAtt(const int16_t *pSrc1, float *pSrc2Dst, int dataLength, unsigned src1ScaleFactor)
   {
      return add_I(pSrc1, pSrc2Dst, dataLength);
   }

     /// Add two vectors.
   static MP_DSP_VECTOR_API
   OsStatus add(const float *pSrc1, const float *pSrc2, float *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Multiply source vector by given \p val and add it to accumulator.
   static MP_DSP_VECTOR_API
   OsStatus addMul_I(const int16_t *pSrc1, float val, float *pSrc2Dst, int dataLength);

     /// @brief Multiply source vector by values linearly changing from
     /// \p valStart to \p valEnd and add it to accumulator vector.
   static MP_DSP_VECTOR_API
   OsStatus addMulLinear_I(const int16_t *pSrc1, float valStart, float valEnd,
                           float *pSrc2Dst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Multiply vector by constant.
   static MP_DSP_VECTOR_API
   OsStatus mul(const int16_t *pSrc, const float val, float *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// @brief Multiply source vector by values linearly changing from
     /// \p valStart to \p valEnd and add it to accumulator vector.
   static MP_DSP_VECTOR_API
   OsStatus mulLinear(const int16_t *pSrc, float valStart, float valEnd,
                      float *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     *  @note Current implementation works correctly only when
     *        (dataLength << (valStart - valEnd)). See implementation for
     *        further discussion.
     */

#endif // MP_FIXED_POINT ]

     /// Calculate absolute maximum value of array
   static inline
   int maxAbs(const int16_t *pSrc, int dataLength);
     /**<
     * @note Result value is int because of inverting (-max_val-1) problem
     */

     /// Calculate maximum value of array
   static inline
   int16_t maximum(const int16_t *pSrc, int dataLength);

     /// Calculate maximum value of array
   static inline
   int32_t maximum(const int32_t *pSrc, int dataLength);

     /// Calculate maximum value of array
   static inline
   int16_t minimum(const int16_t *pSrc, int dataLength);

     /// Calculate maximum value of array
   static inline
   int32_t minimum(const int32_t *pSrc, int dataLength);

    /// Find the number of values in vector that are at maximum or minimum 16 bit value
   static inline
   int32_t countClippedValues(const int16_t *pSrc, int dataLength);

//@}

/* ====================== Vector Conversion Functions ===================== */
///@name Vector Conversion Functions
//@{

#ifdef MP_FIXED_POINT // [

     /// Convert vector of 32-bit integers to 16-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert(const int32_t *pSrc, int16_t *pDst, int dataLength);

     /// Gain vector of 32-bit integers and convert them to 16-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert_Gain(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor);

     /// Attenuate vector of 32-bit integers and convert them to 16-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert_Att(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor);

     /// Convert vector of 16-bit integers to 32-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert(const int16_t *pSrc, int32_t *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Gain vector of 16-bit integers and convert them to 32-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert_Gain(const int16_t *pSrc, int32_t *pDst, int dataLength, unsigned srcScaleFactor);
     /**<
     *  @todo Write unittest!!!
     */

     /// Attenuate vector of 16-bit integers and convert them to 32-bit integers.
   static MP_DSP_VECTOR_API
   OsStatus convert_Att(const int16_t *pSrc, int32_t *pDst, int dataLength, unsigned srcScaleFactor);
     /**<
     *  @todo Write unittest!!!
     */

#else  // MP_FIXED_POINT ][

     /// Convert type of source vector.
   static MP_DSP_VECTOR_API
   OsStatus convert(const float *pSrc, int16_t *pDst, int dataLength);

     /// Stub for fixed-point mode compatibility. It DOES NOT gains values.
   static inline
   OsStatus convert_Gain(const float *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
   {
      return convert(pSrc, pDst, dataLength);
   }

     /// Stub for fixed-point mode compatibility. It DOES NOT attenuate values.
   static inline
   OsStatus convert_Att(const float *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
   {
      return convert(pSrc, pDst, dataLength);
   }

     /// Convert type of source vector.
   static MP_DSP_VECTOR_API
   OsStatus convert(const int16_t *pSrc, float *pDst, int dataLength);
     /**<
     *  @todo Write unittest!!!
     */

     /// Stub for fixed-point mode compatibility. It DOES NOT gains values.
   static inline
   OsStatus convert_Gain(const int16_t *pSrc, float *pDst, int dataLength, unsigned srcScaleFactor)
   {
      return convert(pSrc, pDst, dataLength);
   }

     /// Stub for fixed-point mode compatibility. It DOES NOT attenuate values.
   static inline
   OsStatus convert_Att(const int16_t *pSrc, float *pDst, int dataLength, unsigned srcScaleFactor)
   {
      return convert(pSrc, pDst, dataLength);
   }

#endif // MP_FIXED_POINT ]

//@}

};

/* ============================ INLINE METHODS ============================ */

#include <mp/MpDspUtilsConvertVect.h>
#include <mp/MpDspUtilsIntSqrt.h>
#include <mp/MpDspUtilsSum.h>
#include <mp/MpDspUtilsSumVect.h>
#include <mp/MpDspUtilsShift.h>
#include <mp/MpDspUtilsSerials.h>

#endif  // _MpDspUtils_h_