Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. template <int k>
  20. struct LagrangeResampleHelper
  21. {
  22. static forcedinline void calc (float& a, float b) noexcept { a *= b * (1.0f / k); }
  23. };
  24. template <>
  25. struct LagrangeResampleHelper<0>
  26. {
  27. static forcedinline void calc (float&, float) noexcept {}
  28. };
  29. template <int k>
  30. static float calcCoefficient (float input, float offset) noexcept
  31. {
  32. LagrangeResampleHelper<0 - k>::calc (input, -2.0f - offset);
  33. LagrangeResampleHelper<1 - k>::calc (input, -1.0f - offset);
  34. LagrangeResampleHelper<2 - k>::calc (input, 0.0f - offset);
  35. LagrangeResampleHelper<3 - k>::calc (input, 1.0f - offset);
  36. LagrangeResampleHelper<4 - k>::calc (input, 2.0f - offset);
  37. return input;
  38. }
  39. float Interpolators::LagrangeTraits::valueAtOffset (const float* inputs, float offset, int index) noexcept
  40. {
  41. float result = 0.0f;
  42. result += calcCoefficient<0> (inputs[index], offset); if (++index == 5) index = 0;
  43. result += calcCoefficient<1> (inputs[index], offset); if (++index == 5) index = 0;
  44. result += calcCoefficient<2> (inputs[index], offset); if (++index == 5) index = 0;
  45. result += calcCoefficient<3> (inputs[index], offset); if (++index == 5) index = 0;
  46. result += calcCoefficient<4> (inputs[index], offset);
  47. return result;
  48. }
  49. } // namespace juce