\hypertarget{a00854_source}{}\doxysection{AAX\+\_\+\+Quantize.\+h}
\label{a00854_source}\index{AAX\_Quantize.h@{AAX\_Quantize.h}}
\mbox{\hyperlink{a00854}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ \ Copyright\ 2013-\/2015,\ 2019,\ 2021,\ 2023\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ CONFIDENTIAL:\ this\ document\ contains\ confidential\ information\ of\ Avid.\ Do}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ not\ disclose\ to\ any\ third\ party.\ Use\ of\ the\ information\ contained\ in\ this}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ document\ is\ subject\ to\ an\ Avid\ SDK\ license.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00017\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#ifndef\ AAX\_QUANTIZE\_H}}
\DoxyCodeLine{00021\ \textcolor{preprocessor}{\#define\ AAX\_QUANTIZE\_H}}
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00023\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00533}{AAX.h}}"{}}}
\DoxyCodeLine{00024\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00833}{AAX\_PlatformOptimizationConstants.h}}"{}}}
\DoxyCodeLine{00025\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00830}{AAX\_Constants.h}}"{}}}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ \textcolor{preprocessor}{\#if\ !\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00028\ }
\DoxyCodeLine{00029\ \textcolor{preprocessor}{\#if\ \_MSC\_VER\ \&\&\ !defined(\_\_INTEL\_COMPILER)}}
\DoxyCodeLine{00030\ \textcolor{preprocessor}{\#define\ \_MM\_FUNCTIONALITY}}
\DoxyCodeLine{00031\ \textcolor{preprocessor}{\#include\ <intrin.h>}}
\DoxyCodeLine{00032\ \textcolor{preprocessor}{\#elif\ LINUX\_VERSION}}
\DoxyCodeLine{00033\ \textcolor{preprocessor}{\#elif\ TARGET\_OS\_IPHONE}}
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#elif\ defined(\_\_arm\_\_)}}
\DoxyCodeLine{00035\ \textcolor{preprocessor}{\#elif\ defined(\_\_arm64\_\_)}}
\DoxyCodeLine{00036\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00037\ \textcolor{comment}{//\ GNU\ or\ INTEL:}}
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#include\ <xmmintrin.h>}}
\DoxyCodeLine{00039\ \textcolor{preprocessor}{\#include\ <pmmintrin.h>}}
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#include\ <tmmintrin.h>}}
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{a00935}{AAX}}}
\DoxyCodeLine{00046\ \{}
\DoxyCodeLine{00047\ }
\DoxyCodeLine{00048\ \textcolor{comment}{//This\ assumes\ the\ floating\ point\ processor\ is\ in\ 64\ bit\ IEEE\ mode.}}
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#if\ !\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00050\ \ \ \ \ }
\DoxyCodeLine{00051\ \textcolor{comment}{//\ For\ double-\/>Int32\ conversion}}
\DoxyCodeLine{00052\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ cDouble2IntBias\ =\ ldexpf(1,52)*1.5;}
\DoxyCodeLine{00053\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ cOneHalfOffset\ =\ 0.5;}
\DoxyCodeLine{00054\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int32\_t\ cMantisaWord\ =\ \mbox{\hyperlink{a00935_af4c24d9d2042fe4252db5431ef126d00}{cBigEndian}};}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00056\ \textcolor{comment}{//\ For\ double-\/>Int64\ conversion}}
\DoxyCodeLine{00057\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ kExponentMagicDelta\ \ \ \ \ \ \ \ \ =\ 1.5e-\/8;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//1e\string^(number\ of\ exp\ bit)}}
\DoxyCodeLine{00058\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ kBigMantissaMagicFloat\ \ \ \ \ \ =\ 6755399441055744.0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//2\string^52\ *\ 1.5,\ \ uses\ limited\ precisicion\ to\ floor}}
\DoxyCodeLine{00059\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int64\_t\ \ \ \ \ \ \ \ kBigMantissaMagicMask\ \ \ \ \ \ \ =\ 0x1fffffffffffffLL;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//2\string^52\ *\ 1.5\ mask,\ }}
\DoxyCodeLine{00060\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int64\_t\ \ \ \ \ \ \ \ kBigMantissaMagicInt\ \ \ \ \ \ \ \ =\ 0x18000000000000LL;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//2\string^52\ *\ 1.5,\ \ uses\ limited\ precisicion\ to\ floor}}
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \textcolor{comment}{/*===================================================================================================*/}}
\DoxyCodeLine{00064\ \ \ \ \ }
\DoxyCodeLine{00073\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00935_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00074\ \{}
\DoxyCodeLine{00075\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_dpint(iVal);\ }
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00079\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00080\ \ \ \ \ iVal\ +=\ cDouble2IntBias;}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordflow}{return}\ (\textcolor{keyword}{reinterpret\_cast<}int32\_t*\textcolor{keyword}{>}(\&iVal))[cMantisaWord];}
\DoxyCodeLine{00082\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00083\ \}}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00093\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00935_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{float}\ iVal)}
\DoxyCodeLine{00094\ \{}
\DoxyCodeLine{00095\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00097\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_spint(iVal);\ }
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00099\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00935_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{double}(iVal));}
\DoxyCodeLine{00101\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00102\ \}}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00107\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00935_ae690c060a5ff4cb96e77335231a29673}{FastRndDbl2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00108\ \{}
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00935_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(iVal);}
\DoxyCodeLine{00110\ \}}
\DoxyCodeLine{00111\ }
\DoxyCodeLine{00124\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00935_ad2b2872b49146cf0859c403fea702a39}{FastTrunc2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00125\ \{}
\DoxyCodeLine{00126\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_dpint(iVal\ -\/\ 0.5);\ }
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00130\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00935_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(iVal\ -\/\ 0.5);}
\DoxyCodeLine{00132\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00133\ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00143\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00935_ad2b2872b49146cf0859c403fea702a39}{FastTrunc2Int32}}(\textcolor{keywordtype}{float}\ iVal)}
\DoxyCodeLine{00144\ \{}
\DoxyCodeLine{00145\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00147\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_spint(iVal\ -\/\ 0.5f);\ }
\DoxyCodeLine{00148\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00149\ \textcolor{preprocessor}{\#elif\ \_MSC\_VER}}
\DoxyCodeLine{00150\ \ \ \ \ int32\_t\ r;}
\DoxyCodeLine{00151\ \ \ \ \ r\ =\ \_mm\_cvtt\_ss2si(\ \_mm\_load\_ss(\&iVal)\ );}
\DoxyCodeLine{00152\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00153\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}int32\_t\textcolor{keyword}{>}(iVal);}
\DoxyCodeLine{00155\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00156\ \}}
\DoxyCodeLine{00157\ \ \ \ \ }
\DoxyCodeLine{00167\ \textcolor{keyword}{inline}\ int64\_t\ \mbox{\hyperlink{a00935_a7df6b095ea2469f2adce2a895038212e}{FastRound2Int64}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00168\ \{}
\DoxyCodeLine{00169\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{return}\ (int64\_t)(iVal\ >\ 0.0\ ?\ iVal\ +\ 0.5\ :\ iVal\ -\/\ 0.5);}
\DoxyCodeLine{00171\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00172\ \ \ \ \ iVal\ +=\ kExponentMagicDelta;\ \textcolor{comment}{//\ Round\ to\ nearest}}
\DoxyCodeLine{00173\ \ \ \ \ iVal\ +=\ kBigMantissaMagicFloat;\ \textcolor{comment}{//\ Normalize\ to\ integer}}
\DoxyCodeLine{00174\ \ \ \ \ int64\_t\ result\ =\ \ *\textcolor{keyword}{reinterpret\_cast<}int64\_t*\textcolor{keyword}{>}(\&iVal);}
\DoxyCodeLine{00175\ \ \ \ \ result\ \&=\ kBigMantissaMagicMask;\ \textcolor{comment}{//\ Mask\ out\ upper\ bits\ of\ float\ (exponent,\ sign)}}
\DoxyCodeLine{00176\ \ \ \ \ result\ -\/=\ kBigMantissaMagicInt;\ \textcolor{comment}{//\ Normalize\ to\ integer}}
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00178\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00179\ \}}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00181\ \}\ \textcolor{comment}{//\ namespace\ AAX}}
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00183\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ AAX\_QUANTIZE\_H}}

\end{DoxyCode}
