42#include "EST_system.h"
44#include "sigpr/EST_Window.h"
45#include "EST_TNamedEnum.h"
50static inline int min(
int a,
int b) {
return (a<b)?a:b; }
51static inline int max(
int a,
int b) {
return (a>b)?a:b; }
65 for(
int i=0; i<size; i++ )
77 const float k = 2.0 / (
float)size;
119 k = 2.0 * M_PI / size;
145 int i, c, end=size-1;
151 k = 2.0 * M_PI / size;
156 for( i=0; i<c; i++ ){
168 for( i=0; i<c ; ++i )
176 r_window[end-i] = 0.54 - 0.46 *
cos(k * (i + 0.5));
186typedef enum EST_WindowType {
196 const char *description;
201 { wf_none, {
"none" },
202 {NULL,
"unknown window type"}},
203 { wf_rectangle, {
"rectangle",
"rect",
"rectangular"},
204 {Rectangular,
"Rectangular window"}},
205 { wf_triangle, {
"triangle",
"tri",
"triangular"},
206 {Triangular,
"Triangular window"}},
207 { wf_hanning, {
"hanning",
"han"},
208 {Hanning,
"Hanning window"}},
209 { wf_hamming, {
"hamming",
"ham"},
210 {Hamming,
"Hamming window"}},
211 { wf_none, { NULL }},
218 EST_WindowType key = map.token(name);
223 cerr <<
"no such window type %s" << name <<
endl;
227 return map.info(key).func;
232 EST_WindowType key = map.token(name);
234 return map.info(key).description;
241static float find_dc(
const EST_Wave &
sig,
int start,
int size)
246 start = max(0, start);
247 size = min(size,
sig.num_samples()-start);
249 for(i=0; i<size; i++)
250 sum +=
sig.a_no_check(start+i);
252 return (sum / (
float)size);
268 fwindow.ensure(size, (
bool)FALSE);
271 for (
int i = 0; i < size; ++i)
276 EST_WindowFunc *make_window,
286 window.ensure(size, (
bool)FALSE);
287 dc = find_dc(
sig, start, size);
294 for(i=0; i<size && start+i<0; i++)
297 for(; i<size && start+i <
sig.num_samples(); i++)
315 EST_WindowFunc *make_window,
339 else if (frame.
length() < size)
341 cerr <<
"Frame is wrong size: expected " << size <<
" got "
353 dc = find_dc(
sig, start, size);
360 for(i = 0; i < size && start+i< 0; i++)
363 for (; (i < size) && (start + i <
sig.num_samples()); i++)
366 for(; i < frame.
length(); i++)
385 for(
int n=0; n< map.n() ; n++)
387 const char *
nm = map.name(map.token(n));
388 const char *d = map.info(map.token(n)).description;
399 for(
int n=0; n< map.n() ; n++)
401 const char *
nm = map.name(map.token(n));
412#if defined(INSTANTIATE_TEMPLATES)
414#include "../base_class/EST_TNamedEnum.cc"
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
void resize(int n, int set=1)
resize vector
INLINE int length() const
number of items in vector.
INLINE const T & a_no_check(int n) const
read-only const access operator: without bounds checking
static EST_String options_supported(void)
Return a paragraph describing the available windows.
static EST_String description(const char *name)
Return the description for a given window type.
static void window_signal(const EST_Wave &sig, EST_WindowFunc *make_window, int start, int size, EST_TBuffer< float > &frame)
static void make_window(EST_TBuffer< float > &window_vals, int size, const char *name, int window_centre)
EST_WindowFunc Func
A function which creates a window.
static EST_String options_short(void)
Return a comma separated list of the available window types.
static Func * creator(const char *name, bool report_error=false)
Return the creation function for the given window type.