AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_FastInterpolatedTableLookup.hpp
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 * Copyright 2009-2015, 2023-2024 Avid Technology, Inc.
4 * All rights reserved.
5 *
6 * This file is part of the Avid AAX SDK.
7 *
8 * The AAX SDK is subject to commercial or open-source licensing.
9 *
10 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
11 * Agreement and Avid Privacy Policy.
12 *
13 * AAX SDK License: https://developer.avid.com/aax
14 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
15 *
16 * Or: You may also use this code under the terms of the GPL v3 (see
17 * www.gnu.org/licenses).
18 *
19 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 * DISCLAIMED.
22 */
23/*================================================================================================*/
24
25#ifndef AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
26#define AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
27
28#include "AAX_Quantize.h"
29
30//This version requires that the lookup table is padded with one extra location so we
31//can avoid one of the checks to see if ours pointers are out of bounds.
32template<class TFLOAT, class DFLOAT>
33inline DFLOAT AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFast(const TFLOAT* iTable, DFLOAT iValue) const
34{
35 const TFLOAT aScaledValue=(iValue - mMin)*mTableSizeM1DivMaxMinusMin;
36
37 //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
38 //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.;
39 const TFLOAT aScaledValueLimited = aScaledValue > mTableSizeM1 ? mTableSizeM1 : (aScaledValue > 0.0f ? aScaledValue : 0.0f);
40
41 int aTableIndex=AAX::FastTrunc2Int32(aScaledValueLimited);
42
43 TFLOAT aFracIndex=aScaledValueLimited - TFLOAT(aTableIndex);
44 TFLOAT aFracIndexM1=1.0f-aFracIndex;
45
46 return (DFLOAT)(iTable[aTableIndex]*aFracIndexM1 + iTable[aTableIndex+1]*aFracIndex);
47}
48
49//This version requires that the lookup table is padded with one extra location so we
50//can avoid one of the checks to see if ours pointers are out of bounds.
51template<class TFLOAT, class DFLOAT>
52inline void AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFastMulti(const TFLOAT* iTable, DFLOAT iValue, DFLOAT* oValues) const
53{
54 TFLOAT aScaledValue=(iValue - mMin)*mTableSizeM1DivMaxMinusMin;
55
56 //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
57 //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.
58 const TFLOAT aScaledValueLimited = aScaledValue > mTableSizeM1 ? mTableSizeM1 : (aScaledValue > 0.0f ? aScaledValue : 0.0f);
59
60 int aTableIndex=AAX::FastTrunc2Int32(aScaledValueLimited);
61
62 TFLOAT aFracIndex=aScaledValueLimited - TFLOAT(aTableIndex);
63 TFLOAT aFracIndexM1=1.0f-aFracIndex;
64
65 aTableIndex=aTableIndex*mNumTables;
66 int aTableIndexPlus1=aTableIndex+mNumTables;
67
68 for(int i=0; i<mNumTables; i++)
69 {
70 oValues[i]=(DFLOAT)(iTable[aTableIndex++]*aFracIndexM1 + iTable[aTableIndexPlus1++]*aFracIndex);
71 }
72}
73
74//Block version of table lookup
75template<class TFLOAT, class DFLOAT>
76inline void AAX_FastInterpolatedTableLookup<TFLOAT,DFLOAT>::DoTableLookupExtraFast(const TFLOAT* const iTable, const TFLOAT* const inpBuf, DFLOAT* const outBuf, int blockSize)
77{
78#if defined( _TMS320C6700 )
79 const int r = 16;
80 #pragma MUST_ITERATE(r, , r);
81#endif
82 for (int i = 0; i < blockSize; i++)
83 {
84 outBuf[i] = DoTableLookupExtraFast(iTable, inpBuf[i]);
85 }
86 return;
87}
88
89#endif // AAX_FASTINTERPOLATEDTABLELOOKUP_HPP
Quantization utilities.
int32_t FastTrunc2Int32(double iVal)
Float to Int conversion with truncation.
Definition: AAX_Quantize.h:137
void DoTableLookupExtraFastMulti(const TFLOAT *iTable, DFLOAT iValue, DFLOAT *oValues) const
Definition: AAX_FastInterpolatedTableLookup.hpp:52
DFLOAT DoTableLookupExtraFast(const TFLOAT *const iTable, DFLOAT iValue) const
Perform an extra fast table lookup :)
Definition: AAX_FastInterpolatedTableLookup.hpp:33