Edinburgh Speech Tools  2.1-release
EST_Window.h
Go to the documentation of this file.
1 /************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /************************************************************************/
33 /* */
34 /* Author: Richard Caley and Paul Taylor */
35 /* Date: May 1997, April 98 */
36 /* ------------------------------------------------------------------- */
37 /* Class for windowing speech waveforms */
38 /* */
39 /************************************************************************/
40 
41 #ifndef __EST_WINDOW_H__
42 #define __EST_WINDOW_H__
43 
44 #include "EST_TBuffer.h"
45 #include "EST_Wave.h"
46 
47 /**@defgroup Function types used for parameters to functions.
48 */
49 ///@{
50 
51 /// Function which creates a window.
52 typedef void EST_WindowFunc(int size, EST_TBuffer<float> &r_window, int window_centre );
53 
54 ///@}
55 
56 
57 /** \class EST_Window
58  \brief The EST_Window class provides functions for the creation and use of signal processing windows.
59 
60 Signal processing algorithms often work by on small sections of the
61 speech waveform known as *frames*. A full signal must first be
62 divided into these frames before these algorithms can work. While it
63 would be simple to just "cut out" the required frames from the
64 waveforms, this is usually undesirable as large discontinuities can
65 occur at the frame edges. Instead it is customary to cut out the frame
66 by means of a *window* function, which tapers the signal in the
67 frame so that it has high values in the middle and low or zero values
68 near the frame edges. The EST_Window class provides a wrap
69 around for such windowing operations.
70 
71 There are several types of window function, including:
72 
73  - **Rectangular**, which is used to give a simple copy of the the
74 values between the window limits.
75 
76  \f[w_{n} = \left\{ \begin{array}{ll}
77  1 & \mbox{$0 \leq n \leq N$} \\
78  0 & \mbox{otherwise}
79  \end{array}
80  \right. \f]
81 
82  - **Hanning**: The rectangular window can cause sharp discontinuities
83  at window edges. The hanning window solves this by ensuring that the
84  window edges taper to 0.
85 
86  \f[w_{n} = \left\{ \begin{array}{ll}
87  0.5 - 0.5 \cos(2\pi n / (N-1)) & \mbox{$0 \leq n \leq N$} \\
88  0 & \mbox{otherwise}
89  \end{array}
90  \right. \f]
91 
92  - **Hamming**: The hanning window causes considerable energy
93  loss, which the hamming window attempts to rectify.
94 
95 \f[w_{n} = \left\{ \begin{array}{ll}
96 0.54 - 0.46 \cos(2\pi n / (N-1)) & \mbox{$0 \leq n \leq N$} \\
97 0 & \mbox{otherwise}
98 \end{array}
99 \right. \f]
100 
101 The particular choice of window depends on the application. For
102 instance in most speech synthesis applications Hanning windows are the
103 most suitable as they don't have time domain discontinuities. For
104 analysis applications hamming windows are normally used.
105 
106 
107 For example code, see \ref sigpr-windowing
108 
109 
110 */
111 class EST_Window {
112 public:
113 
114  /// A function which creates a window
116 
117  /**@name Functions for making windows.
118 
119  */
120  ///@{
121 
122  /** Make a Buffer of containing a window function of specified type.
123  If window_centre < 0 (default -1), then a symmetric window is
124  returned. For positive values of the window_centre argument,
125  asymmetric windows are returned.
126  */
127  static void make_window(EST_TBuffer<float> &window_vals, int size,
128  const char *name, int window_centre);
129 
130  /** Make a EST_FVector containing a window function of specified type.
131  If window_centre < 0 (default -1), then a symmetric window is
132  returned. For positive values of the window_centre argument,
133  asymmetric windows are returned.
134  */
135  static void make_window(EST_FVector &window_vals, int size,
136  const char *name, int window_centre);
137 
138  /// Return the creation function for the given window type.
139  static Func *creator(const char *name, bool report_error = false);
140  ///@}
141 
142 /** @name Performing windowing on a section of speech.
143 
144  */
145 
146 ///@{
147 
148  /** Window the waveform `sig` starting at point `start` for
149  a duration of `size` samples. The windowing function required
150  is given as a function pointer `*make_window` which has
151  already been created by a function such as EST_Window::creator.
152  The output windowed frame is placed in the buffer `frame` which
153  will have been resized accordingly within the function.
154  */
155  static void window_signal(const EST_Wave &sig,
157  int start, int size,
158  EST_TBuffer<float> &frame);
159 
160  /** Window the waveform `sig` starting at point `start` for
161  a duration of `size` samples. The windowing function required
162  is given as a function pointer `*make_window` which has
163  already been created by a function such as \ref creator .
164  The output windowed frame is placed in the EST_FVector `frame`.
165  By default, it is assumed that this is already the correct size
166  (i.e. `size` samples long), but if resizing is required the
167  last argument should be set to 1.
168  */
169  static void window_signal(const EST_Wave &sig,
171  int start, int size,
172  EST_FVector &frame,int resize=0);
173 
174  /** Window the waveform `sig` starting at point `start` for
175  a duration of `size` samples. The windowing function required
176  is given as a string: this function will make a temporary window
177  of this type. The output windowed frame is placed in the
178  EST_FVector `frame`. By default, it is assumed that this is
179  already the correct size (i.e. `size` samples long), but if
180  resizing is required the last argument should be set to 1. */
181  static void window_signal(const EST_Wave &sig,
182  const EST_String &window_name,
183  int start, int size,
184  EST_FVector &frame, int resize=0);
185 
186 
187  /** Window the waveform `sig` starting at point `start` for
188  a duration of `size` samples. The window shape required
189  is given as an array of floats. The output windowed frame is placed in the
190  EST_FVector `frame`. By default, it is assumed that this is
191  already the correct size (i.e. `size` samples long), but if
192  resizing is required the last argument should be set to 1. */
193  static void window_signal(const EST_Wave &sig,
194  EST_TBuffer<float> &window_vals,
195  int start, int size,
196  EST_FVector &frame, int resize=0);
197 
198 ///@}
199 
200 
201 /**@name Utility window functions.
202 
203 */
204 ///@{
205  /// Return the description for a given window type.
206  static EST_String description(const char *name);
207 
208  /// Return a paragraph describing the available windows.
209  static EST_String options_supported(void);
210 
211  /// Return a comma separated list of the available window types.
212  static EST_String options_short(void);
213 
214 ///@}
215 };
216 
217 ///For example code, see \ref Windowing .
218 
219 ///@see Windowing mechanisms
220 
221 
222 
223 
224 
225 #endif
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
static Func * creator(const char *name, bool report_error=false)
Return the creation function for the given window type.
Definition: EST_Window.cc:218
static void window_signal(const EST_Wave &sig, EST_WindowFunc *make_window, int start, int size, EST_TBuffer< float > &frame)
Definition: EST_Window.cc:279
static EST_String description(const char *name)
Return the description for a given window type.
Definition: EST_Window.cc:232
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
Definition: EST_FMatrix.h:119
static EST_String options_supported(void)
Return a paragraph describing the available windows.
Definition: EST_Window.cc:385
static void make_window(EST_TBuffer< float > &window_vals, int size, const char *name, int window_centre)
Definition: EST_Window.cc:259
The EST_Window class provides functions for the creation and use of signal processing windows...
Definition: EST_Window.h:111
void EST_WindowFunc(int size, EST_TBuffer< float > &r_window, int window_centre)
Function which creates a window.
Definition: EST_Window.h:52
EST_WindowFunc Func
A function which creates a window.
Definition: EST_Window.h:115
float start(const EST_Item &item)
Definition: EST_item_aux.cc:52
Extending buffer class.
Definition: EST_TBuffer.h:86
static EST_String options_short(void)
Return a comma separated list of the available window types.
Definition: EST_Window.cc:399