AudioCoefInterpolator.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* //device/include/server/AudioFlinger/AudioCoefInterpolator.h
  2. **
  3. ** Copyright 2007, The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #ifndef ANDROID_AUDIO_COEF_INTERPOLATOR_H
  18. #define ANDROID_AUDIO_COEF_INTERPOLATOR_H
  19. #include "AudioCommon.h"
  20. namespace android {
  21. // A helper class for linear interpolation of N-D -> M-D coefficient tables.
  22. // This class provides support for out-of-range indexes.
  23. // Details:
  24. // The purpose is efficient approximation of a N-dimensional vector to
  25. // M-dimensional function. The approximation is based on a table of output
  26. // values on a uniform grid of the input values. Values not on the grid are
  27. // linearly interpolated.
  28. // Access to values are done by specifying input values in table index units,
  29. // having an integer and a fractional part, e.g. retrieving a value from index
  30. // 1.4 will result in linear interpolation between index 1 and index 2.
  31. class AudioCoefInterpolator {
  32. public:
  33. // Constructor.
  34. // nInDims Number of input dimensions (limited to MAX_IN_DIMS).
  35. // inDims An array of size nInDims with the size of the table on each
  36. // respective dimension.
  37. // nOutDims Number of output dimensions (limited to MAX_OUT_DIMS).
  38. // table The coefficient table. Should be of size:
  39. // inDims[0]*inDims[1]*...*inDims[nInDims-1]*nOutDims, where
  40. // func([i,j,k]) = table(i,j,k,:)
  41. AudioCoefInterpolator(size_t nInDims, const size_t inDims[],
  42. size_t nOutDims, const audio_coef_t * table);
  43. // Get the value of the approximated function at a given point.
  44. // intCoord The integer part of the input value. Should be an array of
  45. // size nInDims.
  46. // fracCoord The fractional part of the input value. Should be an array
  47. // of size nInDims. This value is in 32-bit precision.
  48. // out An array for the output value. Should be of size nOutDims.
  49. void getCoef(const int intCoord[], uint32_t fracCoord[], audio_coef_t out[]);
  50. private:
  51. // Maximum allowed number of input dimensions.
  52. static const size_t MAX_IN_DIMS = 8;
  53. // Maximum allowed number of output dimensions.
  54. static const size_t MAX_OUT_DIMS = 8;
  55. // Number of input dimensions.
  56. size_t mNumInDims;
  57. // Number of input dimensions.
  58. size_t mInDims[MAX_IN_DIMS];
  59. // The offset between two consecutive indexes of each dimension. This is in
  60. // fact a cumulative product of mInDims (done in reverse).
  61. size_t mInDimOffsets[MAX_IN_DIMS];
  62. // Number of output dimensions.
  63. size_t mNumOutDims;
  64. // The coefficient table.
  65. const audio_coef_t * mTable;
  66. // A recursive function for getting an interpolated coefficient value.
  67. // The recursion depth is the number of input dimensions.
  68. // At each step, we fetch two interpolated values of the current dimension,
  69. // by two recursive calls to this method for the next dimensions. We then
  70. // linearly interpolate these values over the current dimension.
  71. // index The linear integer index of the value we need to interpolate.
  72. // fracCoord A vector of fractional coordinates for each of the input
  73. // dimensions.
  74. // out Where the output should be written. Needs to be of size
  75. // mNumOutDims.
  76. // dim The input dimensions we are currently interpolating. This
  77. // value will be increased on recursive calls.
  78. void getCoefRecurse(size_t index, const uint32_t fracCoord[],
  79. audio_coef_t out[], size_t dim);
  80. // Scalar interpolation of two data points.
  81. // lo The first data point.
  82. // hi The second data point.
  83. // frac A 32-bit fraction designating the weight of the second point.
  84. static audio_coef_t interp(audio_coef_t lo, audio_coef_t hi, uint32_t frac);
  85. };
  86. }
  87. #endif // ANDROID_AUDIO_COEF_INTERPOLATOR_H