| 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_CommonConversions.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-2015, 2023 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * CONFIDENTIAL: this document contains confidential information of Avid. Do
8 * not disclose to any third party. Use of the information contained in this
9 * document is subject to an Avid SDK license.
10 *
11 */
12
17/*================================================================================================*/
18
19
20#ifndef AAX_COMMONCONVERIONS_H
21#define AAX_COMMONCONVERIONS_H
22
23#include <math.h>
24#include "AAX.h"
25
26
27 const int32_t k32BitPosMax = 0x7FFFFFFF;
28 const int32_t k32BitAbsMax = 0x80000000;
29 const int32_t k32BitNegMax = 0x80000000;
30
31 const int32_t k56kFracPosMax = 0x007FFFFF; // Positive Max Value
32 const int32_t k56kFracAbsMax = 0x00800000; // Absolute Max Value. Essentially negative one without the sign extension.
33 const int32_t k56kFracHalf = 0x00400000;
34 const int32_t k56kFracNegOne = 0xFF800000; //Note sign extension!!!
35 const int32_t k56kFracNegMax = k56kFracNegOne; //Note sign extension!!!
36 const int32_t k56kFracZero = 0x00000000;
37
38 const double kOneOver56kFracAbsMax = 1.0/double(k56kFracAbsMax);
39 const double k56kFloatPosMax = double(k56kFracPosMax)/double(k56kFracAbsMax); //56k Max value represented in floating point format.
40 const double k56kFloatNegMax = -1.0; //56k Min value represented in floating point format.
41 const double kNeg144DB = -144.0;
42 const double kNeg144Gain = 6.3095734448019324943436013662234e-8; //pow(10.0, kNeg144DB / 20.0);
43
49 inline double GainToDB(double aGain)
50{
51 if (aGain == 0.0)
52 return kNeg144DB;
53 else
54 {
55 double dB;
56
57 dB = log10(aGain) * 20.0;
58
59 if (dB < kNeg144DB)
60 dB = kNeg144DB;
61 return (dB); // convert factor to dB
62 }
63}
64
70 inline double DBToGain(double dB)
71{
72 return pow(10.0, dB / 20.0);
73}
74
80 inline double LongToDouble (int32_t aLong)
81{
82 if (aLong > k56kFracPosMax)
83 aLong = k56kFracPosMax;
84 else if (aLong < k56kFracNegMax)
85 aLong = k56kFracNegMax;
86 return (double(aLong) * kOneOver56kFracAbsMax);
87}
88
91int32_t DoubleToLong (double aDouble);
92
95 inline int32_t DoubleToDSPCoef(double d, double max = k56kFloatPosMax, double min = k56kFloatNegMax)
96{
97 if(d >= max) // k56kFloatPosMax unless specified by the caller
98 {
99 return k56kFracPosMax;
100 };
101 if(d < min) // k56kFloatNegMax unless specified by the caller
102 {
103 return k56kFracNegMax;
104 }
105 return static_cast<int32_t>(d*k56kFracAbsMax);
106}
107
110 inline double DSPCoefToDouble(int32_t c, int32_t max = k56kFracPosMax, int32_t min = k56kFracNegMax)
111{
112 if (c > max) // k56kFracPosMax unless specified by the caller
113 c = k56kFracPosMax;
114 else if (c < min) // k56kFracNegMax unless specified by the caller
115 c = k56kFracNegMax;
116 return (double(c) * kOneOver56kFracAbsMax);
117}
118
121 inline double ThirtyTwoBitDSPCoefToDouble(int32_t c)
122{
123 return DSPCoefToDouble(c, k32BitPosMax, k32BitNegMax);
124}
125
128 inline int32_t DoubleTo32BitDSPCoefRnd(double d)
129{
130 return DoubleToDSPCoef(d, k32BitPosMax, k32BitNegMax);
131}
132
133int32_t DoubleTo32BitDSPCoef(double d);
134int32_t DoubleToDSPCoefRnd(double d, double max, double min);
135
136#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:95
k32BitAbsMax
const int32_t k32BitAbsMax
Definition: AAX_CommonConversions.h:28
kNeg144Gain
const double kNeg144Gain
Definition: AAX_CommonConversions.h:42
kNeg144DB
const double kNeg144DB
Definition: AAX_CommonConversions.h:41
k56kFracNegMax
const int32_t k56kFracNegMax
Definition: AAX_CommonConversions.h:35
DoubleToDSPCoefRnd
int32_t DoubleToDSPCoefRnd(double d, double max, double min)
k32BitNegMax
const int32_t k32BitNegMax
Definition: AAX_CommonConversions.h:29
LongToDouble
double LongToDouble(int32_t aLong)
Convert Long to Double.
Definition: AAX_CommonConversions.h:80
k56kFracHalf
const int32_t k56kFracHalf
Definition: AAX_CommonConversions.h:33
ThirtyTwoBitDSPCoefToDouble
double ThirtyTwoBitDSPCoefToDouble(int32_t c)
ThirtyTwoBitDSPCoefToDouble.
Definition: AAX_CommonConversions.h:121
DBToGain
double DBToGain(double dB)
Convert dB to Gain.
Definition: AAX_CommonConversions.h:70
DoubleToLong
int32_t DoubleToLong(double aDouble)
convert floating point equivalent back to int32_t
kOneOver56kFracAbsMax
const double kOneOver56kFracAbsMax
Definition: AAX_CommonConversions.h:38
DSPCoefToDouble
double DSPCoefToDouble(int32_t c, int32_t max=k56kFracPosMax, int32_t min=k56kFracNegMax)
Convert DSPCoef to Double.
Definition: AAX_CommonConversions.h:110
k32BitPosMax
const int32_t k32BitPosMax
Definition: AAX_CommonConversions.h:27
GainToDB
double GainToDB(double aGain)
Convert Gain to dB.
Definition: AAX_CommonConversions.h:49
k56kFracPosMax
const int32_t k56kFracPosMax
Definition: AAX_CommonConversions.h:31
DoubleTo32BitDSPCoefRnd
int32_t DoubleTo32BitDSPCoefRnd(double d)
DoubleTo32BitDSPCoefRnd.
Definition: AAX_CommonConversions.h:128
k56kFloatPosMax
const double k56kFloatPosMax
Definition: AAX_CommonConversions.h:39
DoubleTo32BitDSPCoef
int32_t DoubleTo32BitDSPCoef(double d)
k56kFracAbsMax
const int32_t k56kFracAbsMax
Definition: AAX_CommonConversions.h:32
k56kFloatNegMax
const double k56kFloatNegMax
Definition: AAX_CommonConversions.h:40
k56kFracZero
const int32_t k56kFracZero
Definition: AAX_CommonConversions.h:36
k56kFracNegOne
const int32_t k56kFracNegOne
Definition: AAX_CommonConversions.h:34