\hypertarget{a00866_source}{}\doxysection{AAX\+\_\+\+Quantize.\+h}
\label{a00866_source}\index{AAX\_Quantize.h@{AAX\_Quantize.h}}
\mbox{\hyperlink{a00866}{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-\/2024\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ This\ file\ is\ part\ of\ the\ Avid\ AAX\ SDK.}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ The\ AAX\ SDK\ is\ subject\ to\ commercial\ or\ open-\/source\ licensing.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ \ By\ using\ the\ AAX\ SDK,\ you\ agree\ to\ the\ terms\ of\ both\ the\ Avid\ AAX\ SDK\ License}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ Agreement\ and\ Avid\ Privacy\ Policy.}}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ \ AAX\ SDK\ License:\ https://developer.avid.com/aax}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ Privacy\ Policy:\ https://www.avid.com/legal/privacy-\/policy-\/statement}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ Or:\ You\ may\ also\ use\ this\ code\ under\ the\ terms\ of\ the\ GPL\ v3\ (see}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *\ \ www.gnu.org/licenses).}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ \ THE\ AAX\ SDK\ IS\ PROVIDED\ "{}AS\ IS"{}\ WITHOUT\ ANY\ WARRANTY,\ AND\ ALL\ WARRANTIES,\ WHETHER}}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ \ EXPRESSED\ OR\ IMPLIED,\ INCLUDING\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ PURPOSE,\ ARE}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *\ \ DISCLAIMED.}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00030\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00031\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \textcolor{preprocessor}{\#ifndef\ AAX\_QUANTIZE\_H}}
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#define\ AAX\_QUANTIZE\_H}}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00542}{AAX.h}}"{}}}
\DoxyCodeLine{00037\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00845}{AAX\_PlatformOptimizationConstants.h}}"{}}}
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00842}{AAX\_Constants.h}}"{}}}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#if\ !\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#if\ \_MSC\_VER\ \&\&\ !defined(\_\_INTEL\_COMPILER)}}
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#define\ \_MM\_FUNCTIONALITY}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <intrin.h>}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#elif\ LINUX\_VERSION}}
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#elif\ TARGET\_OS\_IPHONE}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#elif\ defined(\_\_arm\_\_)}}
\DoxyCodeLine{00048\ \textcolor{preprocessor}{\#elif\ defined(\_\_arm64\_\_)}}
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00050\ \textcolor{comment}{//\ GNU\ or\ INTEL:}}
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#include\ <xmmintrin.h>}}
\DoxyCodeLine{00052\ \textcolor{preprocessor}{\#include\ <pmmintrin.h>}}
\DoxyCodeLine{00053\ \textcolor{preprocessor}{\#include\ <tmmintrin.h>}}
\DoxyCodeLine{00054\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00056\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{a00948}{AAX}}}
\DoxyCodeLine{00059\ \{}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \textcolor{comment}{//This\ assumes\ the\ floating\ point\ processor\ is\ in\ 64\ bit\ IEEE\ mode.}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#if\ !\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00063\ \ \ \ \ }
\DoxyCodeLine{00064\ \textcolor{comment}{//\ For\ double-\/>Int32\ conversion}}
\DoxyCodeLine{00065\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ cDouble2IntBias\ =\ ldexpf(1,52)*1.5;}
\DoxyCodeLine{00066\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ cOneHalfOffset\ =\ 0.5;}
\DoxyCodeLine{00067\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int32\_t\ cMantisaWord\ =\ \mbox{\hyperlink{a00948_af4c24d9d2042fe4252db5431ef126d00}{cBigEndian}};}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \textcolor{comment}{//\ For\ double-\/>Int64\ conversion}}
\DoxyCodeLine{00070\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ kExponentMagicDelta\ \ \ \ \ \ \ \ \ =\ 1.5e-\/8;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//1e\string^(number\ of\ exp\ bit)}}
\DoxyCodeLine{00071\ \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{00072\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int64\_t\ \ \ \ \ \ \ \ kBigMantissaMagicMask\ \ \ \ \ \ \ =\ 0x1fffffffffffffLL;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//2\string^52\ *\ 1.5\ mask,\ }}
\DoxyCodeLine{00073\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ int64\_t\ \ \ \ \ \ \ \ kBigMantissaMagicInt\ \ \ \ \ \ \ \ =\ 0x18000000000000LL;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//2\string^52\ *\ 1.5,\ \ uses\ limited\ precisicion\ to\ floor}}
\DoxyCodeLine{00074\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \textcolor{comment}{/*===================================================================================================*/}}
\DoxyCodeLine{00077\ \ \ \ \ }
\DoxyCodeLine{00086\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00948_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00087\ \{}
\DoxyCodeLine{00088\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00089\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_dpint(iVal);\ }
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00092\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00093\ \ \ \ \ iVal\ +=\ cDouble2IntBias;}
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keywordflow}{return}\ (\textcolor{keyword}{reinterpret\_cast<}int32\_t*\textcolor{keyword}{>}(\&iVal))[cMantisaWord];}
\DoxyCodeLine{00095\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00096\ \}}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00106\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00948_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{float}\ iVal)}
\DoxyCodeLine{00107\ \{}
\DoxyCodeLine{00108\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_spint(iVal);\ }
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00112\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00948_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(\textcolor{keywordtype}{double}(iVal));}
\DoxyCodeLine{00114\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00115\ \}}
\DoxyCodeLine{00116\ }
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00120\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00948_ae690c060a5ff4cb96e77335231a29673}{FastRndDbl2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00121\ \{}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00948_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(iVal);}
\DoxyCodeLine{00123\ \}}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00137\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00948_ad2b2872b49146cf0859c403fea702a39}{FastTrunc2Int32}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00138\ \{}
\DoxyCodeLine{00139\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00141\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_dpint(iVal\ -\/\ 0.5);\ }
\DoxyCodeLine{00142\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00143\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00948_af0bbeabd87aa74be4ecca4f767aedc41}{FastRound2Int32}}(iVal\ -\/\ 0.5);}
\DoxyCodeLine{00145\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00146\ \}}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00156\ \textcolor{keyword}{inline}\ int32\_t\ \mbox{\hyperlink{a00948_ad2b2872b49146cf0859c403fea702a39}{FastTrunc2Int32}}(\textcolor{keywordtype}{float}\ iVal)}
\DoxyCodeLine{00157\ \{}
\DoxyCodeLine{00158\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00159\ \ \ \ \ \textcolor{comment}{//\ rounding\ mode\ set\ by\ the\ CSR\ register}}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keyword}{const}\ int32\_t\ r\ =\ \_spint(iVal\ -\/\ 0.5f);\ }
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00162\ \textcolor{preprocessor}{\#elif\ \_MSC\_VER}}
\DoxyCodeLine{00163\ \ \ \ \ int32\_t\ r;}
\DoxyCodeLine{00164\ \ \ \ \ r\ =\ \_mm\_cvtt\_ss2si(\ \_mm\_load\_ss(\&iVal)\ );}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00166\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00167\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}int32\_t\textcolor{keyword}{>}(iVal);}
\DoxyCodeLine{00168\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00169\ \}}
\DoxyCodeLine{00170\ \ \ \ \ }
\DoxyCodeLine{00180\ \textcolor{keyword}{inline}\ int64\_t\ \mbox{\hyperlink{a00948_a7df6b095ea2469f2adce2a895038212e}{FastRound2Int64}}(\textcolor{keywordtype}{double}\ iVal)}
\DoxyCodeLine{00181\ \{}
\DoxyCodeLine{00182\ \textcolor{preprocessor}{\#if\ defined(\ \_TMS320C6X\ )}}
\DoxyCodeLine{00183\ \ \ \ \ \textcolor{keywordflow}{return}\ (int64\_t)(iVal\ >\ 0.0\ ?\ iVal\ +\ 0.5\ :\ iVal\ -\/\ 0.5);}
\DoxyCodeLine{00184\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00185\ \ \ \ \ iVal\ +=\ kExponentMagicDelta;\ \textcolor{comment}{//\ Round\ to\ nearest}}
\DoxyCodeLine{00186\ \ \ \ \ iVal\ +=\ kBigMantissaMagicFloat;\ \textcolor{comment}{//\ Normalize\ to\ integer}}
\DoxyCodeLine{00187\ \ \ \ \ int64\_t\ result\ =\ \ *\textcolor{keyword}{reinterpret\_cast<}int64\_t*\textcolor{keyword}{>}(\&iVal);}
\DoxyCodeLine{00188\ \ \ \ \ result\ \&=\ kBigMantissaMagicMask;\ \textcolor{comment}{//\ Mask\ out\ upper\ bits\ of\ float\ (exponent,\ sign)}}
\DoxyCodeLine{00189\ \ \ \ \ result\ -\/=\ kBigMantissaMagicInt;\ \textcolor{comment}{//\ Normalize\ to\ integer}}
\DoxyCodeLine{00190\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00191\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00192\ \}}
\DoxyCodeLine{00193\ }
\DoxyCodeLine{00194\ \}\ \textcolor{comment}{//\ namespace\ AAX}}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00196\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ AAX\_QUANTIZE\_H}}

\end{DoxyCode}
