diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..a31ce65 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Jim Peters + +Daniel Schürmann + Patches contributed from Mixxx project + +Alexander Barker + Autotools build system + Small patches to fix warnings diff --git a/COPYING_LIB b/COPYING.LESSER similarity index 100% rename from COPYING_LIB rename to COPYING.LESSER diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..cdfcb3e --- /dev/null +++ b/Makefile.am @@ -0,0 +1,25 @@ +ACLOCAL_AMFLAGS = -I m4 + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = $(top_builddir)/fidlib.pc + +include_HEADERS = fidlib.h + +bin_PROGRAMS = +lib_LTLIBRARIES = libfidlib.la + + +libfidlib_la_CFLAGS = $(AM_CFLAGS) -Wall -Wextra -I$(top_srcdir) +libfidlib_la_LDFLAGS = $(LTLDFLAGS) $(LDFLAGS) +libfidlib_la_SOURCES = fidlib.c + +if BUILD_TEST +bin_PROGRAMS += firun + +firun_SOURCES = firun.c +firun_LDADD = $(top_builddir)/libfidlib.la +firun_CFLAGS = $(AM_CFLAGS) -Wall $(TEST_CFLAGS) -I$(top_srcdir) +firun_LDFLAGS = $(LTLDFLAGS) $(TEST_LIBS) + +EXTRA_DIST = README.firun +endif diff --git a/fidlib.txt b/README similarity index 100% rename from fidlib.txt rename to README diff --git a/firun.txt b/README.firun similarity index 100% rename from firun.txt rename to README.firun diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..516041a --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ ! -d ./m4 ]; then + mkdir ./m4 +fi + +if [ "$(uname)" == "Darwin" ]; then + include=" -I/opt/local/share/aclocal" +fi + +autoreconf --install --verbose --force $include diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..2a1d856 --- /dev/null +++ b/configure.ac @@ -0,0 +1,81 @@ + +# Define a few constants using m4 macros to prevent multiple definitions. +m4_define([FIDLIB_MAJOR], [0]) +m4_define([FIDLIB_MINOR], [9]) +m4_define([FIDLIB_PATCH], [11]) +m4_define([FIDLIB_RC], []) +m4_define([FIDLIB_BUGS], [jim@uazu.net]) +m4_define([FIDLIB_VERSION_STRING], FIDLIB_MAJOR[.]FIDLIB_MINOR[.]FIDLIB_PATCH[]FIDLIB_RC) + +m4_pattern_allow([AM_PROG_AR]) + +# Library versioning +# These numbers should be tweaked on every release. Read carefully: +# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +# http://sourceware.org/autobook/autobook/autobook_91.html +lt_current="0" +lt_revision="2" +lt_age="1" +LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}" + + +# Initialize autoconf. +AC_INIT([fidlib], [FIDLIB_VERSION_STRING], [FIDLIB_BUGS]) + +AC_PREREQ(2.64) + +AC_CONFIG_SRCDIR([fidlib.h]) +AC_CONFIG_FILES([ + fidlib.pc \ + Makefile +]) +#AC_CONFIG_AUX_DIR([config]) +#AC_CONFIG_HEADERS([config.h:config.h.in]) +AC_CONFIG_MACRO_DIR([m4]) + +#AC_CANONICAL_SYSTEM +AC_CANONICAL_HOST +AC_CANONICAL_BUILD +AC_CANONICAL_TARGET + +# Initialize automake. +AM_INIT_AUTOMAKE([foreign subdir-objects]) + +# Checks for language. +AC_LANG([C]) + +# Checks for programs. +AC_PROG_CC([gcc clang]) +AC_PROG_CC_C99 +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) + +# Checks for header files +AC_C_CONST +AC_HEADER_STDC +AC_CHECK_HEADERS([math.h unistd.h errno.h]) + +# Initialize libtool. +AC_PROG_LIBTOOL + +AC_ARG_ENABLE([test], + AS_HELP_STRING([--enable-test], [Enable test application firun (default: disabled)]), + [enable_test=$enableval], + [enable_test="no"]) + + +AS_IF([test "x$enable_test" = "xyes"], [ + AC_DEFINE([USE_TEST], 1, [Enable Test Application]) +]) + +# Checks for libraries. +LIBS="-lm $LIBS" + +# Requires for pkg-config +AC_SUBST([LIBS]) +AC_SUBST([TEST_LIBS]) + +# Should the unit tests be built? +AM_CONDITIONAL([BUILD_TEST], [test "x$enable_test" = "xyes"]) + +# Generate the "configure" script +AC_OUTPUT diff --git a/fidlib.c b/fidlib.c index 7f03c7d..12eab0c 100644 --- a/fidlib.c +++ b/fidlib.c @@ -24,9 +24,6 @@ // Robert Bristow-Johnson's EQ cookbook formulae: // http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt // - -#define VERSION "0.9.10" - // // Filter specification string // --------------------------- @@ -195,28 +192,6 @@ // depends on the filter type. // -// -// Check that a target macro has been set. This macro selects -// various fixes required on various platforms: -// -// T_LINUX Linux, or probably any UNIX-like platform with GCC -// T_MINGW MinGW -- either building on Win32 or cross-compiling -// T_MSVC Microsoft Visual C -// -// (On MSVC, add "T_MSVC" to the preprocessor definitions in the -// project settings, or add /D "T_MSVC" to the compiler -// command-line.) -// - -#ifndef T_LINUX -#ifndef T_MINGW -#ifndef T_MSVC -#error Please define one of the T_* target macros (e.g. -DT_LINUX); see fidlib.c -#endif -#endif -#endif - - // // Select which method of filter execution is preferred. // RF_CMDLIST is recommended (and is the default). @@ -226,14 +201,8 @@ // RF_JIT -- fastest JIT run-time generated code (no longer supported) // -#ifndef RF_COMBINED -#ifndef RF_CMDLIST -#ifndef RF_JIT - +#if !defined(RF_COMBINED) && !defined(RF_CMDLIST) && !defined(RF_JIT) #define RF_CMDLIST - -#endif -#endif #endif // @@ -259,26 +228,16 @@ extern FidFilter *mkfilter(char *, ...); // // Macro for local inline routines that shouldn't be visible externally -#ifdef T_MSVC - #define STATIC_INLINE static __inline -#else - #define STATIC_INLINE static inline +// because Microsoft can't figure out how to support C99. +// See Mixxx Bug #1179683 +#ifdef _MSC_VER +#define XINLINE __inline +#define vsnprintf _vsnprintf +#ifndef snprintf +#define snprintf _snprintf #endif - -// MinGW and MSVC fixes -#if defined(T_MINGW) || defined(T_MSVC) - #ifndef vsnprintf - #define vsnprintf _vsnprintf - #endif - #ifndef snprintf - #define snprintf _snprintf - #endif -// Not sure if we strictly need this still - STATIC_INLINE double - my_asinh(double val) { - return log(val + sqrt(val*val + 1.0)); - } - #define asinh(xx) my_asinh(xx) +#else +#define XINLINE inline #endif @@ -310,7 +269,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"); @@ -332,7 +291,7 @@ Alloc(int size) { // Complex multiply: aa *= bb; // -STATIC_INLINE void +static XINLINE void cmul(double *aa, double *bb) { double rr= aa[0] * bb[0] - aa[1] * bb[1]; double ii= aa[0] * bb[1] + aa[1] * bb[0]; @@ -344,7 +303,7 @@ cmul(double *aa, double *bb) { // Complex square: aa *= aa; // -STATIC_INLINE void +static XINLINE void csqu(double *aa) { double rr= aa[0] * aa[0] - aa[1] * aa[1]; double ii= 2 * aa[0] * aa[1]; @@ -356,7 +315,7 @@ csqu(double *aa) { // Complex multiply by real: aa *= bb; // -STATIC_INLINE void +static XINLINE void cmulr(double *aa, double fact) { aa[0] *= fact; aa[1] *= fact; @@ -366,7 +325,7 @@ cmulr(double *aa, double fact) { // Complex conjugate: aa= aa* // -STATIC_INLINE void +static XINLINE void cconj(double *aa) { aa[1]= -aa[1]; } @@ -375,7 +334,7 @@ cconj(double *aa) { // Complex divide: aa /= bb; // -STATIC_INLINE void +static XINLINE void cdiv(double *aa, double *bb) { double rr= aa[0] * bb[0] + aa[1] * bb[1]; double ii= -aa[0] * bb[1] + aa[1] * bb[0]; @@ -388,7 +347,7 @@ cdiv(double *aa, double *bb) { // Complex reciprocal: aa= 1/aa // -STATIC_INLINE void +static XINLINE void crecip(double *aa) { double fact= 1.0 / (aa[0] * aa[0] + aa[1] * aa[1]); aa[0] *= fact; @@ -399,7 +358,7 @@ crecip(double *aa) { // Complex assign: aa= bb // -STATIC_INLINE void +static XINLINE void cass(double *aa, double *bb) { memcpy(aa, bb, 2*sizeof(double)); // Assigning doubles is really slow } @@ -408,7 +367,7 @@ cass(double *aa, double *bb) { // Complex assign: aa= (rr + ii*j) // -STATIC_INLINE void +static XINLINE void cassz(double *aa, double rr, double ii) { aa[0]= rr; aa[1]= ii; @@ -418,7 +377,7 @@ cassz(double *aa, double rr, double ii) { // Complex add: aa += bb // -STATIC_INLINE void +static XINLINE void cadd(double *aa, double *bb) { aa[0] += bb[0]; aa[1] += bb[1]; @@ -428,7 +387,7 @@ cadd(double *aa, double *bb) { // Complex add: aa += (rr + ii*j) // -STATIC_INLINE void +static XINLINE void caddz(double *aa, double rr, double ii) { aa[0] += rr; aa[1] += ii; @@ -438,7 +397,7 @@ caddz(double *aa, double rr, double ii) { // Complex subtract: aa -= bb // -STATIC_INLINE void +static XINLINE void csub(double *aa, double *bb) { aa[0] -= bb[0]; aa[1] -= bb[1]; @@ -448,7 +407,7 @@ csub(double *aa, double *bb) { // Complex subtract: aa -= (rr + ii*j) // -STATIC_INLINE void +static XINLINE void csubz(double *aa, double rr, double ii) { aa[0] -= rr; aa[1] -= ii; @@ -458,7 +417,7 @@ csubz(double *aa, double rr, double ii) { // Complex negate: aa= -aa // -STATIC_INLINE void +static XINLINE void cneg(double *aa) { aa[0]= -aa[0]; aa[1]= -aa[1]; @@ -470,7 +429,7 @@ cneg(double *aa) { // Coefficients are real values. // -STATIC_INLINE void +static XINLINE void evaluate(double *rv, double *coef, int n_coef, double *in) { double pz[2]; // Powers of Z @@ -694,14 +653,14 @@ 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 @@ -824,24 +783,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 +825,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,54 +837,85 @@ 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)); @@ -915,102 +927,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]; @@ -1022,6 +1085,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]; @@ -1033,6 +1099,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]; @@ -1044,6 +1113,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]; @@ -1054,6 +1126,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]; @@ -1064,6 +1139,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]; @@ -1075,6 +1153,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); @@ -1093,6 +1174,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); @@ -1111,11 +1195,16 @@ 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); 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; @@ -1135,11 +1224,16 @@ 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; @@ -1158,11 +1252,16 @@ 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; @@ -1181,11 +1280,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; @@ -1337,7 +1441,7 @@ 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 +1455,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; @@ -1388,7 +1492,7 @@ fid_design(char *spec, double rate, double freq0, double freq1, int f_adj, char 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; @@ -1610,14 +1714,14 @@ expand_spec(char *buf, char *bufend, char *str) { // double -fid_design_coef(double *coef, int n_coef, char *spec, double rate, +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; int a, len; int cnt= 0; double gain= 1.0; - double *iir, *fir, iir_adj; + double *iir, *fir, iir_adj = 0.0; static double const_one= 1; int n_iir, n_fir; int iir_cbm, fir_cbm; @@ -1723,7 +1827,7 @@ fid_list_filters_buf(char *buf, char *bufend) { // Do a convolution of parameters in place // -STATIC_INLINE int +static XINLINE int convolve(double *dst, int n_dst, double *src, int n_src) { int len= n_dst + n_src - 1; int a, b; @@ -1825,7 +1929,7 @@ parse_spec(Spec *sp) { 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); @@ -1937,7 +2041,7 @@ parse_spec(Spec *sp) { // void -fid_rewrite_spec(char *spec, double freq0, double freq1, int adj, +fid_rewrite_spec(const char *spec, double freq0, double freq1, int adj, char **spec1p, char **spec2p, double *freq0p, double *freq1p, int *adjp) { Spec sp; @@ -1959,14 +2063,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; @@ -2015,7 +2119,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; ) { @@ -2061,7 +2165,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); @@ -2147,7 +2251,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,9 +2263,9 @@ 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; @@ -2179,9 +2283,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; @@ -2248,7 +2352,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/fidlib.pc.in b/fidlib.pc.in new file mode 100644 index 0000000..044d88c --- /dev/null +++ b/fidlib.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: fidlib +Description: fidlib library +Version: @VERSION@ +Libs: @LIBS@ -L${libdir} -lfidlib +Cflags: -I${includedir} +Requires: @REQUIRE@ \ No newline at end of file diff --git a/fidmkf.h b/fidmkf.h index 37c7b50..d5295db 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) @@ -142,13 +153,13 @@ // Complex square root: aa= aa^0.5 // -STATIC_INLINE double +static XINLINE double my_sqrt(double aa) { return aa <= 0.0 ? 0.0 : sqrt(aa); } // 'csqrt' clashes with builtin in GCC 4, so call it 'c_sqrt' -STATIC_INLINE void +static XINLINE void c_sqrt(double *aa) { double mag= hypot(aa[0], aa[1]); double rr= my_sqrt((mag + aa[0]) * 0.5); @@ -162,7 +173,7 @@ c_sqrt(double *aa) { // Complex imaginary exponent: aa= e^i.theta // -STATIC_INLINE void +static XINLINE void cexpj(double *aa, double theta) { aa[0]= cos(theta); aa[1]= sin(theta); @@ -173,7 +184,7 @@ cexpj(double *aa, double theta) { // // 'cexp' clashes with builtin in GCC 4, so call it 'c_exp' -STATIC_INLINE void +static XINLINE void c_exp(double *aa) { double mag= exp(aa[0]); aa[0]= mag * cos(aa[1]); @@ -211,7 +222,7 @@ static char zertyp[MAXPZ]; // Pre-warp a frequency // -STATIC_INLINE double +static XINLINE double prewarp(double val) { return tan(val * M_PI) / 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..da741cc 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; @@ -237,7 +237,7 @@ fid_run_new(FidFilter *filt, double (**funcpp)(void *,double)) { while (filt->len) { int n_iir, n_fir, cnt; double *iir, *fir; - double adj; + double adj = 0.0; if (filt->typ == 'F' && filt->len == 1) { gain *= filt->val[0]; filt= FFNEXT(filt); @@ -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 deleted file mode 100755 index 641839d..0000000 --- a/mk-firun +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -OPT="-O6 -s" -[ "$1" = "-d" ] && OPT="-g" - -gcc -DT_LINUX $OPT fidlib.c firun.c -lm -o firun \ No newline at end of file diff --git a/mk-firun-mingw b/mk-firun-mingw deleted file mode 100755 index 22c676a..0000000 --- a/mk-firun-mingw +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -OPT="-O6 -s" -[ "$1" = "-d" ] && OPT="-g" - -gcc -DT_MINGW $OPT fidlib.c firun.c -lm -o firun.exe - diff --git a/mk-firun-tmp b/mk-firun-tmp deleted file mode 100755 index adc785f..0000000 --- a/mk-firun-tmp +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -OPT="-O6 -s" -[ "$1" = "-d" ] && OPT="-g" - -gcc -DT_LINUX $OPT fidlib.c firun-tmp.c -lm -o firun-tmp \ No newline at end of file diff --git a/mk-firun-xmingw b/mk-firun-xmingw deleted file mode 100755 index ed6b01d..0000000 --- a/mk-firun-xmingw +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Cross-compile from Linux to Win32 using mingw32 cross-compiler as -# provided by Debian. Rather hard-coded to my setup here; will need -# adapting anywhere else. - -OPT="-O6 -s" -[ "$1" = "-d" ] && OPT="-g" - -GCC=i586-mingw32msvc-gcc -#INCL="-I /home/jim/win/msys/1.0/mingw/include" -#LIBS="-L/home/jim/win/msys/1.0/mingw/lib -lmingw32" -INCL="-I /usr/i586-mingw32msvc/include" -LIBS="-L/usr/i586-mingw32msvc/lib -lmingw32" - -$GCC -DT_MINGW $OPT $INCL fidlib.c firun.c $LIBS -lm -o firun.exe -