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.

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