CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Window.h
Go to the documentation of this file.
1 ///
2 /// Window.h -- specification of the various function window classes
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5 /// Helper class for other classes that need a signal to be windowed. For example, to perform an FFT
6 /// usually is better to apply a window function to the signal to get beter results.
7 /// Usage (two ways to be used):
8 /// a) Instantiate a window object (for example Window myWindow(512, 1);) and then call the window()
9 /// function to get a pointer to the window buffer.
10 /// or...
11 /// b) call the nextBuffer on the window, so it fills a buffer with itself, wraping around if the buffer
12 /// passed is larger.
13 ///
14 /// The size should be specified in samples.
15 ///
16 /// TODO:
17 /// a) Add more window types.
18 ///
19
20 #ifndef CSL_WINDOW_H
21 #define CSL_WINDOW_H
22
23 #include "CSL_Core.h"
24
25 namespace csl {
26
27 /// Window; The superclass of all other window function classes in CSL.
28 /// Subclasses need only to implement the fillWindow(); and the Constructors.
29
30 class Window : public UnitGenerator {
31 public: // Constructors:
32 Window(); ///< Creates a window using the default Gestalt size and a gain of 1;
33 ///< Creates a window (hann) with the specified size and gain (gain is optional).
34 Window(unsigned windowSize, float gain = 1);
35 ~Window(); ///< clean-up . . . free the allocated buffer that held the window data.
36
37 void setSize(unsigned windowSize); ///< Set the number of samples the window spans.
38 void setGain(float gain); ///< Set the gain to which the window should be normalized.
39 SampleBuffer window() { return mWindowBuffer.buffer(0); }; ///< Returns a pointer to the window data.
40
41 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
42 void dump(); ///< Print some info about the window.
43
44 protected:
45 Buffer mWindowBuffer; ///< used to store the window
46 unsigned mWindowBufferPos; ///< where am I in the window buffer
47 unsigned mWindowSize; ///< length in samples of the window
48 float mGain; ///< gain for the window
49
50 virtual void fillWindow(); ///< subclasses override this to fill the buffer with corresponding function.
51 };
52
53 /// RectangularWindow:A rectangular window has all values set to the Gain value, or by default to 1.
54
55 class RectangularWindow : public Window {
56 public:
57 RectangularWindow() : Window() { }
58 RectangularWindow(unsigned windowSize) : Window(windowSize) { }
59 RectangularWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
60 ~RectangularWindow() { }
61
62 protected:
63 void fillWindow();
64 };
65
66 /// TriangularWindow:A triangularWindow window.
67
68 class TriangularWindow : public Window {
69 public:
70 TriangularWindow() : Window() { }
71 TriangularWindow(unsigned windowSize) : Window(windowSize) { }
72 TriangularWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
73 ~TriangularWindow() { }
74
75 protected:
76 void fillWindow();
77 };
78
79 /// HammingWindow: Belongs to the familly of cosine window functions.
80
81 class HammingWindow : public Window {
82 public:
83
84 HammingWindow() : Window() { }
85 HammingWindow(unsigned windowSize) : Window(windowSize) { }
86 HammingWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
87 ~HammingWindow() { }
88
89 protected:
90 void fillWindow();
91 };
92
93 /// HannWindow
94
95 class HannWindow : public Window {
96 public:
97 HannWindow() : Window() { }
98 HannWindow(unsigned windowSize) : Window(windowSize) { }
99 HannWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
100 ~HannWindow() { }
101
102 protected:
103 void fillWindow();
104 };
105
106 /// BlackmanWindow
107
108 class BlackmanWindow : public Window {
109 public:
110 BlackmanWindow() : Window() { }
111 BlackmanWindow(unsigned windowSize) : Window(windowSize) { }
112 BlackmanWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
113 ~BlackmanWindow() { }
114
115 protected:
116 void fillWindow();
117 };
118
119 /// BlackmanHarrisWindow
120
121 class BlackmanHarrisWindow : public Window {
122 public:
123 BlackmanHarrisWindow() : Window() { }
124 BlackmanHarrisWindow(unsigned windowSize) : Window(windowSize) { }
125 BlackmanHarrisWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
126 ~BlackmanHarrisWindow() { }
127
128 protected:
129 void fillWindow();
130 };
131
132 /// WelchWindow: This is basically an equal-power curve.
133
134 class WelchWindow : public Window {
135 public:
136 WelchWindow() : Window() { }
137 WelchWindow(unsigned windowSize) : Window(windowSize) { }
138 WelchWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
139 ~WelchWindow() { }
140
141 protected:
142 void fillWindow();
143 };
144
145 } // end of namespace
146
147 #endif