summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2016-05-23 12:11:56 -0700
committerRJ Ryan <rryan@mixxx.org>2016-05-23 12:11:56 -0700
commit898de399050338b48150869eabaa544e4ac5fc45 (patch)
tree50cc78b38fad50bb12ff58e281e21b6d660deed8 /lib
parentc44a7cc3c0883375172911e30c340a025e7be7b3 (diff)
parentc2bbbfab4cc9fb12ef9cd662bb14f8af4bf6064d (diff)
Merge pull request #478 from daschuer/fidlib
Fidlib update
Diffstat (limited to 'lib')
-rw-r--r--lib/fidlib-0.9.10/fidlib.c435
-rw-r--r--lib/fidlib-0.9.10/fidlib.h4
-rw-r--r--lib/fidlib-0.9.10/fidrf_cmdlist.h10
3 files changed, 297 insertions, 152 deletions
diff --git a/lib/fidlib-0.9.10/fidlib.c b/lib/fidlib-0.9.10/fidlib.c
index 619325287c..f5c46a011b 100644
--- a/lib/fidlib-0.9.10/fidlib.c
+++ b/lib/fidlib-0.9.10/fidlib.c
@@ -23,7 +23,7 @@
//
// Robert Bristow-Johnson's EQ cookbook formulae:
// http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-//
+//
#define VERSION "0.9.10"
@@ -35,7 +35,7 @@
// specify the filter, or it can be used with the frequency or
// frequency range missing, in which case default values are
// picked up from values passed directly to the routine.
-//
+//
// The spec consists of a series of letters usually followed by
// the order of the filter and then by any other parameters
// required, preceded by slashes. For example:
@@ -69,15 +69,15 @@
// okay= fid_list_filters_buf(buf, buf+sizeof(buf));
//
// // Calculate the response of the filter at a given frequency
-// // (frequency is given as a proportion of the sampling rate, in
-// // the range 0 to 0.5). If phase is returned, then this is
+// // (frequency is given as a proportion of the sampling rate, in
+// // the range 0 to 0.5). If phase is returned, then this is
// // given in the range 0 to 1 (for 0 to 2*pi).
// resp= fid_response(filt, freq);
// resp= fid_response_pha(filt, freq, &phase);
//
// // Estimate the signal delay caused by a particular filter, in samples
// delay= fid_calc_delay(filt);
-//
+//
// // Run a given filter (this will do JIT filter compilation if this is
// // implemented for this processor / OS)
// run= fid_run_new(filt, &funcp);
@@ -93,7 +93,7 @@
// fid_run_freebuf(fbuf1);
// fid_run_free(run);
//
-// // If you need to allocate your own buffers separately for some
+// // If you need to allocate your own buffers separately for some
// // reason, then do it this way:
// run= fid_run_new(filt, &funcp);
// len= fid_run_bufsize(run);
@@ -109,30 +109,30 @@
// free(fbuf1);
// fid_run_free(run);
//
-// // Convert an arbitrary filter into a new filter which is a single
-// // IIR/FIR pair. This is done by convolving the coefficients. This
-// // flattened filter will give the same result, in theory. However,
-// // in practice this will be less accurate, especially in cases where
-// // the limits of the floating point format are being reached (e.g.
+// // Convert an arbitrary filter into a new filter which is a single
+// // IIR/FIR pair. This is done by convolving the coefficients. This
+// // flattened filter will give the same result, in theory. However,
+// // in practice this will be less accurate, especially in cases where
+// // the limits of the floating point format are being reached (e.g.
// // subtracting numbers with small highly significant differences).
// // The routine also ensures that the IIR first coefficient is 1.0.
// filt2= fid_flatten(filt);
// free(filt);
//
// // Parse an entire filter-spec string possibly containing several FIR,
-// // IIR and predefined filters and return it as a FidFilter at the given
+// // IIR and predefined filters and return it as a FidFilter at the given
// // location. Stops at the first ,; or unmatched )]} character, or the end
// // of the string. Returns a strdup'd error string on error, or else 0.
// err= fid_parse(double rate, char **pp, FidFilter **ffp);
//
-// // Set up your own fatal-error handler (default is to dump a message
+// // Set up your own fatal-error handler (default is to dump a message
// // to STDERR and exit on fatal conditions)
// fid_set_error_handler(&my_error_func);
//
// // Get the version number of the library as a string (e.g. "1.0.0")
// txt= fid_version();
//
-// // Design a filter and reduce it to a list of all the non-const
+// // Design a filter and reduce it to a list of all the non-const
// // coefficients, which is returned in the given double[]. The number
// // of coefficients expected must be provided (as a check).
// #define N_COEF <whatever>
@@ -148,11 +148,11 @@
// free(full); free(min);
//
// // Create a FidFilter based on coefficients provided in the
-// // given double array.
+// // given double array.
// static double array[]= { 'I', 3, 1.0, 0.55, 0.77, 'F', 3, 1, -2, 1, 0 };
// filt= fid_cv_array(array);
//
-// // Join a number of filters into a single filter (and free them too,
+// // Join a number of filters into a single filter (and free them too,
// // if the first argument is 1)
// filt= fid_cat(0, filt1, filt2, filt3, filt4, 0);
//
@@ -172,15 +172,15 @@
// elements, or whatever). This is followed by a short bitmap
// which indicates which of the coefficients are constants,
// aiding code-generation. Next comes the count of the following
-// coefficients, as an int. (These header fields normally takes 8
-// bytes, the same as a double, but this might depend on the
-// platform). Then follow the coefficients, as doubles. The next
-// sub-filter follows on straight after that. The end of the list
+// coefficients, as an int. (These header fields normally takes 8
+// bytes, the same as a double, but this might depend on the
+// platform). Then follow the coefficients, as doubles. The next
+// sub-filter follows on straight after that. The end of the list
// is marked by 8 zero bytes, meaning typ==0, cbm==0 and len==0.
//
// The filter can be read with the aid of the FidFilter structure
-// (giving typ, cbm, len and val[] elements) and the FFNEXT()
-// macro: using ff= FFNEXT(ff) steps to the next FidFilter
+// (giving typ, cbm, len and val[] elements) and the FFNEXT()
+// macro: using ff= FFNEXT(ff) steps to the next FidFilter
// structure along the chain.
//
// Note that within the sub-filters, coefficients are listed in
@@ -263,7 +263,7 @@ extern FidFilter *mkfilter(char *, ...);
#if defined(T_MINGW) || defined(T_MSVC)
#define STATIC_INLINE static __inline
#else
- #define STATIC_INLINE static inline
+ #define STATIC_INLINE static inline
#endif
// MinGW and MSVC fixes
@@ -275,7 +275,7 @@ extern FidFilter *mkfilter(char *, ...);
#define snprintf _snprintf
#endif
// Not sure if we strictly need this still
- STATIC_INLINE double
+ STATIC_INLINE double
my_asinh(double val) {
return log(val + sqrt(val*val + 1.0));
}
@@ -289,7 +289,7 @@ extern FidFilter *mkfilter(char *, ...);
static void (*error_handler)(char *err)= 0;
-static void
+static void
error(char *fmt, ...) {
char buf[1024];
va_list ap;
@@ -311,7 +311,7 @@ strdupf(char *fmt, ...) {
int len;
va_start(ap, fmt);
len= vsnprintf(buf, sizeof(buf), fmt, ap);
- if (len < 0 || len >= sizeof(buf)-1)
+ if (len < 0 || len >= (int)sizeof(buf)-1)
error("strdupf exceeded buffer");
rv= strdup(buf);
if (!rv) error("Out of memory");
@@ -367,7 +367,7 @@ cmulr(double *aa, double fact) {
// Complex conjugate: aa= aa*
//
-STATIC_INLINE void
+STATIC_INLINE void
cconj(double *aa) {
aa[1]= -aa[1];
}
@@ -389,18 +389,18 @@ cdiv(double *aa, double *bb) {
// Complex reciprocal: aa= 1/aa
//
-STATIC_INLINE void
+STATIC_INLINE void
crecip(double *aa) {
double fact= 1.0 / (aa[0] * aa[0] + aa[1] * aa[1]);
aa[0] *= fact;
aa[1] *= -fact;
-}
-
+}
+
//
// Complex assign: aa= bb
//
-STATIC_INLINE void
+STATIC_INLINE void
cass(double *aa, double *bb) {
memcpy(aa, bb, 2*sizeof(double)); // Assigning doubles is really slow
}
@@ -409,7 +409,7 @@ cass(double *aa, double *bb) {
// Complex assign: aa= (rr + ii*j)
//
-STATIC_INLINE void
+STATIC_INLINE void
cassz(double *aa, double rr, double ii) {
aa[0]= rr;
aa[1]= ii;
@@ -419,7 +419,7 @@ cassz(double *aa, double rr, double ii) {
// Complex add: aa += bb
//
-STATIC_INLINE void
+STATIC_INLINE void
cadd(double *aa, double *bb) {
aa[0] += bb[0];
aa[1] += bb[1];
@@ -429,7 +429,7 @@ cadd(double *aa, double *bb) {
// Complex add: aa += (rr + ii*j)
//
-STATIC_INLINE void
+STATIC_INLINE void
caddz(double *aa, double rr, double ii) {
aa[0] += rr;
aa[1] += ii;
@@ -439,7 +439,7 @@ caddz(double *aa, double rr, double ii) {
// Complex subtract: aa -= bb
//
-STATIC_INLINE void
+STATIC_INLINE void
csub(double *aa, double *bb) {
aa[0] -= bb[0];
aa[1] -= bb[1];
@@ -449,7 +449,7 @@ csub(double *aa, double *bb) {
// Complex subtract: aa -= (rr + ii*j)
//
-STATIC_INLINE void
+STATIC_INLINE void
csubz(double *aa, double rr, double ii) {
aa[0] -= rr;
aa[1] -= ii;
@@ -459,7 +459,7 @@ csubz(double *aa, double rr, double ii) {
// Complex negate: aa= -aa
//
-STATIC_INLINE void
+STATIC_INLINE void
cneg(double *aa) {
aa[0]= -aa[0];
aa[1]= -aa[1];
@@ -503,7 +503,7 @@ evaluate(double *rv, double *coef, int n_coef, double *in) {
// Housekeeping
//
-void
+void
fid_set_error_handler(void (*rout)(char*)) {
error_handler= rout;
}
@@ -521,7 +521,7 @@ fid_version() {
// phase between 0 and two-pi.
//
-double
+double
fid_response_pha(FidFilter *filt, double freq, double *phase) {
double top[2], bot[2];
double theta= freq * 2 * M_PI;
@@ -533,16 +533,16 @@ fid_response_pha(FidFilter *filt, double freq, double *phase) {
bot[1]= 0;
zz[0]= cos(theta);
zz[1]= sin(theta);
-
+
while (filt->len) {
double resp[2];
int cnt= filt->len;
evaluate(resp, filt->val, cnt, zz);
if (filt->typ == 'I')
- cmul(bot, resp);
+ cmul(bot, resp);
else if (filt->typ == 'F')
cmul(top, resp);
- else
+ else
error("Unknown filter type %d in fid_response_pha()", filt->typ);
filt= FFNEXT(filt);
}
@@ -567,7 +567,7 @@ fid_response_pha(FidFilter *filt, double freq, double *phase) {
// can be inlined.
//
-double
+double
fid_response(FidFilter *filt, double freq) {
double top[2], bot[2];
double theta= freq * 2 * M_PI;
@@ -579,16 +579,16 @@ fid_response(FidFilter *filt, double freq) {
bot[1]= 0;
zz[0]= cos(theta);
zz[1]= sin(theta);
-
+
while (filt->len) {
double resp[2];
int cnt= filt->len;
evaluate(resp, filt->val, cnt, zz);
if (filt->typ == 'I')
- cmul(bot, resp);
+ cmul(bot, resp);
else if (filt->typ == 'F')
cmul(top, resp);
- else
+ else
error("Unknown filter type %d in fid_response()", filt->typ);
filt= FFNEXT(filt);
}
@@ -605,13 +605,13 @@ fid_response(FidFilter *filt, double freq) {
// are complete. This involves running test impulses through the
// filter several times. The estimated delay in samples is
// returned.
-//
+//
// Delays longer than 8,000,000 samples are not handled well, as
// the code drops out at this point rather than get stuck in an
// endless loop.
//
-int
+int
fid_calc_delay(FidFilter *filt) {
FidRun *run;
FidFunc *dostep;
@@ -626,20 +626,20 @@ fid_calc_delay(FidFilter *filt) {
// a reference point much further ahead in the impulse response.
f1= fid_run_newbuf(run);
f2= fid_run_newbuf(run);
-
+
tot= fabs(dostep(f1, 1.0));
tot100= fabs(dostep(f2, 1.0));
tot100 += fabs(dostep(f2, 0.0));
tot100 += fabs(dostep(f2, 0.0));
tot100 += fabs(dostep(f2, 0.0));
-
+
for (cnt= 1; cnt < 0x1000000; cnt++) {
tot += fabs(dostep(f1, 0.0));
tot100 += fabs(dostep(f2, 0.0));
tot100 += fabs(dostep(f2, 0.0));
tot100 += fabs(dostep(f2, 0.0));
tot100 += fabs(dostep(f2, 0.0));
-
+
if (tot/tot100 >= 0.999) break;
}
fid_run_freebuf(f1);
@@ -649,7 +649,7 @@ fid_calc_delay(FidFilter *filt) {
tot50= tot100/2;
f1= fid_run_newbuf(run);
tot= fabs(dostep(f1, 1.0));
- for (cnt= 0; tot < tot50; cnt++)
+ for (cnt= 0; tot < tot50; cnt++)
tot += fabs(dostep(f1, 0.0));
fid_run_freebuf(f1);
@@ -657,7 +657,7 @@ fid_calc_delay(FidFilter *filt) {
fid_run_free(run);
return cnt;
}
-
+
//
// 'mkfilter'-derived code
@@ -679,7 +679,7 @@ stack_filter(int order, int n_head, int n_val, ...) {
int a, b, len;
if (order == 0) return rv;
-
+
// Copy from ap
va_start(ap, n_val);
p= q= rv;
@@ -687,7 +687,7 @@ stack_filter(int order, int n_head, int n_val, ...) {
p->typ= va_arg(ap, int);
p->cbm= va_arg(ap, int);
p->len= va_arg(ap, int);
- for (b= 0; b<p->len; b++)
+ for (b= 0; b<p->len; b++)
p->val[b]= va_arg(ap, double);
p= FFNEXT(p);
}
@@ -695,16 +695,16 @@ stack_filter(int order, int n_head, int n_val, ...) {
// Check length
len= ((char*)p)-((char*)q);
- if (len != FFCSIZE(n_head-1, n_val))
+ if (len != (int)FFCSIZE(n_head-1, n_val))
error("Internal error; bad call to stack_filter(); length mismatch (%d,%d)",
len, FFCSIZE(n_head-1, n_val));
-
+
// Make as many additional copies as necessary
while (order-- > 0) {
memcpy(p, q, len);
p= (FidFilter*)(len + (char*)p);
}
-
+
// List is already terminated due to zeroed allocation
return rv;
}
@@ -714,17 +714,17 @@ stack_filter(int order, int n_head, int n_val, ...) {
// assumed that the gradient goes upwards from 'f0' to the peak,
// and then down again to 'f3'. If there are any other curves,
// this routine will get confused and will come up with some
-// frequency, although probably not the right one.
+// frequency, although probably not the right one.
//
// Returns the frequency of the peak.
//
-static double
+static double
search_peak(FidFilter *ff, double f0, double f3) {
double f1, f2;
double r1, r2;
int a;
-
+
// Binary search, modified, taking two intermediate points. Do 20
// subdivisions, which should give 1/2^20 == 1e-6 accuracy compared
// to original range.
@@ -765,7 +765,7 @@ do_lowpass(int mz, double freq) {
rv= z2fidfilter(1.0, ~0); // FIR is constant
rv->val[0]= 1.0 / fid_response(rv, 0.0);
return rv;
-}
+}
static FidFilter*
do_highpass(int mz, double freq) {
@@ -795,19 +795,19 @@ do_bandstop(int mz, double f0, double f1) {
rv= z2fidfilter(1.0, 5); // FIR second coefficient is *non-const* for bandstop
rv->val[0]= 1.0 / fid_response(rv, 0.0); // Use 0Hz response as reference
return rv;
-}
+}
//
// Information passed to individual filter design routines:
//
-// double* rout(double rate, double f0, double f1,
+// double* rout(double rate, double f0, double f1,
// int order, int n_arg, double *arg);
//
// 'rate' is the sampling rate, or 1 if not set
-// 'f0' and 'f1' give the frequency or frequency range as a
+// 'f0' and 'f1' give the frequency or frequency range as a
// proportion of the sampling rate
-// 'order' is the order of the filter (the integer passed immediately
+// 'order' is the order of the filter (the integer passed immediately
// after the name)
// 'n_arg' is the number of additional arguments for the filter
// 'arg' gives the additional argument values: arg[n]
@@ -817,7 +817,7 @@ do_bandstop(int mz, double f0, double f1) {
//
// See the previous description for the required meaning of the
// return value FidFilter list.
-//
+//
//
// Filter design routines and supporting code
@@ -825,24 +825,41 @@ do_bandstop(int mz, double f0, double f1) {
static FidFilter*
des_bpre(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
bandpass_res(f0, arg[0]);
return z2fidfilter(1.0, ~0); // FIR constant
}
static FidFilter*
des_bsre(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
bandstop_res(f0, arg[0]);
return z2fidfilter(1.0, 0); // FIR not constant, depends on freq
}
static FidFilter*
des_apre(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
allpass_res(f0, arg[0]);
return z2fidfilter(1.0, 0); // FIR not constant, depends on freq
}
static FidFilter*
des_pi(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
prop_integral(prewarp(f0));
s2z_bilinear();
return z2fidfilter(1.0, 0); // FIR not constant, depends on freq
@@ -850,6 +867,11 @@ des_pi(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_piz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
prop_integral(prewarp(f0));
s2z_matchedZ();
return z2fidfilter(1.0, 0); // FIR not constant, depends on freq
@@ -857,58 +879,89 @@ des_piz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lpbe(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_lowpass(BL, f0);
}
static FidFilter*
des_hpbe(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_highpass(BL, f0);
}
static FidFilter*
des_bpbe(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_bandpass(BL, f0, f1);
}
static FidFilter*
des_bsbe(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_bandstop(BL, f0, f1);
}
static FidFilter*
des_lpbez(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_lowpass(MZ, f0);
}
static FidFilter*
des_hpbez(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_highpass(MZ, f0);
}
static FidFilter*
des_bpbez(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_bandpass(MZ, f0, f1);
}
static FidFilter*
des_bsbez(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
bessel(order);
return do_bandstop(MZ, f0, f1);
}
static FidFilter* // Butterworth-Bessel cross
des_lpbube(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double tmp[MAXPZ];
int a;
bessel(order); memcpy(tmp, pol, order * sizeof(double));
- butterworth(order);
+ butterworth(order);
for (a= 0; a<order; a++) pol[a] += (tmp[a]-pol[a]) * 0.01 * arg[0];
//for (a= 1; a<order; a+=2) pol[a] += arg[1] * 0.01;
return do_lowpass(BL, f0);
@@ -916,102 +969,153 @@ des_lpbube(double rate, double f0, double f1, int order, int n_arg, double *arg)
static FidFilter*
des_lpbu(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_lowpass(BL, f0);
}
static FidFilter*
des_hpbu(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_highpass(BL, f0);
}
static FidFilter*
des_bpbu(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_bandpass(BL, f0, f1);
}
static FidFilter*
des_bsbu(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_bandstop(BL, f0, f1);
}
static FidFilter*
des_lpbuz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_lowpass(MZ, f0);
}
static FidFilter*
des_hpbuz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_highpass(MZ, f0);
}
static FidFilter*
des_bpbuz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_bandpass(MZ, f0, f1);
}
static FidFilter*
des_bsbuz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
+ (void)arg;
butterworth(order);
return do_bandstop(MZ, f0, f1);
}
static FidFilter*
des_lpch(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_lowpass(BL, f0);
}
static FidFilter*
des_hpch(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_highpass(BL, f0);
}
static FidFilter*
des_bpch(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_bandpass(BL, f0, f1);
}
static FidFilter*
des_bsch(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_bandstop(BL, f0, f1);
}
static FidFilter*
des_lpchz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_lowpass(MZ, f0);
}
static FidFilter*
des_hpchz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_highpass(MZ, f0);
}
static FidFilter*
des_bpchz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_bandpass(MZ, f0, f1);
}
static FidFilter*
des_bschz(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)n_arg;
chebyshev(order, arg[0]);
return do_bandstop(MZ, f0, f1);
}
static FidFilter*
des_lpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1023,6 +1127,9 @@ des_lpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_hpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1034,6 +1141,9 @@ des_hpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_bpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1045,6 +1155,9 @@ des_bpbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_bsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1055,6 +1168,9 @@ des_bsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_apbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1065,6 +1181,9 @@ des_apbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_pkbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double alpha= sin(omega) / 2 / arg[0];
@@ -1076,6 +1195,9 @@ des_pkbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double sinv= sin(omega);
@@ -1094,6 +1216,9 @@ des_lsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_hsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)n_arg;
double omega= 2 * M_PI * f0;
double cosv= cos(omega);
double sinv= sin(omega);
@@ -1112,6 +1237,11 @@ des_hsbq(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lpbl(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
double wid= 0.4109205/f0;
double tot, adj;
int max= (int)floor(wid);
@@ -1122,7 +1252,7 @@ des_lpbl(double rate, double f0, double f1, int order, int n_arg, double *arg) {
ff->len= max*2+1;
ff->val[max]= tot= 1.0;
for (a= 1; a<=max; a++) {
- double val= 0.42 +
+ double val= 0.42 +
0.5 * cos(M_PI * a / wid) +
0.08 * cos(M_PI * 2.0 * a / wid);
ff->val[max-a]= val;
@@ -1136,6 +1266,11 @@ des_lpbl(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lphm(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
double wid= 0.3262096/f0;
double tot, adj;
int max= (int)floor(wid);
@@ -1146,7 +1281,7 @@ des_lphm(double rate, double f0, double f1, int order, int n_arg, double *arg) {
ff->len= max*2+1;
ff->val[max]= tot= 1.0;
for (a= 1; a<=max; a++) {
- double val= 0.54 +
+ double val= 0.54 +
0.46 * cos(M_PI * a / wid);
ff->val[max-a]= val;
ff->val[max+a]= val;
@@ -1159,6 +1294,11 @@ des_lphm(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lphn(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
double wid= 0.360144/f0;
double tot, adj;
int max= (int)floor(wid);
@@ -1169,7 +1309,7 @@ des_lphn(double rate, double f0, double f1, int order, int n_arg, double *arg) {
ff->len= max*2+1;
ff->val[max]= tot= 1.0;
for (a= 1; a<=max; a++) {
- double val= 0.5 +
+ double val= 0.5 +
0.5 * cos(M_PI * a / wid);
ff->val[max-a]= val;
ff->val[max+a]= val;
@@ -1182,6 +1322,11 @@ des_lphn(double rate, double f0, double f1, int order, int n_arg, double *arg) {
static FidFilter*
des_lpba(double rate, double f0, double f1, int order, int n_arg, double *arg) {
+ (void)rate;
+ (void)f1;
+ (void)order;
+ (void)n_arg;
+ (void)arg;
double wid= 0.3189435/f0;
double tot, adj;
int max= (int)floor(wid);
@@ -1222,29 +1367,29 @@ static struct {
"Proportional-integral filter, frequency #F" },
{ des_piz, "PiZ/#F",
"Proportional-integral filter, matched z-transform, frequency #F" },
- { des_lpbe, "LpBe#O/#F",
+ { des_lpbe, "LpBe#O/#F",
"Lowpass Bessel filter, order #O, -3.01dB frequency #F" },
- { des_hpbe, "HpBe#O/#F",
+ { des_hpbe, "HpBe#O/#F",
"Highpass Bessel filter, order #O, -3.01dB frequency #F" },
- { des_bpbe, "BpBe#O/#R",
+ { des_bpbe, "BpBe#O/#R",
"Bandpass Bessel filter, order #O, -3.01dB frequencies #R" },
- { des_bsbe, "BsBe#O/#R",
+ { des_bsbe, "BsBe#O/#R",
"Bandstop Bessel filter, order #O, -3.01dB frequencies #R" },
- { des_lpbu, "LpBu#O/#F",
+ { des_lpbu, "LpBu#O/#F",
"Lowpass Butterworth filter, order #O, -3.01dB frequency #F" },
- { des_hpbu, "HpBu#O/#F",
+ { des_hpbu, "HpBu#O/#F",
"Highpass Butterworth filter, order #O, -3.01dB frequency #F" },
- { des_bpbu, "BpBu#O/#R",
+ { des_bpbu, "BpBu#O/#R",
"Bandpass Butterworth filter, order #O, -3.01dB frequencies #R" },
- { des_bsbu, "BsBu#O/#R",
+ { des_bsbu, "BsBu#O/#R",
"Bandstop Butterworth filter, order #O, -3.01dB frequencies #R" },
{ des_lpch, "LpCh#O/#V/#F",
"Lowpass Chebyshev filter, order #O, passband ripple #VdB, -3.01dB frequency #F" },
- { des_hpch, "HpCh#O/#V/#F",
+ { des_hpch, "HpCh#O/#V/#F",
"Highpass Chebyshev filter, order #O, passband ripple #VdB, -3.01dB frequency #F" },
- { des_bpch, "BpCh#O/#V/#R",
+ { des_bpch, "BpCh#O/#V/#R",
"Bandpass Chebyshev filter, order #O, passband ripple #VdB, -3.01dB frequencies #R" },
- { des_bsch, "BsCh#O/#V/#R",
+ { des_bsch, "BsCh#O/#V/#R",
"Bandstop Chebyshev filter, order #O, passband ripple #VdB, -3.01dB frequencies #R" },
{ des_lpbez, "LpBeZ#O/#F",
"Lowpass Bessel filter, matched z-transform, order #O, -3.01dB frequency #F" },
@@ -1333,12 +1478,12 @@ static struct {
//
typedef struct Spec Spec;
-static char* parse_spec(Spec*);
+static char* parse_spec(Spec*);
static FidFilter *auto_adjust_single(Spec *sp, double rate, double f0);
static FidFilter *auto_adjust_dual(Spec *sp, double rate, double f0, double f1);
struct Spec {
#define MAXARG 10
- char *spec;
+ const char *spec;
double in_f0, in_f1;
int in_adj;
double argarr[MAXARG];
@@ -1382,9 +1527,9 @@ fid_design(const char *spec, double rate, double freq0, double freq1, int f_adj,
rv= filter[sp.fi].rout(rate, f0, f1, sp.order, sp.n_arg, sp.argarr);
else if (strstr(filter[sp.fi].fmt, "#R"))
rv= auto_adjust_dual(&sp, rate, f0, f1);
- else
+ else
rv= auto_adjust_single(&sp, rate, f0);
-
+
// Generate a long description if required
if (descp) {
char *fmt= filter[sp.fi].txt;
@@ -1394,13 +1539,13 @@ fid_design(const char *spec, double rate, double freq0, double freq1, int f_adj,
char ch;
double *arg= sp.argarr;
int n_arg= sp.n_arg;
-
+
while ((ch= *fmt++)) {
if (ch != '#') {
*p++= ch;
continue;
}
-
+
switch (*fmt++) {
case 'O':
p += sprintf(p, "%d", sp.order);
@@ -1412,7 +1557,7 @@ fid_design(const char *spec, double rate, double freq0, double freq1, int f_adj,
p += sprintf(p, "%g-%g", f0*rate, f1*rate);
break;
case 'V':
- if (n_arg <= 0)
+ if (n_arg <= 0)
error("Internal error -- disagreement between filter short-spec\n"
" and long-description over number of arguments");
n_arg--;
@@ -1462,11 +1607,11 @@ auto_adjust_single(Spec *sp, double rate, double f0) {
}
incr= r2 > r0;
- if (a0 > a2) {
+ if (a0 > a2) {
a1= a0; a0= a2; a2= a1;
incr= !incr;
}
-
+
// Binary search
while (1) {
a1= 0.5 * (a0 + a2);
@@ -1475,7 +1620,7 @@ auto_adjust_single(Spec *sp, double rate, double f0) {
if (resp >= 0.9999995 * M301DB && resp < 1.0000005 * M301DB) break;
if (incr == (resp > M301DB))
a2= a1;
- else
+ else
a0= a1;
}
@@ -1519,7 +1664,7 @@ auto_adjust_dual(Spec *sp, double rate, double f0, double f1) {
DESIGN(mid, wid);
bpass= (fid_response(rv, 0) < 0.5);
delta= wid * 0.5;
-
+
// Try delta changes until we get there
for (cnt= 0; 1; cnt++, delta *= 0.51) {
DESIGN(mid, wid); // I know -- this is redundant
@@ -1529,13 +1674,13 @@ auto_adjust_dual(Spec *sp, double rate, double f0, double f1) {
wid0= wid;
mid1= mid + (INC_MID ? delta : -delta);
wid1= wid + (INC_WID ? delta : -delta);
-
+
if (mid0 - wid1 > 0.0 && mid0 + wid1 < 0.5) {
DESIGN(mid0, wid1);
if (MATCH) break;
if (PERR < perr) { perr= PERR; mid= mid0; wid= wid1; }
}
-
+
if (mid1 - wid0 > 0.0 && mid1 + wid0 < 0.5) {
DESIGN(mid1, wid0);
if (MATCH) break;
@@ -1567,13 +1712,13 @@ auto_adjust_dual(Spec *sp, double rate, double f0, double f1) {
// space, drops dead
//
-static void
+static void
expand_spec(char *buf, char *bufend, char *str) {
int ch;
char *p= buf;
while ((ch= *str++)) {
- if (p + 10 >= bufend)
+ if (p + 10 >= bufend)
error("Buffer overflow in fidlib expand_spec()");
if (ch == '#') {
switch (*str++) {
@@ -1610,8 +1755,8 @@ expand_spec(char *buf, char *bufend, char *str) {
// 'n_coef' argument provides a partial safeguard.
//
-double
-fid_design_coef(double *coef, int n_coef, const char *spec, double rate,
+double
+fid_design_coef(double *coef,