61 for (j = 1; j < a.
n(); ++j)
62 s += a(j) * (float)sig.
a_safe(i - j);
64 sig.
a(i) = (short) s + res.
a(i);
73 for (i = 0; i < a.
n(); ++i)
76 for (j = 1; j < a.
n(); ++j)
83 for (j = 1; j < a.
n(); ++j)
123 lpc.
frame(filter, i);
125 if (size < filter.
n())
128 in_sig.
sub_wave(in_sub, start, size);
141 for (k = 0, j = start; j <
end; ++j, ++k){
162 for (start = 0, i = 0; i < lpc.
num_frames() - 1; ++i)
168 lpc.
frame(filter, i);
176 if (start < filter.
n())
177 for (k = start; k <
end; ++k)
179 for (s = 0,j = 1; j < filter.
n(); ++j)
184 for (k = start; k <
end; ++k)
187 for (j = 1; j < filter.
n(); ++j)
207 if (order < 0) order = 0;
209 float *filt =
walloc(
float,order+1);
214 for (k=0; k<order; k++)
216 for (start = k, m = 0, i = 0; i < lpc.
num_frames() - 1; ++i)
224 for (k = start; k <
end; ++k,++m)
227 for (j = 1; j < n; ++j)
228 s += filt[j] * buff[k-j];
231 buff[k] = s + residual[m];
236 for (j=0,i=order; i < k; j++,i++)
237 signal[j] = (
short)buff[i];
249 sig.
a(i, j) = (
int)((
float)sig.
a(i, j) + a * last);
250 last = (float)sig(i, j);
304 for (i = 0; (i < h); ++i)
310 a[i] = sum /(float) k;
316 for (j = 0; j < n; ++j)
318 a[i] = sum /(float) k;
325 for (j = 0; j < k; ++j)
327 a[i] = sum /(float) k;
337 int delay_correction)
345 FIRfilter(in_sig, out_sig, numerator, delay_correction);
350 const EST_FVector &numerator,
int delay_correction)
352 if (delay_correction < 0)
353 EST_error(
"Can't have negative delay !\n");
355 if (numerator.
n() <= 0)
356 EST_error(
"Can't filter EST_Wave with given filter");
371 float *in =
walloc(
float,n);
372 for (i=0; i < n; ++i)
374 float *numer =
walloc(
float,numerator.
n());
375 for (i=0; i < numerator.
n(); ++i)
377 float *out =
walloc(
float,n);
379 for (i = 0; i < n; ++i)
384 int jhigh=numerator.
n();
386 if(i+delay_correction >= n)
387 jlow = i + delay_correction - n + 1;
389 if(i+delay_correction - jhigh < 0)
390 jhigh = i + delay_correction;
392 for(j=jlow; j<jhigh; j++)
393 if (((i+delay_correction - j) >= 0) &&
394 ((i+delay_correction - j) < n))
395 out[i] += in[i+delay_correction - j] * numer[j];
425 if((filter_order & 1) == 0){
426 cerr <<
"Requested filter order must be odd" << endl;
431 int N =
fastlog2(frequency_response.
n());
432 if(frequency_response.
n() != (
int)pow(
float(2.0),(float)N)){
433 cerr <<
"Desired frequency response must have dimension 2^N" << endl;
440 for(i=0;i<dummy.n();i++)
446 cerr <<
"Failed to design filter because FFT failed" << endl;
452 int mid = filter_order/2;
454 reduced_filt[
mid] = filt(0);
455 for(i=1; i<=
mid ;i++)
458 float window = 0.5 + 0.5 * cos(
PI*(
float)i / (
float)mid);
459 reduced_filt[mid+i] = filt(i) * window;
460 reduced_filt[mid-i] = filt(i) * window;
469 int cutoff_freq,
int order,
470 float gain1,
float gain2)
474 if (sample_rate <= 0){
475 cerr <<
"Can't design a FIR filter for a sampling rate of " 476 << sample_rate << endl;
483 int fft_size = (
int)pow(
float(2.0), float(N));
484 while(fft_size < order*4){
486 fft_size = (
int)pow(
float(2.0), float(N));
493 int normalised_cutoff = (fft_size * cutoff_freq)/sample_rate;
494 for(i=0;i<normalised_cutoff;i++){
495 freq_resp[i] = gain1;
496 freq_resp[fft_size-i-1] = gain1;
498 for(;i<fft_size/2;i++){
499 freq_resp[i] = gain2;
500 freq_resp[fft_size-i-1] = gain2;
509 freq, order, 1.0, 0.0);
515 freq, order, 0.0, 1.0);
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
float mid(const EST_Item &item)
void FIRlowpass_filter(const EST_Wave &in_sig, EST_Wave &out_sig, int freq, int order)
void set_sample_rate(const int n)
Set sampling rate to n
float end(const EST_Item &item)
#define walloc(TYPE, SIZE)
EST_FVector design_FIR_filter(const EST_FVector &frequency_response, int filter_order)
void FIRfilter(EST_Wave &in_sig, const EST_FVector &numerator, int delay_correction)
void pre_emphasis(EST_Wave &sig, float a)
EST_FVector design_lowpass_FIR_filter(int sample_rate, int freq, int order)
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
int num_channels() const
return number of channels in track
void set_file_type(const EST_String t)
INLINE const T & a_no_check(ssize_t n) const
read-only const access operator: without bounds checking
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)
float & a_no_check(ssize_t i, int c=0)
short & a(ssize_t i, ssize_t channel=0)
void FIR_double_filter(EST_Wave &in_sig, EST_Wave &out_sig, const EST_FVector &numerator)
void lpc_filter_1(EST_Track &lpc, EST_Wave &res, EST_Wave &sig)
void sub_wave(EST_Wave &sw, int offset=0, ssize_t num=EST_ALL, ssize_t start_c=0, ssize_t nchan=EST_ALL)
short & a_safe(ssize_t i, ssize_t channel=0)
EST_String file_type() const
void lpc_filter_fast(EST_Track &lpc, EST_Wave &res, EST_Wave &sig)
float & t(ssize_t i=0)
return time position of frame i
void inv_lpc_filter_ola(EST_Wave &in_sig, EST_Track &lpc, EST_Wave &out_sig)
void FIRlowpass_double_filter(EST_Wave &in_sig, int freq, int order)
const EST_SMatrix & values() const
EST_FVector design_high_or_low_pass_FIR_filter(int sample_rate, int cutoff_freq, int order, float gain1, float gain2)
INLINE short & a_no_check(ssize_t i, ssize_t channel=0)
void inv_lpc_filter(EST_Wave &sig, EST_FVector &a, EST_Wave &res)
ssize_t num_frames() const
return number of frames in track
void FIRhighpass_filter(EST_Wave &in_sig, int freq, int order)
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
int sample_rate() const
return the sampling rate (frequency)
float start(const EST_Item &item)
void FIRhighpass_double_filter(const EST_Wave &in_sig, EST_Wave &out_sig, int freq, int order)
ssize_t num_channels() const
return the number of channels in the waveform
void simple_mean_smooth(EST_Wave &c, int n)
void post_emphasis(EST_Wave &sig, float a)
float sum(const EST_FMatrix &a)
sum of elements
INLINE ssize_t n() const
number of items in vector.
void reverse(EST_Wave &sig)
void frame(EST_FVector &fv, int n, int startf=0, int nf=EST_ALL)
void fill(short v=0, ssize_t channel=EST_ALL)
void lpc_filter(EST_Wave &sig, EST_FVector &a, EST_Wave &res)
EST_FVector design_highpass_FIR_filter(int sample_rate, int freq, int order)