| 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_CommonConversions.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-2015, 2023-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
30/*================================================================================================*/
31
32
33#ifndef AAX_COMMONCONVERIONS_H
34#define AAX_COMMONCONVERIONS_H
35
36#include <math.h>
37#include "AAX.h"
38
39
40 const int32_t k32BitPosMax = 0x7FFFFFFF;
41 const int32_t k32BitAbsMax = 0x80000000;
42 const int32_t k32BitNegMax = 0x80000000;
43
44 const int32_t k56kFracPosMax = 0x007FFFFF; // Positive Max Value
45 const int32_t k56kFracAbsMax = 0x00800000; // Absolute Max Value. Essentially negative one without the sign extension.
46 const int32_t k56kFracHalf = 0x00400000;
47 const int32_t k56kFracNegOne = 0xFF800000; //Note sign extension!!!
48 const int32_t k56kFracNegMax = k56kFracNegOne; //Note sign extension!!!
49 const int32_t k56kFracZero = 0x00000000;
50
51 const double kOneOver56kFracAbsMax = 1.0/double(k56kFracAbsMax);
52 const double k56kFloatPosMax = double(k56kFracPosMax)/double(k56kFracAbsMax); //56k Max value represented in floating point format.
53 const double k56kFloatNegMax = -1.0; //56k Min value represented in floating point format.
54 const double kNeg144DB = -144.0;
55 const double kNeg144Gain = 6.3095734448019324943436013662234e-8; //pow(10.0, kNeg144DB / 20.0);
56
62 inline double GainToDB(double aGain)
63{
64 if (aGain == 0.0)
65 return kNeg144DB;
66 else
67 {
68 double dB;
69
70 dB = log10(aGain) * 20.0;
71
72 if (dB < kNeg144DB)
73 dB = kNeg144DB;
74 return (dB); // convert factor to dB
75 }
76}
77
83 inline double DBToGain(double dB)
84{
85 return pow(10.0, dB / 20.0);
86}
87
93 inline double LongToDouble (int32_t aLong)
94{
95 if (aLong > k56kFracPosMax)
96 aLong = k56kFracPosMax;
97 else if (aLong < k56kFracNegMax)
98 aLong = k56kFracNegMax;
99 return (double(aLong) * kOneOver56kFracAbsMax);
100}
101
104int32_t DoubleToLong (double aDouble);
105
108 inline int32_t DoubleToDSPCoef(double d, double max = k56kFloatPosMax, double min = k56kFloatNegMax)
109{
110 if(d >= max) // k56kFloatPosMax unless specified by the caller
111 {
112 return k56kFracPosMax;
113 };
114 if(d < min) // k56kFloatNegMax unless specified by the caller
115 {
116 return k56kFracNegMax;
117 }
118 return static_cast<int32_t>(d*k56kFracAbsMax);
119}
120
123 inline double DSPCoefToDouble(int32_t c, int32_t max = k56kFracPosMax, int32_t min = k56kFracNegMax)
124{
125 if (c > max) // k56kFracPosMax unless specified by the caller
126 c = k56kFracPosMax;
127 else if (c < min) // k56kFracNegMax unless specified by the caller
128 c = k56kFracNegMax;
129 return (double(c) * kOneOver56kFracAbsMax);
130}
131
134 inline double ThirtyTwoBitDSPCoefToDouble(int32_t c)
135{
136 return DSPCoefToDouble(c, k32BitPosMax, k32BitNegMax);
137}
138
141 inline int32_t DoubleTo32BitDSPCoefRnd(double d)
142{
143 return DoubleToDSPCoef(d, k32BitPosMax, k32BitNegMax);
144}
145
146int32_t DoubleTo32BitDSPCoef(double d);
147int32_t DoubleToDSPCoefRnd(double d, double max, double min);
148
149#endif // AAX_COMMONCONVERIONS_H
AAX.h
Various utility definitions for AAX.
DoubleToDSPCoef
int32_t DoubleToDSPCoef(double d, double max=k56kFloatPosMax, double min=k56kFloatNegMax)
Convert Double to DSPCoef.
Definition: AAX_CommonConversions.h:108
k32BitAbsMax
const int32_t k32BitAbsMax
Definition: AAX_CommonConversions.h:41
kNeg144Gain
const double kNeg144Gain
Definition: AAX_CommonConversions.h:55
kNeg144DB
const double kNeg144DB
Definition: AAX_CommonConversions.h:54
k56kFracNegMax
const int32_t k56kFracNegMax
Definition: AAX_CommonConversions.h:48
DoubleToDSPCoefRnd
int32_t DoubleToDSPCoefRnd(double d, double max, double min)
k32BitNegMax
const int32_t k32BitNegMax
Definition: AAX_CommonConversions.h:42
LongToDouble
double LongToDouble(int32_t aLong)
Convert Long to Double.
Definition: AAX_CommonConversions.h:93
k56kFracHalf
const int32_t k56kFracHalf
Definition: AAX_CommonConversions.h:46
ThirtyTwoBitDSPCoefToDouble
double ThirtyTwoBitDSPCoefToDouble(int32_t c)
ThirtyTwoBitDSPCoefToDouble.
Definition: AAX_CommonConversions.h:134
DBToGain
double DBToGain(double dB)
Convert dB to Gain.
Definition: AAX_CommonConversions.h:83
DoubleToLong
int32_t DoubleToLong(double aDouble)
convert floating point equivalent back to int32_t
kOneOver56kFracAbsMax
const double kOneOver56kFracAbsMax
Definition: AAX_CommonConversions.h:51
DSPCoefToDouble
double DSPCoefToDouble(int32_t c, int32_t max=k56kFracPosMax, int32_t min=k56kFracNegMax)
Convert DSPCoef to Double.
Definition: AAX_CommonConversions.h:123
k32BitPosMax
const int32_t k32BitPosMax
Definition: AAX_CommonConversions.h:40
GainToDB
double GainToDB(double aGain)
Convert Gain to dB.
Definition: AAX_CommonConversions.h:62
k56kFracPosMax
const int32_t k56kFracPosMax
Definition: AAX_CommonConversions.h:44
DoubleTo32BitDSPCoefRnd
int32_t DoubleTo32BitDSPCoefRnd(double d)
DoubleTo32BitDSPCoefRnd.
Definition: AAX_CommonConversions.h:141
k56kFloatPosMax
const double k56kFloatPosMax
Definition: AAX_CommonConversions.h:52
DoubleTo32BitDSPCoef
int32_t DoubleTo32BitDSPCoef(double d)
k56kFracAbsMax
const int32_t k56kFracAbsMax
Definition: AAX_CommonConversions.h:45
k56kFloatNegMax
const double k56kFloatNegMax
Definition: AAX_CommonConversions.h:53
k56kFracZero
const int32_t k56kFracZero
Definition: AAX_CommonConversions.h:49
k56kFracNegOne
const int32_t k56kFracNegOne
Definition: AAX_CommonConversions.h:47