CSL  6.0
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:
58  RectangularWindow(unsigned windowSize) : Window(windowSize) { }
59  RectangularWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
61 
62 protected:
63  void fillWindow();
64 };
65 
66 /// TriangularWindow:A triangularWindow window.
67 
68 class TriangularWindow : public Window {
69 public:
71  TriangularWindow(unsigned windowSize) : Window(windowSize) { }
72  TriangularWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
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 
85  HammingWindow(unsigned windowSize) : Window(windowSize) { }
86  HammingWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
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) { }
101 
102 protected:
103  void fillWindow();
104 };
105 
106 /// BlackmanWindow
107 
108 class BlackmanWindow : public Window {
109 public:
111  BlackmanWindow(unsigned windowSize) : Window(windowSize) { }
112  BlackmanWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
114 
115 protected:
116  void fillWindow();
117 };
118 
119 /// BlackmanHarrisWindow
120 
121 class BlackmanHarrisWindow : public Window {
122 public:
124  BlackmanHarrisWindow(unsigned windowSize) : Window(windowSize) { }
125  BlackmanHarrisWindow(unsigned windowSize, float gain) : Window(windowSize, gain) { }
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) { }
140 
141 protected:
142  void fillWindow();
143 };
144 
145 } // end of namespace
146 
147 #endif
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
TriangularWindow(unsigned windowSize)
Definition: Window.h:71
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:101
virtual void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:58
TriangularWindow:A triangularWindow window.
Definition: Window.h:68
WelchWindow(unsigned windowSize, float gain)
Definition: Window.h:138
HannWindow(unsigned windowSize, float gain)
Definition: Window.h:99
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
WelchWindow(unsigned windowSize)
Definition: Window.h:137
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
Definition: CSL_Core.cpp:66
SampleBuffer window()
Definition: Window.h:39
RectangularWindow:A rectangular window has all values set to the Gain value, or by default to 1...
Definition: Window.h:55
float mGain
gain for the window
Definition: Window.h:48
RectangularWindow(unsigned windowSize, float gain)
Definition: Window.h:59
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:86
Window; The superclass of all other window function classes in CSL. Subclasses need only to implement...
Definition: Window.h:30
void setGain(float gain)
Set the gain to which the window should be normalized.
Definition: Window.cpp:25
BlackmanHarrisWindow(unsigned windowSize)
Definition: Window.h:124
Buffer mWindowBuffer
used to store the window
Definition: Window.h:45
void dump()
Print some info about the window.
Definition: Window.cpp:130
BlackmanHarrisWindow.
Definition: Window.h:121
TriangularWindow(unsigned windowSize, float gain)
Definition: Window.h:72
HammingWindow: Belongs to the familly of cosine window functions.
Definition: Window.h:81
unsigned mWindowBufferPos
where am I in the window buffer
Definition: Window.h:46
unsigned mWindowSize
length in samples of the window
Definition: Window.h:47
HannWindow.
Definition: Window.h:95
void setSize(unsigned windowSize)
Set the number of samples the window spans.
Definition: Window.cpp:30
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:119
WelchWindow: This is basically an equal-power curve.
Definition: Window.h:134
HammingWindow(unsigned windowSize)
Definition: Window.h:85
BlackmanWindow(unsigned windowSize)
Definition: Window.h:111
HannWindow(unsigned windowSize)
Definition: Window.h:98
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:65
BlackmanWindow.
Definition: Window.h:108
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:93
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:71
BlackmanWindow(unsigned windowSize, float gain)
Definition: Window.h:112
forward declaration
Definition: CSL_Core.h:241
HammingWindow(unsigned windowSize, float gain)
Definition: Window.h:86
~Window()
clean-up . . . free the allocated buffer that held the window data.
Definition: Window.cpp:21
void fillWindow()
subclasses override this to fill the buffer with corresponding function.
Definition: Window.cpp:109
RectangularWindow(unsigned windowSize)
Definition: Window.h:58
BlackmanHarrisWindow(unsigned windowSize, float gain)
Definition: Window.h:125
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
Returns a pointer to the window data.
Definition: Window.cpp:40
Base class of CSL exceptions (written upper-case). Has a string message.
Window()
Creates a window using the default Gestalt size and a gain of 1; < Creates a window (hann) with the s...
Definition: Window.cpp:11