| 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_Quantize.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 * Copyright 2013-2015, 2019, 2021, 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_QUANTIZE_H
21#define AAX_QUANTIZE_H
22
23#include "AAX.h"
24#include "AAX_PlatformOptimizationConstants.h"
25#include "AAX_Constants.h"
26
27#if ! defined( _TMS320C6X )
28
29#if _MSC_VER && !defined(__INTEL_COMPILER)
30#define _MM_FUNCTIONALITY
31#include <intrin.h>
32#elif LINUX_VERSION
33#elif TARGET_OS_IPHONE
34#elif defined(__arm__)
35#elif defined(__arm64__)
36#else
37// GNU or INTEL:
38#include <xmmintrin.h>
39#include <pmmintrin.h>
40#include <tmmintrin.h>
41#endif
42
43#endif
44
45 namespace AAX
46{
47
48//This assumes the floating point processor is in 64 bit IEEE mode.
49#if ! defined( _TMS320C6X )
50
51// For double->Int32 conversion
52 static const double cDouble2IntBias = ldexpf(1,52)*1.5;
53 static const double cOneHalfOffset = 0.5;
54 static const int32_t cMantisaWord = cBigEndian;
55
56// For double->Int64 conversion
57 static const double kExponentMagicDelta = 1.5e-8; //1e^(number of exp bit)
58 static const double kBigMantissaMagicFloat = 6755399441055744.0; //2^52 * 1.5, uses limited precisicion to floor
59 static const int64_t kBigMantissaMagicMask = 0x1fffffffffffffLL; //2^52 * 1.5 mask,
60 static const int64_t kBigMantissaMagicInt = 0x18000000000000LL; //2^52 * 1.5, uses limited precisicion to floor
61#endif
62
63/*===================================================================================================*/
64
73 inline int32_t FastRound2Int32(double iVal)
74{
75#if defined( _TMS320C6X )
76 // rounding mode set by the CSR register
77 const int32_t r = _dpint(iVal);
78 return r;
79#else
80 iVal += cDouble2IntBias;
81 return (reinterpret_cast<int32_t*>(&iVal))[cMantisaWord];
82#endif
83}
84
93 inline int32_t FastRound2Int32(float iVal)
94{
95#if defined( _TMS320C6X )
96 // rounding mode set by the CSR register
97 const int32_t r = _spint(iVal);
98 return r;
99#else
100 return FastRound2Int32(double(iVal));
101#endif
102}
103
104
107 inline int32_t FastRndDbl2Int32(double iVal)
108{
109 return FastRound2Int32(iVal);
110}
111
124 inline int32_t FastTrunc2Int32(double iVal)
125{
126#if defined( _TMS320C6X )
127 // rounding mode set by the CSR register
128 const int32_t r = _dpint(iVal - 0.5);
129 return r;
130#else
131 return FastRound2Int32(iVal - 0.5);
132#endif
133}
134
143 inline int32_t FastTrunc2Int32(float iVal)
144{
145#if defined( _TMS320C6X )
146 // rounding mode set by the CSR register
147 const int32_t r = _spint(iVal - 0.5f);
148 return r;
149#elif _MSC_VER
150 int32_t r;
151 r = _mm_cvtt_ss2si( _mm_load_ss(&iVal) );
152 return r;
153#else
154 return static_cast<int32_t>(iVal);
155#endif
156}
157
167 inline int64_t FastRound2Int64(double iVal)
168{
169#if defined( _TMS320C6X )
170 return (int64_t)(iVal > 0.0 ? iVal + 0.5 : iVal - 0.5);
171#else
172 iVal += kExponentMagicDelta; // Round to nearest
173 iVal += kBigMantissaMagicFloat; // Normalize to integer
174 int64_t result = *reinterpret_cast<int64_t*>(&iVal);
175 result &= kBigMantissaMagicMask; // Mask out upper bits of float (exponent, sign)
176 result -= kBigMantissaMagicInt; // Normalize to integer
177 return result;
178#endif
179}
180
181} // namespace AAX
182
183#endif // AAX_QUANTIZE_H
AAX.h
Various utility definitions for AAX.
AAX_Constants.h
Signal processing constants.
AAX_PlatformOptimizationConstants.h
Constants descriptor...
AAX
Definition: AAX_EnvironmentUtilities.h:59
AAX::FastRound2Int64
int64_t FastRound2Int64(double iVal)
Round to Int64.
Definition: AAX_Quantize.h:167
AAX::FastTrunc2Int32
int32_t FastTrunc2Int32(double iVal)
Float to Int conversion with truncation.
Definition: AAX_Quantize.h:124
AAX::FastRndDbl2Int32
int32_t FastRndDbl2Int32(double iVal)
Definition: AAX_Quantize.h:107
AAX::FastRound2Int32
int32_t FastRound2Int32(double iVal)
Round to Int32.
Definition: AAX_Quantize.h:73
AAX::cBigEndian
const int cBigEndian
Definition: AAX_Constants.h:44