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.

113 lines
4.2KB

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