AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_FastInterpolatedTableLookup.hpp
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  * Copyright 2009-2015 by Avid Technology, Inc.
4  * All rights reserved.
5  *
6  * CONFIDENTIAL: This document contains confidential information. Do not
7  * read or examine this document unless you are an Avid Technology employee
8  * or have signed a non-disclosure agreement with Avid Technology which protects
9  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
10  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
11  * OF Avid Technology, INC.
12  */
13 /*================================================================================================*/
14 
15 #ifndef AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
16 #define AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
17 
18 #include "AAX_Quantize.h"
19 
20 //This version requires that the lookup table is padded with one extra location so we
21 //can avoid one of the checks to see if ours pointers are out of bounds.
22 template<class TFLOAT, class DFLOAT>
23 inline DFLOAT AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFast(const TFLOAT* iTable, DFLOAT iValue) const
24 {
25  const TFLOAT aScaledValue=(iValue - mMin)*mTableSizeM1DivMaxMinusMin;
26 
27  //Clamp between 0.0 and table size, so we don't go out of the table bounds. One thing that's not obvious is this clamp was written
28  //so that it will return 0.0 if a NaN is given as the table input. This keeps us within bounds even if we're feed garbage.;
29  const TFLOAT aScaledValueLimited = aScaledValue > mTableSizeM1 ? mTableSizeM1 : (aScaledValue > 0.0f ? aScaledValue : 0.0f);
30 
31  int aTableIndex=AAX::FastTrunc2Int32(aScaledValueLimited);
32 
33  TFLOAT aFracIndex=aScaledValueLimited - TFLOAT(aTableIndex);
34  TFLOAT aFracIndexM1=1.0f-aFracIndex;
35 
36  return (DFLOAT)(iTable[aTableIndex]*aFracIndexM1 + iTable[aTableIndex+1]*aFracIndex);
37 }
38 
39 //This version requires that the lookup table is padded with one extra location so we
40 //can avoid one of the checks to see if ours pointers are out of bounds.
41 template<class TFLOAT, class DFLOAT>
42 inline void AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFastMulti(const TFLOAT* iTable, DFLOAT iValue, DFLOAT* oValues) const
43 {
44  TFLOAT aScaledValue=(iValue - mMin)*mTableSizeM1DivMaxMinusMin;
45 
46  //Clamp between 0.0 and table size, so we don't go out of the table bounds. One thing that's not obvious is this clamp was written
47  //so that it will return 0.0 if a NaN is given as the table input. This keeps us within bounds even if we're feed garbage.
48  const TFLOAT aScaledValueLimited = aScaledValue > mTableSizeM1 ? mTableSizeM1 : (aScaledValue > 0.0f ? aScaledValue : 0.0f);
49 
50  int aTableIndex=AAX::FastTrunc2Int32(aScaledValueLimited);
51 
52  TFLOAT aFracIndex=aScaledValueLimited - TFLOAT(aTableIndex);
53  TFLOAT aFracIndexM1=1.0f-aFracIndex;
54 
55  aTableIndex=aTableIndex*mNumTables;
56  int aTableIndexPlus1=aTableIndex+mNumTables;
57 
58  for(int i=0; i<mNumTables; i++)
59  {
60  oValues[i]=(DFLOAT)(iTable[aTableIndex++]*aFracIndexM1 + iTable[aTableIndexPlus1++]*aFracIndex);
61  }
62 }
63 
64 //Block version of table lookup
65 template<class TFLOAT, class DFLOAT>
66 inline void AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFast(const TFLOAT* const iTable, const TFLOAT* const inpBuf, DFLOAT* const outBuf, int blockSize)
67 {
68 #if defined( _TMS320C6700 )
69  const int r = 16;
70  #pragma MUST_ITERATE(r, , r);
71 #endif
72  for (int i = 0; i < blockSize; i++)
73  {
74  outBuf[i] = DoTableLookupExtraFast(iTable, inpBuf[i]);
75  }
76  return;
77 }
78 
79 #endif // AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
Quantization utilities.
int32_t FastTrunc2Int32(double iVal)
Float to Int conversion with truncation.
Definition: AAX_Quantize.h:126
void DoTableLookupExtraFastMulti(const TFLOAT *iTable, DFLOAT iValue, DFLOAT *oValues) const
Definition: AAX_FastInterpolatedTableLookup.hpp:42
DFLOAT DoTableLookupExtraFast(const TFLOAT *const iTable, DFLOAT iValue) const
Perform an extra fast table lookup :)
Definition: AAX_FastInterpolatedTableLookup.hpp:23