Coverage Report

Created: 2025-07-11 06:54

/src/aac/libSACenc/src/sacenc_vectorfunctions.h
Line
Count
Source (jump to first uncovered line)
1
/* -----------------------------------------------------------------------------
2
Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4
© Copyright  1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
5
Forschung e.V. All rights reserved.
6
7
 1.    INTRODUCTION
8
The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9
that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10
scheme for digital audio. This FDK AAC Codec software is intended to be used on
11
a wide variety of Android devices.
12
13
AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14
general perceptual audio codecs. AAC-ELD is considered the best-performing
15
full-bandwidth communications codec by independent studies and is widely
16
deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17
specifications.
18
19
Patent licenses for necessary patent claims for the FDK AAC Codec (including
20
those of Fraunhofer) may be obtained through Via Licensing
21
(www.vialicensing.com) or through the respective patent owners individually for
22
the purpose of encoding or decoding bit streams in products that are compliant
23
with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24
Android devices already license these patent claims through Via Licensing or
25
directly from the patent owners, and therefore FDK AAC Codec software may
26
already be covered under those patent licenses when it is used for those
27
licensed purposes only.
28
29
Commercially-licensed AAC software libraries, including floating-point versions
30
with enhanced sound quality, are also available from Fraunhofer. Users are
31
encouraged to check the Fraunhofer website for additional applications
32
information and documentation.
33
34
2.    COPYRIGHT LICENSE
35
36
Redistribution and use in source and binary forms, with or without modification,
37
are permitted without payment of copyright license fees provided that you
38
satisfy the following conditions:
39
40
You must retain the complete text of this software license in redistributions of
41
the FDK AAC Codec or your modifications thereto in source code form.
42
43
You must retain the complete text of this software license in the documentation
44
and/or other materials provided with redistributions of the FDK AAC Codec or
45
your modifications thereto in binary form. You must make available free of
46
charge copies of the complete source code of the FDK AAC Codec and your
47
modifications thereto to recipients of copies in binary form.
48
49
The name of Fraunhofer may not be used to endorse or promote products derived
50
from this library without prior written permission.
51
52
You may not charge copyright license fees for anyone to use, copy or distribute
53
the FDK AAC Codec software or your modifications thereto.
54
55
Your modified versions of the FDK AAC Codec must carry prominent notices stating
56
that you changed the software and the date of any change. For modified versions
57
of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58
must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59
AAC Codec Library for Android."
60
61
3.    NO PATENT LICENSE
62
63
NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64
limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65
Fraunhofer provides no warranty of patent non-infringement with respect to this
66
software.
67
68
You may use this FDK AAC Codec software or modifications thereto only for
69
purposes that are authorized by appropriate patent licenses.
70
71
4.    DISCLAIMER
72
73
This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74
holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75
including but not limited to the implied warranties of merchantability and
76
fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77
CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78
or consequential damages, including but not limited to procurement of substitute
79
goods or services; loss of use, data, or profits, or business interruption,
80
however caused and on any theory of liability, whether in contract, strict
81
liability, or tort (including negligence), arising in any way out of the use of
82
this software, even if advised of the possibility of such damage.
83
84
5.    CONTACT INFORMATION
85
86
Fraunhofer Institute for Integrated Circuits IIS
87
Attention: Audio and Multimedia Departments - FDK AAC LL
88
Am Wolfsmantel 33
89
91058 Erlangen, Germany
90
91
www.iis.fraunhofer.de/amm
92
amm-info@iis.fraunhofer.de
93
----------------------------------------------------------------------------- */
94
95
/*********************** MPEG surround encoder library *************************
96
97
   Author(s):   Josef Hoepfl
98
99
   Description: Encoder Library Interface
100
                vector functions
101
102
*******************************************************************************/
103
104
/*****************************************************************************
105
\file
106
This file contains vector functions
107
******************************************************************************/
108
109
#ifndef SACENC_VECTORFUNCTIONS_H
110
#define SACENC_VECTORFUNCTIONS_H
111
112
/* Includes ******************************************************************/
113
#include "common_fix.h"
114
115
/* Defines *******************************************************************/
116
0
#define SUM_UP_STATIC_SCALE 0
117
0
#define SUM_UP_DYNAMIC_SCALE 1
118
119
/* Data Types ****************************************************************/
120
121
/* Constants *****************************************************************/
122
123
/* Function / Class Declarations *********************************************/
124
125
/**
126
 * \brief          Vector function : Sum up complex power
127
 *
128
 *                 Description : ret = sum( re{X[i]} * re{X[i]} + im{X[i]} *
129
 * im{X[i]} ),  i=0,...,n-1 ret is scaled by outScaleFactor
130
 *
131
 * \param          const FIXP_DPK x[]
132
 *                 Input: complex vector of the length n
133
 *
134
 * \param          int scaleMode
135
 *                 Input: choose static or dynamic scaling
136
 * (SUM_UP_DYNAMIC_SCALE/SUM_UP_STATIC_SCALE)
137
 *
138
 * \param          int inScaleFactor
139
 *                 Input: determine headroom bits for the complex input vector
140
 *
141
 * \param          int outScaleFactor
142
 *                 Output: complete scaling in energy calculation
143
 *
144
 * \return         FIXP_DBL ret
145
 */
146
FIXP_DBL sumUpCplxPow2(const FIXP_DPK *const x, const INT scaleMode,
147
                       const INT inScaleFactor, INT *const outScaleFactor,
148
                       const INT n);
149
150
/**
151
 * \brief          Vector function : Sum up complex power
152
 *
153
 *                 Description : ret = sum( re{X[i][j]} * re{X[i][]} +
154
 * im{X[i][]} * im{X[i][]} ),  i=sDim1,...,nDim1-1 i=sDim2,...,nDim2-1 ret is
155
 * scaled by outScaleFactor
156
 *
157
 * \param          const FIXP_DPK x[]
158
 *                 Input: complex vector of the length n
159
 *
160
 * \param          int scaleMode
161
 *                 Input: choose static or dynamic scaling
162
 * (SUM_UP_DYNAMIC_SCALE/SUM_UP_STATIC_SCALE)
163
 *
164
 * \param          int inScaleFactor
165
 *                 Input: determine headroom bits for the complex input vector
166
 *
167
 * \param          int outScaleFactor
168
 *                 Output: complete scaling in energy calculation
169
 *
170
 * \param          int sDim1
171
 *                 Input: start index for loop counter in dimension 1
172
 *
173
 * \param          int nDim1
174
 *                 Input: loop counter in dimension 1
175
 *
176
 * \param          int sDim2
177
 *                 Input: start index for loop counter in dimension 2
178
 *
179
 * \param          int nDim2
180
 *                 Input: loop counter in dimension 2
181
 *
182
 * \return         FIXP_DBL ret
183
 */
184
FIXP_DBL sumUpCplxPow2Dim2(const FIXP_DPK *const *const x, const INT scaleMode,
185
                           const INT inScaleFactor, INT *const outScaleFactor,
186
                           const INT sDim1, const INT nDim1, const INT sDim2,
187
                           const INT nDim2);
188
189
/**
190
 * \brief          Vector function : Z[i] = X[i],  i=0,...,n-1
191
 *
192
 *                 Description : re{Z[i]} = re{X[i]},  i=0,...,n-1
193
 *                               im{Z[i]} = im{X[i]},  i=0,...,n-1
194
 *
195
 *                 Copy complex vector X[] to complex vector Z[].
196
 *                 It is allowed to overlay X[] with Z[].
197
 *
198
 * \param          FIXP_DPK Z[]
199
 *                 Output: vector of the length n
200
 *
201
 * \param          const FIXP_DPK X[]
202
 *                 Input: vector of the length n
203
 *
204
 * \param          int n
205
 *                 Input: length of vector Z[] and X[]
206
 *
207
 * \return         void
208
 */
209
void copyCplxVec(FIXP_DPK *const Z, const FIXP_DPK *const X, const INT n);
210
211
/**
212
 * \brief          Vector function : Z[i] = a,  i=0,...,n-1
213
 *
214
 *                 Description : re{Z[i]} = a,  i=0,...,n-1
215
 *                               im{Z[i]} = a,  i=0,...,n-1
216
 *
217
 *                 Set real and imaginary part of the complex value Z to a.
218
 *
219
 * \param          FIPX_DPK Z[]
220
 *                 Output: vector of the length n
221
 *
222
 * \param          const FIXP_DBL a
223
 *                 Input: constant value
224
 *
225
 * \param          int n
226
 *                 Input: length of vector Z[]
227
 *
228
 * \return         void
229
 */
230
void setCplxVec(FIXP_DPK *const Z, const FIXP_DBL a, const INT n);
231
232
/**
233
 * \brief          Vector function : Calculate complex-valued result of complex
234
 * scalar product
235
 *
236
 *                 Description : re{Z} = sum( re{X[i]} * re{Y[i]} + im{X[i]} *
237
 * im{Y[i]},  i=0,...,n-1 ) im{Z} = sum( im{X[i]} * re{Y[i]} - re{X[i]} *
238
 * im{Y[i]},  i=0,...,n-1 )
239
 *
240
 *                 The function returns the complex-valued result of the complex
241
 * scalar product at the address of Z. The result is scaled by scaleZ.
242
 *
243
 * \param          FIXP_DPK *Z
244
 *                 Output: pointer to Z
245
 *
246
 * \param          const FIXP_DPK *const *const X
247
 *                 Input: vector of the length n
248
 *
249
 * \param          const FIXP_DPK *const *const Y
250
 *                 Input: vector of the length n
251
 *
252
 * \param          int scaleX
253
 *                 Input: scalefactor of vector X[]
254
 *
255
 * \param          int scaleY
256
 *                 Input: scalefactor of vector Y[]
257
 *
258
 * \param          int scaleZ
259
 *                 Output: scalefactor of vector Z[]
260
 *
261
 * \param          int sDim1
262
 *                 Input: start index for loop counter in dimension 1
263
 *
264
 * \param          int nDim1
265
 *                 Input: loop counter in dimension 1
266
 *
267
 * \param          int sDim2
268
 *                 Input: start index for loop counter in dimension 2
269
 *
270
 * \param          int nDim2
271
 *                 Input: loop counter in dimension 2
272
 *
273
 * \return         void
274
 */
275
void cplx_cplxScalarProduct(FIXP_DPK *const Z, const FIXP_DPK *const *const X,
276
                            const FIXP_DPK *const *const Y, const INT scaleX,
277
                            const INT scaleY, INT *const scaleZ,
278
                            const INT sDim1, const INT nDim1, const INT sDim2,
279
                            const INT nDim2);
280
281
/**
282
 * \brief          Vector function : Calculate correlation
283
 *
284
 *                 Description : z[i] = pr12[i] / sqrt(p1[i]*p2[i]) ,
285
 * i=0,...,n-1
286
 *
287
 * \param          FIXP_DBL z[]
288
 *                 Output: vector of length n
289
 *
290
 * \param          const FIXP_DBL pr12[]
291
 *                 Input: vector of the length n
292
 *
293
 * \param          const FIXP_DBL p1[]
294
 *                 Input: vector of the length n
295
 *
296
 * \param          const FIXP_DBL p2[]
297
 *                 Input: vector of the length n
298
 *
299
 * \param          int n
300
 *                 Input: length of vector pr12[], p1[] and p2[]
301
 *
302
 * \return         void
303
 */
304
void FDKcalcCorrelationVec(FIXP_DBL *const z, const FIXP_DBL *const pr12,
305
                           const FIXP_DBL *const p1, const FIXP_DBL *const p2,
306
                           const INT n);
307
308
/**
309
 * \brief          Vector function : Calculate coherence
310
 *
311
 *                 Description : z[i] = sqrt( (p12r[i]*p12r[i] +
312
 * p12i[i]*p12i[i]) / (p1[i]*p2[i]) ),  i=0,...,n-1
313
 *
314
 * \param          FIXP_DBL z[]
315
 *                 Output: vector of length n
316
 *
317
 * \param          const FIXP_DBL p12r[]
318
 *                 Input: vector of the length n
319
 *
320
 * \param          const FIXP_DBL p12i[]
321
 *                 Input: vector of the length n
322
 *
323
 * \param          const FIXP_DBL p1[]
324
 *                 Input: vector of the length n
325
 *
326
 * \param          const FIXP_DBL p2[]
327
 *                 Input: vector of the length n
328
 *
329
 * \param          int scaleP12[]
330
 *                 Input: scalefactor of p12r and p12i
331
 *
332
 * \param          int scaleP
333
 *                 Input: scalefactor of p1 and p2
334
 *
335
 * \param          int n
336
 *                 Input: length of vector p12r[], p12i[], p1[] and p2[]
337
 *
338
 * \return         void
339
 */
340
void calcCoherenceVec(FIXP_DBL *const z, const FIXP_DBL *const p12r,
341
                      const FIXP_DBL *const p12i, const FIXP_DBL *const p1,
342
                      const FIXP_DBL *const p2, const INT scaleP12,
343
                      const INT scaleP, const INT n);
344
345
/**
346
 * \brief          Vector function : Z[j][i] = a[pb] * X[j][i] + b[pb] *
347
 * Y[j][i],  j=0,...,nHybridBands-1;  i=startTimeSlot,...,nTimeSlots-1;
348
 * pb=0,...,nParameterBands-1
349
 *
350
 *                 Description : re{Z[j][i]} = a[pb] * re{X[j][i]} + b[pb] *
351
 * re{Y[j][i]},  j=0,...,nHybridBands-1;  i=startTimeSlot,...,nTimeSlots-1;
352
 * pb=0,...,nParameterBands-1 im{Z[j][i]} = a[pb] * im{X[j][i]} + b[pb] *
353
 * im{Y[j][i]},  j=0,...,nHybridBands-1;
354
 * i=startTimeSlot,...,nTimeSlots-1;  pb=0,...,nParameterBands-1
355
 *
356
 *                 It is allowed to overlay X[] or Y[] with Z[]. The scalefactor
357
 * of channel 1 is updated with the common scalefactor of channel 1 and
358
 * channel 2.
359
 *
360
 * \param          FIXP_DPK **Z
361
 *                 Output: vector of the length nHybridBands*nTimeSlots
362
 *
363
 * \param          const FIXP_DBL *a
364
 *                 Input: vector of length nParameterBands
365
 *
366
 * \param          const FIXP_DPK **X
367
 *                 Input: vector of the length nHybridBands*nTimeSlots
368
 *
369
 * \param          const FIXP_DBL *b
370
 *                 Input: vector of length nParameterBands
371
 *
372
 * \param          const FIXP_DPK **Y
373
 *                 Input: vector of the length nHybridBands*nTimeSlots
374
 *
375
 * \param          int scale
376
 *                 Input: scale of vector a and b
377
 *
378
 * \param          int *scaleCh1
379
 *                 Input: scale of ch1
380
 *
381
 * \param          int scaleCh2
382
 *                 Input: scale of ch2
383
 *
384
 * \param          UCHAR *pParameterBand2HybridBandOffset
385
 *                 Input: vector of length nParameterBands
386
 *
387
 * \param          int nTimeSlots
388
 *                 Input: number of time slots
389
 *
390
 * \param          int startTimeSlot
391
 *                 Input: start time slot
392
 *
393
 * \return         void
394
 */
395
void addWeightedCplxVec(FIXP_DPK *const *const Z, const FIXP_DBL *const a,
396
                        const FIXP_DPK *const *const X, const FIXP_DBL *const b,
397
                        const FIXP_DPK *const *const Y, const INT scale,
398
                        INT *const scaleCh1, const INT scaleCh2,
399
                        const UCHAR *const pParameterBand2HybridBandOffset,
400
                        const INT nParameterBands, const INT nTimeSlots,
401
                        const INT startTimeSlot);
402
403
/**
404
 * \brief          Vector function : Calculate the headroom of a complex vector
405
 * in a parameter band grid
406
 *
407
 * \param          FIXP_DPK **x
408
 *                 Input: pointer to complex input vector
409
 *
410
 * \param          UCHAR *pParameterBand2HybridBandOffset
411
 *                 Input: pointer to hybrid band offsets
412
 *
413
 * \param          int *outScaleFactor
414
 *                 Input: pointer to ouput scalefactor
415
 *
416
 * \param          int startTimeSlot
417
 *                 Input: start time slot
418
 *
419
 * \param          int nTimeSlots
420
 *                 Input: number of time slot
421
 *
422
 * \param          int nParamBands
423
 *                 Input: number of parameter bands
424
 *
425
 * \return         void
426
 */
427
void FDKcalcPbScaleFactor(const FIXP_DPK *const *const x,
428
                          const UCHAR *const pParameterBand2HybridBandOffset,
429
                          INT *const outScaleFactor, const INT startTimeSlot,
430
                          const INT nTimeSlots, const INT nParamBands);
431
432
/**
433
 * \brief          Vector function : Calculate the common headroom of two
434
 * sparate vectors
435
 *
436
 * \param          FIXP_DBL *x
437
 *                 Input: pointer to first input vector
438
 *
439
 * \param          FIXP_DBL *y
440
 *                 Input: pointer to second input vector
441
 *
442
 * \param          int n
443
 *                 Input: number of samples
444
 *
445
 * \return         int headromm in bits
446
 */
447
INT FDKcalcScaleFactor(const FIXP_DBL *const x, const FIXP_DBL *const y,
448
                       const INT n);
449
450
/**
451
 * \brief          Vector function : Calculate the headroom of a complex vector
452
 *
453
 * \param          FIXP_DPK *x
454
 *                 Input: pointer to complex input vector
455
 *
456
 * \param          INT startBand
457
 *                 Input: start band
458
 *
459
 * \param          INT bands
460
 *                 Input: number of bands
461
 *
462
 * \return         int headromm in bits
463
 */
464
INT FDKcalcScaleFactorDPK(const FIXP_DPK *RESTRICT x, const INT startBand,
465
                          const INT bands);
466
467
/* Function / Class Definition ***********************************************/
468
template <class T>
469
inline void FDKmemcpy_flex(T *const dst, const INT dstStride,
470
                           const T *const src, const INT srcStride,
471
0
                           const INT nSamples) {
472
0
  int i;
473
474
0
  for (i = 0; i < nSamples; i++) {
475
0
    dst[i * dstStride] = src[i * srcStride];
476
0
  }
477
0
}
Unexecuted instantiation: void FDKmemcpy_flex<int>(int*, int, int const*, int, int)
Unexecuted instantiation: void FDKmemcpy_flex<short>(short*, int, short const*, int, int)
478
479
template <class T>
480
0
inline void FDKmemset_flex(T *const x, const T c, const INT nSamples) {
481
0
  int i;
482
483
0
  for (i = 0; i < nSamples; i++) {
484
0
    x[i] = c;
485
0
  }
486
0
}
487
488
#endif /* SACENC_VECTORFUNCTIONS_H */