1 //
2 //	fidlib include file
3 //
4 #ifndef FIDLIB_H
5 #define FIDLIB_H
6 typedef struct FidFilter FidFilter;
7 struct FidFilter {
8    short typ;		// Type of filter element 'I' IIR, 'F' FIR, or 0 for end of list
9    short cbm;		// Constant bitmap.  Bits 0..14, if set, indicate that val[0..14]
10    			//   is a constant across changes in frequency for this filter type
11    			//   Bit 15, if set, indicates that val[15..inf] are constant.
12    int len;		// Number of doubles stored in val[], or 0 for end of list
13    double val[1];
14 };
15 
16 // Lets you write: for (; ff->typ; ff= FFNEXT(ff)) { ... }
17 #define FFNEXT(ff) ((FidFilter*)((ff)->val + (ff)->len))
18 
19 // Size of a sub-filter with 'cnt' double values attached
20 #define FFSIZE(cnt) (sizeof(FidFilter) + ((cnt)-1)*sizeof(double))
21 
22 // Size required for the memory chunk to contain the given number
23 // headers and values, plus termination
24 #define FFCSIZE(n_head,n_val) ((sizeof(FidFilter)-sizeof(double))*((n_head)+1) + sizeof(double)*(n_val))
25 
26 // Allocate the chunk of memory to hold a list of FidFilters, with
27 // n_head FidFilters and n_val total double values in the whole list.
28 // Includes space for the final termination, and zeros the memory.
29 #define FFALLOC(n_head,n_val) (FidFilter*)Alloc(FFCSIZE(n_head, n_val))
30 
31 // These are so you can use easier names to refer to running filters
32 typedef void FidRun;
33 typedef double (FidFunc)(void*, double);
34 
35 
36 //
37 //	Prototypes
38 //
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 extern void fid_set_error_handler(void(*rout)(char *));
44 extern char *fid_version();
45 extern double fid_response_pha(FidFilter *filt, double freq, double *phase);
46 extern double fid_response(FidFilter *filt, double freq);
47 extern int fid_calc_delay(FidFilter *filt);
48 extern FidFilter *fid_design(const char *spec, double rate, double freq0, double freq1,
49 			     int f_adj, char **descp);
50 extern double fid_design_coef(double *coef, int n_coef, const char *spec,
51 			      double rate, double freq0, double freq1, int adj);
52 extern void fid_list_filters(FILE *out);
53 extern int fid_list_filters_buf(char *buf, char *bufend);
54 extern FidFilter *fid_flatten(FidFilter *filt);
55 extern void fid_rewrite_spec(const char *spec, double freq0, double freq1, int adj,
56 			     char **spec1p, char **spec2p,
57 			     double *freq0p, double *freq1p, int *adjp);
58 extern FidFilter *fid_cv_array(double *arr);
59 extern FidFilter *fid_cat(int freeme, ...);
60 extern char *fid_parse(double rate, char **pp, FidFilter **ffp);
61 
62 //
63 //	Filter running prototypes
64 //
65 
66 extern void *fid_run_new(FidFilter *filt, double(**funcpp)(void *, double));
67 extern void *fid_run_newbuf(void *run);
68 extern int fid_run_bufsize(void *run);
69 extern void fid_run_initbuf(void *run, void *buf);
70 extern void fid_run_zapbuf(void *buf);
71 extern void fid_run_freebuf(void *runbuf);
72 extern void fid_run_free(void *run);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 #endif
78