| AAX SDK 2.8.0 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-2024 Avid Technology, Inc.
4 * All rights reserved.
5 *
6 * This file is part of the Avid AAX SDK.
7 *
8 * The AAX SDK is subject to commercial or open-source licensing.
9 *
10 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
11 * Agreement and Avid Privacy Policy.
12 *
13 * AAX SDK License: https://developer.avid.com/aax
14 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
15 *
16 * Or: You may also use this code under the terms of the GPL v3 (see
17 * www.gnu.org/licenses).
18 *
19 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 * DISCLAIMED.
22 */
23
30/*================================================================================================*/
31#pragma once
32
33#ifndef AAX_MISCUTILS_H
34#define AAX_MISCUTILS_H
35
36#include "AAX_PlatformOptimizationConstants.h"
37#include "AAX_Constants.h"
38
39#if defined(_MSC_VER)
40 #define DECLARE_ALIGNED(t,v,x) __declspec(align(x)) t v
41// #define DECLARE_ALIGNED(t,v,x) t v
42#elif defined (__GNUC__)
43 #define DECLARE_ALIGNED(t,v,x) t v __attribute__ ((aligned (x)))
44// #define DECLARE_ALIGNED(t,v,x) t v
45#elif defined (_TMS320C6X)
46 #define DECLARE_ALIGNED(t,v,x) t v
47 #warn "DECLARE_ALIGNED macro does not currently align data on TI"
48#else
49 #error "DigiError: Please port the DECLARE_ALIGNED macro to this platform"
50#endif
51
52
58#ifdef _TMS320C6X
59#define AAX_ALIGNMENT_HINT(a,b) std::_nassert(((int)(a) % b) == 0)
60#define AAX_WORD_ALIGNED_HINT(a) AAX_ALIGNMENT_HINT(a,4)
61#define AAX_DWORD_ALIGNED_HINT(a) AAX_ALIGNMENT_HINT(a,8)
62#else
63#define AAX_ALIGNMENT_HINT(a,b)
64#define AAX_WORD_ALIGNED_HINT(a)
65#define AAX_DWORD_ALIGNED_HINT(a)
66#endif
67
73#ifdef _TMS320C6X
74#define AAX_LO(x) (_itof(_lo((_amemd8_const(&x)))))
75#define AAX_HI(x) (_itof(_hi((_amemd8_const(&x)))))
76#define AAX_INT_LO(x) (_lo((_amemd8_const(&x))))
77#define AAX_INT_HI(x) (_hi((_amemd8_const(&x))))
78#else //for non-TI systems increment pointer by 4-bytes to simulate hi-word access
79#define AAX_LO(x) x
80#define AAX_HI(x) *((const_cast<float*>(&x))+1)
81#define AAX_INT_LO(x) x
82#define AAX_INT_HI(x) *((const_cast<int32_t*>(reinterpret_cast<const int32_t*>(&x)))+1)
83#endif
84
85
86
87
88 namespace AAX
89{
90
91 template<class GFLOAT>
92 inline GFLOAT ClampToZero(GFLOAT iValue, GFLOAT iClampThreshold)
93{
94 return (iValue < iClampThreshold && iValue > -iClampThreshold) ? 0.0 : iValue;
95}
96
97/*template<class GFLOAT>
98 class SmoothingFilter
99{
100 public:
101 SmoothingFilter() { Reset(); }
102 void Reset(void) { mYnm1=0.0; }
103 void Reset(double iInitialState) { mYnm1=iInitialState; }
104 void SetSmothingRate(double iFrequency, double iSampleRate) { mZeroCoef = 1.0-std::exp(iFrequency*-cTwoPi/iSampleRate); }
105 void SetSmoothingCoeff(GFLOAT b0) { mZeroCoef = b0; }
106 inline GFLOAT Smooth(GFLOAT iInput)
107 {
108 mYnm1 += mZeroCoef * (iInput - mYnm1);
109 DeDenormal(mYnm1);
110 return (GFLOAT)mYnm1;
111 }
112
113 private:
114 double mYnm1; // y[n-1]
115 GFLOAT mZeroCoef;
116};*/
117
118 inline void ZeroMemorySW(void* iPointer, int iNumBytes)
119{
120 char* aCharPointer=static_cast<char*>(iPointer);
121
122 for(int aIndex=0; aIndex<iNumBytes; aIndex++)
123 {
124 *aCharPointer=0;
125 aCharPointer++;
126 }
127}
128
129//Warning: the number of bytes passed in must be multiple of 4
130 inline void ZeroMemoryDW(void* iPointer, int iNumBytes)
131{
132 int* aDWPointer=static_cast<int*>(iPointer);
133
134 int numDWords=iNumBytes/sizeof(int);
135 for(int aIndex=0; aIndex<numDWords; aIndex++)
136 {
137 *aDWPointer=0;
138 aDWPointer++;
139 }
140}
141
142 template<typename T, int N> void Fill( T *iArray, const T* iVal )
143{
144// std::fill_n( iArray, N, iVal );
145 for (int i = 0; i != N; ++i)
146 {
147 *(iArray + i) = *iVal;
148 }
149}
150
151 template< typename T, int M, int N > inline void Fill( T *iArray, const T* iVal )//Fill( T (&iArray)[M][N], const T& iVal )
152{
153 for ( int i = 0; i != M; ++i )
154 {
155 Fill( iArray + i, iVal );
156 }
157}
158
159 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 )
160{
161 for ( int i = 0; i != L; ++i )
162 {
163 Fill( iArray + i, iVal );
164 }
165}
166
167 static const int cSignBitWord = cLittleEndian;
168
169 double
170 inline fabs(double iVal)
171{
172 //On Windows this version is slower than std::fabs so use that instead.
173#if defined(MAC_VERSION)
174 double aVal = iVal;
175 int* tempptr = (reinterpret_cast<int*>(&aVal))+cSignBitWord;
176 *tempptr &= 0x7fffffff;
177
178 return aVal;
179#else
180 return std::fabs(iVal);
181#endif
182}
183
184 float
185 inline fabs(float iVal)
186{
187 // Call intrinsic if on TI c6727. fabs is about the same speed as std::fabs,
188 // although metrowerks v9.5 MSL libraries are much slower so for the time
189 // being were using this.
190 int temp = (*(reinterpret_cast<int*>(&iVal)) & 0x7fffffff);
191 return *reinterpret_cast<float*>(&temp);
192}
193
194 float
195 inline fabsf(float iVal)
196{
197 return AAX::fabs (iVal);
198}
199
200 template <class T>
201 inline T AbsMax(const T& iValue, const T& iMax)
202{
203 return std::fabs(iValue) < std::fabs(iMax) ? iMax : iValue;
204}
205
206 template <class T>
207 inline T MinMax(const T& iValue, const T& iMin, const T& iMax)
208{
209 return iValue > iMax ? iMax : (iValue < iMin ? iMin : iValue);
210}
211
212 template <class T>
213 inline T Max(const T& iValue1, const T& iValue2)
214{
215 return iValue1 > iValue2 ? iValue1 : iValue2;
216}
217
218 template <class T>
219 inline T Min(const T& iValue1, const T& iValue2)
220{
221 return iValue1 < iValue2 ? iValue1 : iValue2;
222}
223
224 template <class T>
225 inline T Sign(const T& iValue)
226{
227 return iValue < (T)(0.0) ? (T)(-1.0) : (T)(1.0);
228}
229
230//Polynomial evaluation.
231 inline double PolyEval(double x, const double* coefs, int numCoefs)
232{
233 // Coefs are ordered from highest degree to lowest (Matlab convention)
234 if(numCoefs < 1) return 0.0;
235
236 double result = coefs[0];
237 for(int i = 1; i < numCoefs; ++i)
238 {
239 result = result*x + coefs[i];
240 };
241
242 return result;
243}
244
245 inline double CeilLog2(double iValue)
246{
247 return std::pow(2.0f, (float)(std::ceil(std::log(iValue)/std::log(2.0f))));
248}
249
250 inline void SinCosMix(float aLinearMix, float &aSinMix, float &aCosMix)
251{
252 aSinMix=static_cast< float >( std::sin(aLinearMix*cHalfPi) );
253 aCosMix=static_cast< float >( std::cos(aLinearMix*cHalfPi) );
254}
255
256
257} // namespace AAX
258
259
260// Some methods have been broken off into AAX_Denormal.h; including
261// AAX_Denormal.h here for compatibility with projects that have not
262// yet been updated to include this new header.
263#include "AAX_Denormal.h"
264
265#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:72
AAX::ZeroMemoryDW
void ZeroMemoryDW(void *iPointer, int iNumBytes)
Definition: AAX_MiscUtils.h:130
AAX::Fill
void Fill(T *iArray, const T *iVal)
Definition: AAX_MiscUtils.h:142
AAX::ZeroMemorySW
void ZeroMemorySW(void *iPointer, int iNumBytes)
Definition: AAX_MiscUtils.h:118
AAX::SinCosMix
void SinCosMix(float aLinearMix, float &aSinMix, float &aCosMix)
Definition: AAX_MiscUtils.h:250
AAX::Min
T Min(const T &iValue1, const T &iValue2)
Definition: AAX_MiscUtils.h:219
AAX::cHalfPi
const double cHalfPi
Definition: AAX_Constants.h:63
AAX::Max
T Max(const T &iValue1, const T &iValue2)
Definition: AAX_MiscUtils.h:213
AAX::ClampToZero
GFLOAT ClampToZero(GFLOAT iValue, GFLOAT iClampThreshold)
Definition: AAX_MiscUtils.h:92
AAX::fabsf
float fabsf(float iVal)
Definition: AAX_MiscUtils.h:195
AAX::PolyEval
double PolyEval(double x, const double *coefs, int numCoefs)
Definition: AAX_MiscUtils.h:231
AAX::AbsMax
T AbsMax(const T &iValue, const T &iMax)
Definition: AAX_MiscUtils.h:201
AAX::fabs
double fabs(double iVal)
Definition: AAX_MiscUtils.h:170
AAX::CeilLog2
double CeilLog2(double iValue)
Definition: AAX_MiscUtils.h:245
AAX::Sign
T Sign(const T &iValue)
Definition: AAX_MiscUtils.h:225
AAX::MinMax
T MinMax(const T &iValue, const T &iMin, const T &iMax)
Definition: AAX_MiscUtils.h:207
AAX::cLittleEndian
const int cLittleEndian
Definition: AAX_Constants.h:58