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