The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

105 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. namespace dsp
  16. {
  17. /**
  18. A class which provides multiple windowing functions useful for filter design
  19. and spectrum analyzers.
  20. The different functions provided here can be used by creating either a
  21. WindowingFunction object, or a static function to fill an array with the
  22. windowing method samples.
  23. @tags{DSP}
  24. */
  25. template <typename FloatType>
  26. class JUCE_API WindowingFunction
  27. {
  28. public:
  29. //==============================================================================
  30. /** The windowing methods available. */
  31. enum WindowingMethod
  32. {
  33. rectangular = 0,
  34. triangular,
  35. hann,
  36. hamming,
  37. blackman,
  38. blackmanHarris,
  39. flatTop,
  40. kaiser,
  41. numWindowingMethods
  42. };
  43. //==============================================================================
  44. /** This constructor automatically fills a buffer of the specified size using
  45. the fillWindowingTables function and the specified arguments.
  46. @see fillWindowingTables
  47. */
  48. WindowingFunction (size_t size, WindowingMethod,
  49. bool normalise = true, FloatType beta = 0);
  50. //==============================================================================
  51. /** Fills the content of the object array with a given windowing method table.
  52. @param size the size of the destination buffer allocated in the object
  53. @param type the type of windowing method being used
  54. @param normalise if the result must be normalised, creating a DC amplitude
  55. response of one
  56. @param beta an optional argument useful only for Kaiser's method
  57. which must be positive and sets the properties of the
  58. method (bandwidth and attenuation increases with beta)
  59. */
  60. void fillWindowingTables (size_t size, WindowingMethod type,
  61. bool normalise = true, FloatType beta = 0) noexcept;
  62. /** Fills the content of an array with a given windowing method table.
  63. @param samples the destination buffer pointer
  64. @param size the size of the destination buffer allocated in the object
  65. @param normalise if the result must be normalised, creating a DC amplitude
  66. response of one
  67. @param beta an optional argument useful only for Kaiser's method,
  68. which must be positive and sets the properties of the
  69. method (bandwidth and attenuation increases with beta)
  70. */
  71. static void fillWindowingTables (FloatType* samples, size_t size, WindowingMethod,
  72. bool normalise = true, FloatType beta = 0) noexcept;
  73. /** Multiplies the content of a buffer with the given window. */
  74. void multiplyWithWindowingTable (FloatType* samples, size_t size) noexcept;
  75. /** Returns the name of a given windowing method. */
  76. static const char* getWindowingMethodName (WindowingMethod) noexcept;
  77. private:
  78. //==============================================================================
  79. Array<FloatType> windowTable;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WindowingFunction)
  81. };
  82. } // namespace dsp
  83. } // namespace juce