50 static inline int irint(
float f) {
return (
int)(f+0.5); }
51 static inline int irint(
double f) {
return (
int)(f+0.5); }
52 static inline int min(
int a,
int b) {
return (a<b)?a:b; }
53 static inline int max(
int a,
int b) {
return (a>b)?a:b; }
67 for(
int i=0; i<size; i++ )
77 if( window_centre < 0 ) {
79 const float k = 2.0 / (float)size;
86 r_window[end-i] = r_window[i];
91 const float k_left = 1.0 / (float) (window_centre+1);
92 const float k_right = 1.0 / (float) (size-(window_centre+1));
98 r_window[i] = i * k_left;
101 const int righthand_size = size-1-window_centre;
102 for( i=0; i<righthand_size; ++i )
103 r_window[end-i] = i * k_right;
114 if( window_centre < 0 ){
121 k = 2.0 *
M_PI / size;
123 r_window[end-i] = r_window[i] = 0.5 - 0.5 * cos(k * (i + 0.5));
130 int effective_size = (2*window_centre)+1;
131 k = 2.0 *
M_PI / effective_size;
133 r_window[i] = 0.5 - 0.5 * cos(k * (i + 0.5));
136 const int righthand_size = size-1-window_centre;
137 effective_size = (2*righthand_size)+1;
138 k = 2.0 *
M_PI / effective_size;
139 for( i=0; i<righthand_size; ++i )
140 r_window[end-i] = 0.5 - 0.5 * cos(k * (i + 0.5));
147 int i, c, end=size-1;
151 if( window_centre < 0 ){
153 k = 2.0 *
M_PI / size;
158 for( i=0; i<c; i++ ){
159 r_window[i] = 0.54 - 0.46 * cos(k * (i + 0.5));
160 r_window[end-i] = r_window[i];
168 int effective_size = (2*window_centre)+1;
169 k = 2.0 *
M_PI / effective_size;
170 for( i=0; i<c ; ++i )
171 r_window[i] = 0.54 - 0.46 * cos(k * (i + 0.5));
174 const int righthand_size = size-1-window_centre;
175 effective_size = (2*righthand_size)+1;
176 k = 2.0 *
M_PI / effective_size;
177 for( i=0; i<righthand_size; ++i )
178 r_window[end-i] = 0.54 - 0.46 * cos(k * (i + 0.5));
196 typedef struct Info {
198 const char *description;
204 {
NULL,
"unknown window type"}},
206 {Rectangular,
"Rectangular window"}},
208 {Triangular,
"Triangular window"}},
210 {Hanning,
"Hanning window"}},
212 {Hamming,
"Hamming window"}},
225 cerr <<
"no such window type %s" << name << endl;
243 static float find_dc(
const EST_Wave &sig,
int start,
int size)
248 start =
max(0, start);
253 for(i=0; i<size; i++)
256 return (sum / (
float)size);
260 const char *name,
int window_centre )
264 make_window(size, window_vals, window_centre);
268 const char *name,
int window_centre )
273 make_window(size, fwindow, window_centre);
275 for (
int i = 0; i < size; ++i)
276 window_vals[i] = fwindow[i];
289 make_window(size, window_vals,-1);
291 dc = find_dc(sig, start, size);
298 for(i=0; i<size && start+i<0; i++)
302 window[i] = (window_vals(i) * (sig.
a(start + i) - dc) + dc);
315 window_signal(sig, wf, start, size, frame, resize);
325 make_window(size, window_vals,-1);
343 else if (frame.
length() < size)
345 cerr <<
"Frame is wrong size: expected " << size <<
" got " 346 << frame.
length() << endl;
357 dc = find_dc(sig, start, size);
364 for(i = 0; i < size && start+i< 0; i++)
367 for (; (i < size) && (start + i < sig.
num_samples()); i++)
370 for(; i < frame.
length(); i++)
389 for(
int n=0; n< map.
n() ; n++)
392 const char *d = map.
info(map.
token(n)).description;
403 for(
int n=0; n< map.
n() ; n++)
416 #if defined(INSTANTIATE_TEMPLATES) 418 #include "../base_class/EST_TNamedEnum.cc" A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
float end(const EST_Item &item)
static Func * creator(const char *name, bool report_error=false)
Return the creation function for the given window type.
static void window_signal(const EST_Wave &sig, EST_WindowFunc *make_window, int start, int size, EST_TBuffer< float > &frame)
static EST_String description(const char *name)
Return the description for a given window type.
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
void ensure(unsigned int req_size)
Extend if needed, copying existing data.
INLINE const T & a_no_check(ssize_t n) const
read-only const access operator: without bounds checking
static EST_String options_supported(void)
Return a paragraph describing the available windows.
ssize_t num_samples() const
return the number of samples in the waveform
static void make_window(EST_TBuffer< float > &window_vals, int size, const char *name, int window_centre)
short & a(ssize_t i, ssize_t channel=0)
ENUM token(const char *value) const
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)
float max(float a, float b)
const char * name(ENUM tok, int n=0) const
INLINE ssize_t length() const
number of items in vector.
INLINE short & a_no_check(ssize_t i, ssize_t channel=0)
float min(float a, float b)
void EST_WindowFunc(int size, EST_TBuffer< float > &r_window, int window_centre)
Function which creates a window.
EST_WindowFunc Func
A function which creates a window.
INFO & info(ENUM token) const
float start(const EST_Item &item)
float sum(const EST_FMatrix &a)
sum of elements
void resize(int n, int set=1)
resize vector
static EST_String options_short(void)
Return a comma separated list of the available window types.