diff --git a/fidlib.c b/fidlib.c index 7f03c7d..f5c46a0 100644 --- a/fidlib.c +++ b/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 @@ -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 @@ -259,10 +259,11 @@ extern FidFilter *mkfilter(char *, ...); // // Macro for local inline routines that shouldn't be visible externally -#ifdef T_MSVC +// See Mixxx Bug #1179683 +#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 @@ -274,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)); } @@ -288,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; @@ -310,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"); @@ -366,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]; } @@ -388,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 } @@ -408,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; @@ -418,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]; @@ -428,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; @@ -438,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]; @@ -448,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; @@ -458,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]; @@ -502,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; } @@ -520,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; @@ -532,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); } @@ -566,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; @@ -578,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); } @@ -604,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; @@ -625,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); @@ -648,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); @@ -656,7 +657,7 @@ fid_calc_delay(FidFilter *filt) { fid_run_free(run); return cnt; } - + // // 'mkfilter'-derived code @@ -678,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; @@ -686,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; blen; b++) + for (b= 0; blen; b++) p->val[b]= va_arg(ap, double); p= FFNEXT(p); } @@ -694,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= (void*)(len + (char*)p); + p= (FidFilter*)(len + (char*)p); } - + // List is already terminated due to zeroed allocation return rv; } @@ -713,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. @@ -764,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) { @@ -794,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] @@ -816,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 @@ -824,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 @@ -849,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 @@ -856,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; atyp= 'F'; ff->cbm= 0; 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; @@ -1135,17 +1266,22 @@ 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); int a; - FidFilter *ff= Alloc(FFCSIZE(1, max*2+1)); + FidFilter *ff= (FidFilter*)Alloc(FFCSIZE(1, max*2+1)); ff->typ= 'F'; ff->cbm= 0; 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; @@ -1158,17 +1294,22 @@ 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); int a; - FidFilter *ff= Alloc(FFCSIZE(1, max*2+1)); + FidFilter *ff= (FidFilter*)Alloc(FFCSIZE(1, max*2+1)); ff->typ= 'F'; ff->cbm= 0; 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; @@ -1181,11 +1322,16 @@ 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); int a; - FidFilter *ff= Alloc(FFCSIZE(1, max*2+1)); + FidFilter *ff= (FidFilter*)Alloc(FFCSIZE(1, max*2+1)); ff->typ= 'F'; ff->cbm= 0; ff->len= max*2+1; @@ -1221,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" }, @@ -1332,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]; @@ -1351,7 +1497,7 @@ struct Spec { }; FidFilter * -fid_design(char *spec, double rate, double freq0, double freq1, int f_adj, char **descp) { +fid_design(const char *spec, double rate, double freq0, double freq1, int f_adj, char **descp) { FidFilter *rv; Spec sp; double f0, f1; @@ -1381,25 +1527,25 @@ fid_design(char *spec, double rate, double freq0, double freq1, int f_adj, char 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; int max= strlen(fmt) + 60 + sp.n_arg * 20; - char *desc= Alloc(max); + char *desc= (char*)Alloc(max); char *p= desc; 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); @@ -1411,7 +1557,7 @@ fid_design(char *spec, double rate, double freq0, double freq1, int f_adj, char 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--; @@ -1461,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); @@ -1474,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; } @@ -1518,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 @@ -1528,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; @@ -1566,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++) { @@ -1609,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, char *spec, double rate, +double +fid_design_coef(double *coef, int n_coef, const char *spec, double rate, double freq0, double freq1, int adj) { FidFilter *filt= fid_design(spec, rate, freq0, freq1, adj, 0); FidFilter *ff= filt; @@ -1659,13 +1805,13 @@ fid_design_coef(double *coef, int n_coef, char *spec, double rate, len= n_fir > n_iir ? n_fir : n_iir; for (a= len-1; a>=0; a--) { // Output IIR if present and non-const - if (a < n_iir && a>0 && + if (a < n_iir && a>0 && !(iir_cbm & (1<<(a<15?a:15)))) { if (cnt++ < n_coef) *coef++= iir_adj * iir[a]; } // Output FIR if present and non-const - if (a < n_fir && + if (a < n_fir && !(fir_cbm & (1<<(a<15?a:15)))) { if (cnt++ < n_coef) *coef++= fir[a]; } @@ -1676,16 +1822,16 @@ fid_design_coef(double *coef, int n_coef, char *spec, double rate, error("fid_design_coef called with the wrong number of coefficients.\n" " Given %d, expecting %d: (\"%s\",%g,%g,%g,%d)", n_coef, cnt, spec, rate, freq0, freq1, adj); - + free(filt); return gain; } - + // // List all the known filters to the given file handle // -void +void fid_list_filters(FILE *out) { int a; @@ -1703,7 +1849,7 @@ fid_list_filters(FILE *out) { // NUL-terminated; returns 1 okay, 0 not enough space // -int +int fid_list_filters_buf(char *buf, char *bufend) { int a, cnt; char tmp[4096]; @@ -1763,11 +1909,11 @@ fid_flatten(FidFilter *filt) { m_iir += ff->len-1; else if (ff->typ == 'F') m_fir += ff->len-1; - else + else error("fid_flatten doesn't know about type %d", ff->typ); ff= FFNEXT(ff); } - + // Setup the output array rv= FFALLOC(2, m_iir + m_fir); rv->typ= 'I'; @@ -1784,16 +1930,16 @@ fid_flatten(FidFilter *filt) { // Do the convolution ff= filt; while (ff->len) { - if (ff->typ == 'I') + if (ff->typ == 'I') n_iir= convolve(iir, n_iir, ff->val, ff->len); - else + else n_fir= convolve(fir, n_fir, ff->val, ff->len); ff= FFNEXT(ff); } // Sanity check if (n_iir != m_iir || - n_fir != m_fir) + n_fir != m_fir) error("Internal error in fid_combine() -- array under/overflow"); // Fix iir[0] @@ -1818,14 +1964,14 @@ parse_spec(Spec *sp) { sp->n_arg= 0; sp->order= 0; sp->f0= 0; - sp->f1= 0; + sp->f1= 0; sp->adj= 0; sp->minlen= -1; sp->n_freq= 0; - + for (a= 0; 1; a++) { char *fmt= filter[a].fmt; - char *p= sp->spec; + const char *p= sp->spec; char ch, *q; if (!fmt) return strdupf("Spec-string \"%s\" matches no known format", sp->spec); @@ -1841,7 +1987,7 @@ parse_spec(Spec *sp) { // Handling a format character switch (ch= *fmt++) { default: - return strdupf("Internal error: Unknown format #%c in format: %s", + return strdupf("Internal error: Unknown format #%c in format: %s", fmt[-1], filter[a].fmt); case 'o': case 'O': @@ -1850,13 +1996,13 @@ parse_spec(Spec *sp) { if (ch == 'O') goto bad; sp->order= 1; } - if (sp->order <= 0) + if (sp->order <= 0) return strdupf("Bad order %d in spec-string \"%s\"", sp->order, sp->spec); p= q; break; case 'V': - sp->n_arg++; + sp->n_arg++; *arg++= strtod(p, &q); - if (p == q) goto bad; + if (p == q) goto bad; p= q; break; case 'F': sp->minlen= p-1-sp->spec; @@ -1865,7 +2011,7 @@ parse_spec(Spec *sp) { if (sp->adj) p++; sp->f0= strtod(p, &q); sp->f1= 0; - if (p == q) goto bad; + if (p == q) goto bad; p= q; break; case 'R': sp->minlen= p-1-sp->spec; @@ -1873,12 +2019,12 @@ parse_spec(Spec *sp) { sp->adj= (p[0] == '='); if (sp->adj) p++; sp->f0= strtod(p, &q); - if (p == q) goto bad; + if (p == q) goto bad; p= q; if (*p++ != '-') goto bad; sp->f1= strtod(p, &q); - if (p == q) goto bad; - if (sp->f0 > sp->f1) + if (p == q) goto bad; + if (sp->f0 > sp->f1) return strdupf("Backwards frequency range in spec-string \"%s\"", sp->spec); p= q; break; } @@ -1889,7 +2035,7 @@ parse_spec(Spec *sp) { if (fmt[0] == '/' && fmt[1] == '#' && fmt[2] == 'F') { sp->minlen= p-sp->spec; sp->n_freq= 1; - if (sp->in_f0 < 0.0) + if (sp->in_f0 < 0.0) return strdupf("Frequency omitted from filter-spec, and no default provided"); sp->f0= sp->in_f0; sp->f1= 0; @@ -1909,22 +2055,22 @@ parse_spec(Spec *sp) { // Check for trailing unmatched format characters if (*fmt) { bad: - return strdupf("Bad match of spec-string \"%s\" to format \"%s\"", + return strdupf("Bad match of spec-string \"%s\" to format \"%s\"", sp->spec, filter[a].fmt); } - if (sp->n_arg > MAXARG) + if (sp->n_arg > MAXARG) return strdupf("Internal error -- maximum arguments exceeded"); - + // Set the minlen to the whole string if unset if (sp->minlen < 0) sp->minlen= p-sp->spec; - + // Save values, return sp->fi= a; return 0; } return 0; } - + // // Parse a filter-spec and freq0/freq1 arguments and rewrite them @@ -1936,9 +2082,9 @@ parse_spec(Spec *sp) { // spec-string is not generated. // -void -fid_rewrite_spec(char *spec, double freq0, double freq1, int adj, - char **spec1p, +void +fid_rewrite_spec(const char *spec, double freq0, double freq1, int adj, + char **spec1p, char **spec2p, double *freq0p, double *freq1p, int *adjp) { Spec sp; char *err; @@ -1959,14 +2105,14 @@ fid_rewrite_spec(char *spec, double freq0, double freq1, int adj, default: buf[0]= 0; } len= strlen(buf); - rv= Alloc(sp.minlen + len + 1); + rv= (char*)Alloc(sp.minlen + len + 1); memcpy(rv, spec, sp.minlen); strcpy(rv+sp.minlen, buf); *spec1p= rv; } if (spec2p) { - char *rv= Alloc(sp.minlen + 1); + char *rv= (char*)Alloc(sp.minlen + 1); memcpy(rv, spec, sp.minlen); *spec2p= rv; *freq0p= sp.f0; @@ -1984,11 +2130,11 @@ fid_rewrite_spec(char *spec, double freq0, double freq1, int adj, // // This is really just a convenience function, allowing a filter // to be conveniently dumped to C source code and then -// reconstructed. +// reconstructed. // // Note that for more general filter generation, FidFilter // instances can be created simply by allocating the memory and -// filling them in (see fidlib.h). +// filling them in (see fidlib.h). // FidFilter * @@ -2003,7 +2149,7 @@ fid_cv_array(double *arr) { int len, typ; typ= (int)(*dp++); - if (typ != 'F' && typ != 'I') + if (typ != 'F' && typ != 'I') error("Bad type in array passed to fid_cv_array: %g", dp[-1]); len= (int)(*dp++); @@ -2015,7 +2161,7 @@ fid_cv_array(double *arr) { dp += len; } - rv= ff= Alloc(FFCSIZE(n_head, n_val)); + rv= ff= (FidFilter*)Alloc(FFCSIZE(n_head, n_val)); // Scan through to fill in FidFilter for (dp= arr; *dp; ) { @@ -2042,7 +2188,7 @@ fid_cv_array(double *arr) { // free'd once read; otherwise they are left untouched. The // newly allocated resultant filter is returned, which should be // released with free() when finished with. -// +// FidFilter * fid_cat(int freeme, ...) { @@ -2061,7 +2207,7 @@ fid_cat(int freeme, ...) { } va_end(ap); - rv= Alloc(FFCSIZE(0,0) + len); + rv= (FidFilter*)Alloc(FFCSIZE(0,0) + len); dst= (char*)rv; va_start(ap, freeme); @@ -2084,7 +2230,7 @@ fid_cat(int freeme, ...) { // // Skip white space (including comments) -static void +static void skipWS(char **pp) { char *p= *pp; @@ -2102,11 +2248,11 @@ skipWS(char **pp) { // Grab a word from the input into the given buffer. Returns 0: end // of file or error, else 1: success. Error is indicated when the // word doesn't fit in the buffer. -static int +static int grabWord(char **pp, char *buf, int buflen) { char *p, *q; - int len; - + int len; + skipWS(pp); p= *pp; if (!*p) return 0; @@ -2115,16 +2261,16 @@ grabWord(char **pp, char *buf, int buflen) { if (*q == ',' || *q == ';' || *q == ')' || *q == ']' || *q == '}') { q++; } else { - while (*q && *q != '#' && !isspace(*q) && + while (*q && *q != '#' && !isspace(*q) && (*q != ',' && *q != ';' && *q != ')' && *q != ']' && *q != '}')) q++; } len= q-p; if (len >= buflen) return 0; - + memcpy(buf, p, len); buf[len]= 0; - + *pp= q; return 1; } @@ -2147,7 +2293,7 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { char buf[128]; char *p= *pp, *rew; #define INIT_LEN 128 - char *rv= Alloc(INIT_LEN); + char *rv= (char*)Alloc(INIT_LEN); char *rvend= rv + INIT_LEN; char *rvp= rv; char *tmp; @@ -2159,10 +2305,10 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { char dmy; #define ERR(ptr, msg) { *pp= ptr; *ffp= 0; return msg; } -#define INCBUF { tmp= realloc(rv, (rvend-rv) * 2); if (!tmp) error("Out of memory"); \ +#define INCBUF { tmp= (char*)realloc(rv, (rvend-rv) * 2); if (!tmp) error("Out of memory"); \ rvend= (rvend-rv) * 2 + tmp; rvp= (rvp-rv) + tmp; \ - curr= (void*)(((char*)curr) - rv + tmp); rv= tmp; } - + curr= (FidFilter*)(((char*)curr) - rv + tmp); rv= tmp; } + while (1) { rew= p; if (!grabWord(&p, buf, sizeof(buf))) { @@ -2179,9 +2325,9 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { case ']': case '}': // End of filter, return it - tmp= realloc(rv, (rvp-rv) + xtra); + tmp= (char*)realloc(rv, (rvp-rv) + xtra); if (!tmp) error("Out of memory"); - curr= (void*)((rvp-rv) + tmp); + curr= (FidFilter*)((rvp-rv) + tmp); curr->typ= 0; curr->cbm= 0; curr->len= 0; *pp= buf[0] ? (p-1) : p; *ffp= (FidFilter*)tmp; @@ -2217,7 +2363,7 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { if ((err= parse_spec(&sp))) ERR(rew, err); f0= sp.f0; f1= sp.f1; - + // Adjust frequencies to range 0-0.5, and check them f0 /= rate; if (f0 > 0.5) ERR(rew, strdupf("Frequency of %gHz out of range with " @@ -2225,16 +2371,16 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { f1 /= rate; if (f1 > 0.5) ERR(rew, strdupf("Frequency of %gHz out of range with " "sampling rate of %gHz", f1*rate, rate)); - + // Okay we now have a successful spec-match to filter[sp.fi], and sp.n_arg // args are now in sp.argarr[] - + // Generate the filter if (!sp.adj) ff= filter[sp.fi].rout(rate, f0, f1, sp.order, sp.n_arg, sp.argarr); else if (strstr(filter[sp.fi].fmt, "#R")) ff= auto_adjust_dual(&sp, rate, f0, f1); - else + else ff= auto_adjust_single(&sp, rate, f0); // Append it to our FidFilter to return @@ -2248,7 +2394,7 @@ fid_parse(double rate, char **pp, FidFilter **ffp) { } // Must be a list of coefficients - curr= (void*)rvp; + curr= (FidFilter*)rvp; rvp += xtra; while (rvp + sizeof(double) >= rvend) INCBUF; curr->typ= typ; diff --git a/fidlib.h b/fidlib.h index 86da649..e84130f 100644 --- a/fidlib.h +++ b/fidlib.h @@ -1,7 +1,8 @@ // // fidlib include file // - +#ifndef FIDLIB_H +#define FIDLIB_H typedef struct FidFilter FidFilter; struct FidFilter { short typ; // Type of filter element 'I' IIR, 'F' FIR, or 0 for end of list @@ -35,20 +36,23 @@ typedef double (FidFunc)(void*, double); // // Prototypes // +#ifdef __cplusplus +extern "C" { +#endif extern void fid_set_error_handler(void(*rout)(char *)); extern char *fid_version(); extern double fid_response_pha(FidFilter *filt, double freq, double *phase); extern double fid_response(FidFilter *filt, double freq); extern int fid_calc_delay(FidFilter *filt); -extern FidFilter *fid_design(char *spec, double rate, double freq0, double freq1, +extern FidFilter *fid_design(const char *spec, double rate, double freq0, double freq1, int f_adj, char **descp); -extern double fid_design_coef(double *coef, int n_coef, char *spec, +extern double fid_design_coef(double *coef, int n_coef, const char *spec, double rate, double freq0, double freq1, int adj); extern void fid_list_filters(FILE *out); extern int fid_list_filters_buf(char *buf, char *bufend); extern FidFilter *fid_flatten(FidFilter *filt); -extern void fid_rewrite_spec(char *spec, double freq0, double freq1, int adj, +extern void fid_rewrite_spec(const char *spec, double freq0, double freq1, int adj, char **spec1p, char **spec2p, double *freq0p, double *freq1p, int *adjp); extern FidFilter *fid_cv_array(double *arr); @@ -66,3 +70,8 @@ extern void fid_run_initbuf(void *run, void *buf); extern void fid_run_zapbuf(void *buf); extern void fid_run_freebuf(void *runbuf); extern void fid_run_free(void *run); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/fidmkf.h b/fidmkf.h index 37c7b50..d09aaa4 100644 --- a/fidmkf.h +++ b/fidmkf.h @@ -128,11 +128,22 @@ // Not A Lawyer". // +#ifndef FIDMK_H +#define FIDMK_H + +#ifndef T_MSVC + #ifdef HUGE_VAL + #define INF HUGE_VAL + #else + #define INF (1.0/0.0) + #endif +#endif -#ifdef HUGE_VAL +//Hacks for crappy linker error in MSVC... - Albert +#ifdef T_MSVC + #undef HUGE_VAL + #define HUGE_VAL 1.797693134862315E+308 #define INF HUGE_VAL -#else - #define INF (1.0/0.0) #endif #define TWOPI (2*M_PI) @@ -729,7 +740,7 @@ z2fidfilter(double gain, int cbm) { ff->len= 0; ff= FFNEXT(ff); - rv= realloc(rv, ((char*)ff)-((char*)rv)); + rv= (FidFilter*)realloc(rv, ((char*)ff)-((char*)rv)); if (!rv) error("Out of memory"); return rv; } @@ -831,3 +842,5 @@ prop_integral(double freq) { } // END // +#endif + diff --git a/fidrf_cmdlist.h b/fidrf_cmdlist.h index fbe7883..f45ee29 100644 --- a/fidrf_cmdlist.h +++ b/fidrf_cmdlist.h @@ -28,7 +28,7 @@ typedef struct RunBuf { double *coef; char *cmd; int mov_cnt; // Number of bytes to memmove - double buf[0]; + double buf[1]; // is resized in fid_run_newbuf() } RunBuf; @@ -76,9 +76,9 @@ typedef unsigned char uchar; static double filter_step(void *fbuf, double iir) { double *coef= ((RunBuf*)fbuf)->coef; - uchar *cmd= ((RunBuf*)fbuf)->cmd; + char *cmd= ((RunBuf*)fbuf)->cmd; double *buf= &((RunBuf*)fbuf)->buf[0]; - uchar ch; + char ch; double fir= 0; double tmp= buf[0]; int cnt; @@ -228,7 +228,7 @@ fid_run_new(FidFilter *filt, double (**funcpp)(void *,double)) { // Allocate worst-case sizes for temporary arrays coef_tmp= ALLOC_ARR(coef_max= filt_cnt + 1, double); - cmd_tmp= ALLOC_ARR(cmd_max= filt_cnt + 4, char); + cmd_tmp= (uchar*)ALLOC_ARR(cmd_max= filt_cnt + 4, char); dp= coef_tmp; cp= cmd_tmp; prev= 0; @@ -386,18 +386,18 @@ fid_run_new(FidFilter *filt, double (**funcpp)(void *,double)) { void * fid_run_newbuf(void *run) { - Run *rr= run; + Run *rr= (Run*)run; RunBuf *rb; int siz; if (rr->magic != 0x64966325) error("Bad handle passed to fid_run_newbuf()"); - siz= rr->buf_size ? rr->buf_size : 1; // Minimum one element to avoid problems - rb= Alloc(sizeof(RunBuf) + siz * sizeof(double)); + siz= rr->buf_size > 0 ? rr->buf_size - 1 : 0; // Fist element is part of sizeof(RunBuf) + rb= (RunBuf*)Alloc(sizeof(RunBuf) + siz * sizeof(double)); rb->coef= rr->coef; rb->cmd= rr->cmd; - rb->mov_cnt= (siz-1) * sizeof(double); + rb->mov_cnt= siz * sizeof(double); // rb->buf[] already zerod return rb; @@ -409,7 +409,7 @@ fid_run_newbuf(void *run) { int fid_run_bufsize(void *run) { - Run *rr= run; + Run *rr= (Run*)run; int siz; if (rr->magic != 0x64966325) @@ -430,8 +430,8 @@ fid_run_bufsize(void *run) { void fid_run_initbuf(void *run, void *buf) { - Run *rr= run; - RunBuf *rb= buf; + Run *rr= (Run*)run; + RunBuf *rb= (RunBuf*)buf; int siz; if (rr->magic != 0x64966325) @@ -453,7 +453,7 @@ fid_run_initbuf(void *run, void *buf) { void fid_run_zapbuf(void *buf) { - RunBuf *rb= buf; + RunBuf *rb= (RunBuf*)buf; memset(rb->buf, 0, rb->mov_cnt + sizeof(double)); } diff --git a/fidrf_combined.h b/fidrf_combined.h index dc7204b..6b5a606 100644 --- a/fidrf_combined.h +++ b/fidrf_combined.h @@ -17,6 +17,9 @@ // that the code is easy to understand. // +#ifndef FIDCOMBINED_H +#define FIDCOMBINED_H + typedef struct Run { int magic; // Magic: 0x64966325 double *fir; // FIR parameters @@ -144,3 +147,5 @@ fid_run_free(void *run) { } // END // +#endif + diff --git a/firun.c b/firun.c index b17fdda..b5296f7 100644 --- a/firun.c +++ b/firun.c @@ -55,6 +55,7 @@ NL " -L Ignore following arguments, display list of filter types." #include #include #include +#include #include #include #include @@ -115,10 +116,10 @@ int n_chan; // Number of output channels int n_filt; // Number of filters FidFilter **filt; // Loaded filters -uchar *inbuf; // Input buffer -uchar *inbufend; // End of input buffer allocated space, +1 -uchar *inp; // Input pointer -uchar *inend; // End of currently-loaded data, +1 +char *inbuf; // Input buffer +char *inbufend; // End of input buffer allocated space, +1 +char *inp; // Input pointer +char *inend; // End of currently-loaded data, +1 int ineof; // Hit EOF? // @@ -264,7 +265,7 @@ void refill_input() { if (!inbuf) { int len= 16384; // 100ms of data at 44100Hz 16-bit stereo - inbuf= ALLOC_ARR(len+1, uchar); + inbuf= ALLOC_ARR(len+1, char); inbufend= inbuf+len; *inbufend= 0; // Trailing NUL so that string-reading functions can never overrun inp= inend= inbuf; @@ -315,8 +316,7 @@ input(char **ipp) { inp++; continue; case 'a': { - int cnt; - uchar *tmp; + char *tmp; // Skip WS (maybe lots of it) while (1) { @@ -329,7 +329,7 @@ input(char **ipp) { if (inend - inp < 128 && !ineof) refill_input(); if (inp == inend) goto badeof; - val= strtod(inp, (char**)&tmp); + val= strtod(inp, &tmp); if (inp == tmp) error("Bad floating-point value:\n %.20s", inp); inp= tmp; @@ -367,7 +367,7 @@ input(char **ipp) { val= ((((ch2<<8) + ch1) ^ 32768) - 32768) / 32768.0; break; case 'f': - if (avail < sizeof(float)) goto badeof; + if (avail < (int)sizeof(float)) goto badeof; memcpy((void*)&fv, inp, sizeof(float)); inp += sizeof(float); val= fv; @@ -578,7 +578,6 @@ main(int ac, char **av) { char *ip= ispec; char *op= ospec; int chan= 0; - int ch; if (inend - inp < 128 && !ineof) refill_input(); diff --git a/mk-firun b/mk-firun index 641839d..aede515 100755 --- a/mk-firun +++ b/mk-firun @@ -1,6 +1,7 @@ #!/bin/bash OPT="-O6 -s" -[ "$1" = "-d" ] && OPT="-g" +[ "$1" = "-d" ] && OPT="-g -Wall -Wextra" -gcc -DT_LINUX $OPT fidlib.c firun.c -lm -o firun \ No newline at end of file + +gcc -DT_LINUX $OPT fidlib.c firun.c -lm -o firun