| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_MiscUtils.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 * Copyright 2013-2015, 2018, 2023 Avid Technology, Inc.
4 * All rights reserved.
5 *
6 * CONFIDENTIAL: this document contains confidential information of Avid. Do
7 * not disclose to any third party. Use of the information contained in this
8 * document is subject to an Avid SDK license.
9 */
10
17/*================================================================================================*/
18#pragma once
19
20#ifndef AAX_MISCUTILS_H
21#define AAX_MISCUTILS_H
22
23#include "AAX_PlatformOptimizationConstants.h"
24#include "AAX_Constants.h"
25
26#if defined(_MSC_VER)
27 #define DECLARE_ALIGNED(t,v,x) __declspec(align(x)) t v
28// #define DECLARE_ALIGNED(t,v,x) t v
29#elif defined (__GNUC__)
30 #define DECLARE_ALIGNED(t,v,x) t v __attribute__ ((aligned (x)))
31// #define DECLARE_ALIGNED(t,v,x) t v
32#elif defined (_TMS320C6X)
33 #define DECLARE_ALIGNED(t,v,x) t v
34 #warn "DECLARE_ALIGNED macro does not currently align data on TI"
35#else
36 #error "DigiError: Please port the DECLARE_ALIGNED macro to this platform"
37#endif
38
39
45#ifdef _TMS320C6X
46#define AAX_ALIGNMENT_HINT(a,b) std::_nassert(((int)(a) % b) == 0)
47#define AAX_WORD_ALIGNED_HINT(a) AAX_ALIGNMENT_HINT(a,4)
48#define AAX_DWORD_ALIGNED_HINT(a) AAX_ALIGNMENT_HINT(a,8)
49#else
50#define AAX_ALIGNMENT_HINT(a,b)
51#define AAX_WORD_ALIGNED_HINT(a)
52#define AAX_DWORD_ALIGNED_HINT(a)
53#endif
54
60#ifdef _TMS320C6X
61#define AAX_LO(x) (_itof(_lo((_amemd8_const(&x)))))
62#define AAX_HI(x) (_itof(_hi((_amemd8_const(&x)))))
63#define AAX_INT_LO(x) (_lo((_amemd8_const(&x))))
64#define AAX_INT_HI(x) (_hi((_amemd8_const(&x))))
65#else //for non-TI systems increment pointer by 4-bytes to simulate hi-word access
66#define AAX_LO(x) x
67#define AAX_HI(x) *((const_cast<float*>(&x))+1)
68#define AAX_INT_LO(x) x
69#define AAX_INT_HI(x) *((const_cast<int32_t*>(reinterpret_cast<const int32_t*>(&x)))+1)
70#endif
71
72
73
74
75 namespace AAX
76{
77
78 template<class GFLOAT>
79 inline GFLOAT ClampToZero(GFLOAT iValue, GFLOAT iClampThreshold)
80{
81 return (iValue < iClampThreshold && iValue > -iClampThreshold) ? 0.0 : iValue;
82}
83
84/*template<class GFLOAT>
85 class SmoothingFilter
86{
87 public:
88 SmoothingFilter() { Reset(); }
89 void Reset(void) { mYnm1=0.0; }
90 void Reset(double iInitialState) { mYnm1=iInitialState; }
91 void SetSmothingRate(double iFrequency, double iSampleRate) { mZeroCoef = 1.0-std::exp(iFrequency*-cTwoPi/iSampleRate); }
92 void SetSmoothingCoeff(GFLOAT b0) { mZeroCoef = b0; }
93 inline GFLOAT Smooth(GFLOAT iInput)
94 {
95 mYnm1 += mZeroCoef * (iInput - mYnm1);
96 DeDenormal(mYnm1);
97 return (GFLOAT)mYnm1;
98 }
99
100 private:
101 double mYnm1; // y[n-1]
102 GFLOAT mZeroCoef;
103};*/
104
105 inline void ZeroMemorySW(void* iPointer, int iNumBytes)
106{
107 char* aCharPointer=static_cast<char*>(iPointer);
108
109 for(int aIndex=0; aIndex<iNumBytes; aIndex++)
110 {
111 *aCharPointer=0;
112 aCharPointer++;
113 }
114}
115
116//Warning: the number of bytes passed in must be multiple of 4
117 inline void ZeroMemoryDW(void* iPointer, int iNumBytes)
118{
119 int* aDWPointer=static_cast<int*>(iPointer);
120
121 int numDWords=iNumBytes/sizeof(int);
122 for(int aIndex=0; aIndex<numDWords; aIndex++)
123 {
124 *aDWPointer=0;
125 aDWPointer++;
126 }
127}
128
129 template<typename T, int N> void Fill( T *iArray, const T* iVal )
130{
131// std::fill_n( iArray, N, iVal );
132 for (int i = 0; i != N; ++i)
133 {
134 *(iArray + i) = *iVal;
135 }
136}
137
138 template< typename T, int M, int N > inline void Fill( T *iArray, const T* iVal )//Fill( T (&iArray)[M][N], const T& iVal )
139{
140 for ( int i = 0; i != M; ++i )
141 {
142 Fill( iArray + i, iVal );
143 }
144}
145
146 template< typename T, int L, int M, int N > inline void Fill( T *iArray, const T* iVal ) //Fill( T (&iArray)[L][M][N], const T& iVal )
147{
148 for ( int i = 0; i != L; ++i )
149 {
150 Fill( iArray + i, iVal );
151 }
152}
153
154 static const int cSignBitWord = cLittleEndian;
155
156 double
157 inline fabs(double iVal)
158{
159 //On Windows this version is slower than std::fabs so use that instead.
160#if defined(MAC_VERSION)
161 double aVal = iVal;
162 int* tempptr = (reinterpret_cast<int*>(&aVal))+cSignBitWord;
163 *tempptr &= 0x7fffffff;
164
165 return aVal;
166#else
167 return std::fabs(iVal);
168#endif
169}
170
171 float
172 inline fabs(float iVal)
173{
174 // Call intrinsic if on TI c6727. fabs is about the same speed as std::fabs,
175 // although metrowerks v9.5 MSL libraries are much slower so for the time
176 // being were using this.
177 int temp = (*(reinterpret_cast<int*>(&iVal)) & 0x7fffffff);
178 return *reinterpret_cast<float*>(&temp);
179}
180
181 float
182 inline fabsf(float iVal)
183{
184 return AAX::fabs (iVal);
185}
186
187 template <class T>
188 inline T AbsMax(const T& iValue, const T& iMax)
189{
190 return std::fabs(iValue) < std::fabs(iMax) ? iMax : iValue;
191}
192
193 template <class T>
194 inline T MinMax(const T& iValue, const T& iMin, const T& iMax)
195{
196 return iValue > iMax ? iMax : (iValue < iMin ? iMin : iValue);
197}
198
199 template <class T>
200 inline T Max(const T& iValue1, const T& iValue2)
201{
202 return iValue1 > iValue2 ? iValue1 : iValue2;
203}
204
205 template <class T>
206 inline T Min(const T& iValue1, const T& iValue2)
207{
208 return iValue1 < iValue2 ? iValue1 : iValue2;
209}
210
211 template <class T>
212 inline T Sign(const T& iValue)
213{
214 return iValue < (T)(0.0) ? (T)(-1.0) : (T)(1.0);
215}
216
217//Polynomial evaluation.
218 inline double PolyEval(double x, const double* coefs, int numCoefs)
219{
220 // Coefs are ordered from highest degree to lowest (Matlab convention)
221 if(numCoefs < 1) return 0.0;
222
223 double result = coefs[0];
224 for(int i = 1; i < numCoefs; ++i)
225 {
226 result = result*x + coefs[i];
227 };
228
229 return result;
230}
231
232 inline double CeilLog2(double iValue)
233{
234 return std::pow(2.0f, (float)(std::ceil(std::log(iValue)/std::log(2.0f))));
235}
236
237 inline void SinCosMix(float aLinearMix, float &aSinMix, float &aCosMix)
238{
239 aSinMix=static_cast< float >( std::sin(aLinearMix*cHalfPi) );
240 aCosMix=static_cast< float >( std::cos(aLinearMix*cHalfPi) );
241}
242
243
244} // namespace AAX
245
246
247// Some methods have been broken off into AAX_Denormal.h; including
248// AAX_Denormal.h here for compatibility with projects that have not
249// yet been updated to include this new header.
250#include "AAX_Denormal.h"
251
252#endif // AAX_MISCUTILS_H
AAX_Constants.h
Signal processing constants.
AAX_PlatformOptimizationConstants.h
Constants descriptor...
AAX_Denormal.h
Signal processing utilities for denormal/subnormal floating point numbers.
AAX
Definition: AAX_EnvironmentUtilities.h:59
AAX::ZeroMemoryDW
void ZeroMemoryDW(void *iPointer, int iNumBytes)
Definition: AAX_MiscUtils.h:117
AAX::Fill
void Fill(T *iArray, const T *iVal)
Definition: AAX_MiscUtils.h:129
AAX::ZeroMemorySW
void ZeroMemorySW(void *iPointer, int iNumBytes)
Definition: AAX_MiscUtils.h:105
AAX::SinCosMix
void SinCosMix(float aLinearMix, float &aSinMix, float &aCosMix)
Definition: AAX_MiscUtils.h:237
AAX::Min
T Min(const T &iValue1, const T &iValue2)
Definition: AAX_MiscUtils.h:206
AAX::cHalfPi
const double cHalfPi
Definition: AAX_Constants.h:50
AAX::Max
T Max(const T &iValue1, const T &iValue2)
Definition: AAX_MiscUtils.h:200
AAX::ClampToZero
GFLOAT ClampToZero(GFLOAT iValue, GFLOAT iClampThreshold)
Definition: AAX_MiscUtils.h:79
AAX::fabsf
float fabsf(float iVal)
Definition: AAX_MiscUtils.h:182
AAX::PolyEval
double PolyEval(double x, const double *coefs, int numCoefs)
Definition: AAX_MiscUtils.h:218
AAX::AbsMax
T AbsMax(const T &iValue, const T &iMax)
Definition: AAX_MiscUtils.h:188
AAX::fabs
double fabs(double iVal)
Definition: AAX_MiscUtils.h:157
AAX::CeilLog2
double CeilLog2(double iValue)
Definition: AAX_MiscUtils.h:232
AAX::Sign
T Sign(const T &iValue)
Definition: AAX_MiscUtils.h:212
AAX::MinMax
T MinMax(const T &iValue, const T &iMin, const T &iMax)
Definition: AAX_MiscUtils.h:194
AAX::cLittleEndian
const int cLittleEndian
Definition: AAX_Constants.h:45