Edinburgh Speech Tools  2.4-release
EST_Window.h
1 /************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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 /**@name 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 /** The EST_Window class provides functions for the creation and use
58 of signal processing windows.
59
60 Signal processing algorithms often work by on small sections of the
61 speech waveform known as {\em 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 \{em 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 \Ref{EST_Window} class provides a wrap
69 around for such windowing operations.
70
71 There are several types of window function, including:
72
73 \begin{itemize}
74
75 \item {\bf Rectangular}, which is used to give a simple copy of the the
76 values between the window limits.
77
78 $w_{n} = \left\{ \begin{array}{ll} 79 1 & \mbox{0 \leq n \leq N} \\ 80 0 & \mbox{otherwise} 81 \end{array} 82 \right.$
83
84 \item {\bf Hanning}. The rectangular window can cause sharp discontinuities
85 at window edges. The hanning window solves this by ensuring that the
86 window edges taper to 0.
87
88 $w_{n} = \left\{ \begin{array}{ll} 89 0.5 - 0.5 \cos(2\pi n / (N-1)) & \mbox{0 \leq n \leq N} \\ 90 0 & \mbox{otherwise} 91 \end{array} 92 \right.$
93
94 \item {\bf Hamming.} The hanning window causes considerable energy
95 loss, which the hamming window attempts to rectify.
96
97 $w_{n} = \left\{ \begin{array}{ll} 98 0.54 - 0.46 \cos(2\pi n / (N-1)) & \mbox{0 \leq n \leq N} \\ 99 0 & \mbox{otherwise} 100 \end{array} 101 \right.$
102
103 \end{itemize}
104
105 The particular choice of window depends on the application. For
106 instance in most speech synthesis applications Hanning windows are the
107 most suitable as they don't have time domain discontinuities. For
108 analysis applications hamming windows are normally used.
109
110
111 For example code, see \Ref{Windowing}
112
113
114 */
115
116 class EST_Window {
117 public:
118
119  /// A function which creates a window
120  typedef EST_WindowFunc Func;
121
122  /**@name Functions for making windows.
123
124  */
125  //@{
126
127  /** Make a Buffer of containing a window function of specified type.
128  If window_centre < 0 (default -1), then a symmetric window is
129  returned. For positive values of the window_centre argument,
130  asymmetric windows are returned.
131  */
132  static void make_window(EST_TBuffer<float> &window_vals, int size,
133  const char *name, int window_centre);
134
135  /** Make a EST_FVector containing a window function of specified type.
136  If window_centre < 0 (default -1), then a symmetric window is
137  returned. For positive values of the window_centre argument,
138  asymmetric windows are returned.
139  */
140  static void make_window(EST_FVector &window_vals, int size,
141  const char *name, int window_centre);
142
143  /// Return the creation function for the given window type.
144  static Func *creator(const char *name, bool report_error = false);
145  //@}
146
147 /** @name Performing windowing on a section of speech.
148
149  */
150
151 //@{
152
153  /** Window the waveform {\tt sig} starting at point {\tt start} for
154  a duration of {\tt size} samples. The windowing function required
155  is given as a function pointer {\tt *make_window} which has
156  already been created by a function such as \Ref{creator}.
157  The output windowed frame is placed in the buffer {\tt frame} which
158  will have been resized accordingly within the function.
159  */
160
161  static void window_signal(const EST_Wave &sig,
162  EST_WindowFunc *make_window,
163  int start, int size,
164  EST_TBuffer<float> &frame);
165
166  /** Window the waveform {\tt sig} starting at point {\tt start} for
167  a duration of {\tt size} samples. The windowing function required
168  is given as a function pointer {\tt *make_window} which has
169  already been created by a function such as \Ref{creator}.
170  The output windowed frame is placed in the EST_FVector {\tt frame}.
171  By default, it is assumed that this is already the correct size
172  (i.e. {\tt size} samples long), but if resizing is required the
173  last argument should be set to 1.
174  */
175
176  static void window_signal(const EST_Wave &sig,
177  EST_WindowFunc *make_window,
178  int start, int size,
179  EST_FVector &frame,int resize=0);
180
181  /** Window the waveform {\tt sig} starting at point {\tt start} for
182  a duration of {\tt size} samples. The windowing function required
183  is given as a string: this function will make a temporary window
184  of this type. The output windowed frame is placed in the
185  EST_FVector {\tt frame}. By default, it is assumed that this is
186  already the correct size (i.e. {\tt size} samples long), but if
187  resizing is required the last argument should be set to 1. */
188
189  static void window_signal(const EST_Wave &sig,
190  const EST_String &window_name,
191  int start, int size,
192  EST_FVector &frame, int resize=0);
193
194
195  /** Window the waveform {\tt sig} starting at point {\tt start} for
196  a duration of {\tt size} samples. The window shape required
197  is given as an array of floats. The output windowed frame is placed in the
198  EST_FVector {\tt frame}. By default, it is assumed that this is
199  already the correct size (i.e. {\tt size} samples long), but if
200  resizing is required the last argument should be set to 1. */
201  static void window_signal(const EST_Wave &sig,
202  EST_TBuffer<float> &window_vals,
203  int start, int size,
204  EST_FVector &frame, int resize=0);
205
206 //@}
207
208
209 /**@name Utility window functions.
210
211 */
212 //@{
213  /// Return the description for a given window type.
214  static EST_String description(const char *name);
215
216  /// Return a paragraph describing the available windows.
217  static EST_String options_supported(void);
218
219  /// Return a comma separated list of the available window types.
220  static EST_String options_short(void);
221
222 //@}
223 };
224
225 ///For example code, see \Ref{Windowing}.
226
227 //@see Windowing mechanisms
228
229
230
231
232
233 #endif