1 /*------------ Telecommunications & Signal Processing Lab --------------
2                          McGill University
3 
4 Routine:
5   libtsp.h
6 
7 Description:
8   Function prototypes and declarations for the TSP library routines
9 
10 Author / revision:
11   P. Kabal  Copyright (C) 2005
12   $Revision: 2.104 $  $Date: 2005/02/01 13:22:34 $
13 
14 ----------------------------------------------------------------------*/
15 
16 #ifndef libtsp_h_
17 #define libtsp_h_
18 
19 #include <stdio.h>	/* typedef for FILE */
20 
21 /* Audio file parameter structure */
22 #ifndef	AFILE_t_
23 #  define AFILE_t_
24 typedef struct AF_filepar AFILE;	/* Audio file parameters */
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* ----- AF Prototypes ----- */
32 void
33 AFclose (AFILE *AFp);
34 int
35 AFdReadData (AFILE *AFp, long int offs, double Dbuff[], int Nreq);
36 int
37 AFdWriteData (AFILE *AFp, const double Dbuff[], int Nval);
38 int
39 AFfReadData (AFILE *AFp, long int offs, float Dbuff[], int Nreq);
40 int
41 AFfWriteData (AFILE *AFp, const float Dbuff[], int Nval);
42 AFILE *
43 AFopnRead (const char Fname[], long int *Nsamp, long int *Nchan, double *Sfreq,
44 	   FILE *fpinfo);
45 AFILE *
46 AFopnWrite (const char Fname[], int Ftype, int Dformat, long int Nchan,
47 	    double Sfreq, FILE *fpinfo);
48 int
49 AFsetFileType (const char String[]);
50 void
51 AFsetInfo (const char Info[]);
52 int
53 AFsetNHpar (const char String[]);
54 int
55 AFsetSpeaker(const char String[]);
56 
57   /* Deprecated */
58 AFILE *
59 AFopenRead (const char Fname[], long int *Nsamp, long int *Nchan, float *Sfreq,
60 	    FILE *fpinfo);
61 AFILE *
62 AFopenWrite (const char Fname[], int Fformat, long int Nchan, double Sfreq,
63 	     FILE *fpinfo);
64 int
65 AFreadData (AFILE *AFp, long int offs, float Dbuff[], int Nreq);
66 int
67 AFwriteData (AFILE *AFp, const float Dbuff[], int Nval);
68 
69 
70 /* ----- FI Prototypes ----- */
71 void
72 FIdBiquad (const double x[], double y[], int Nout, const double h[5]);
73 void
74 FIdConvSI (const double x[], double y[], int Nout, const double h[], int Ncof,
75 	  int mr, int Nsub, int Ir);
76 void
77 FIdConvol (const double x[], double y[], int Nout, const double h[], int Ncof);
78 void
79 FIdFiltAP (const double x[], double y[], int Nout, const double p[], int Np);
80 void
81 FIdFiltIIR (const double x[], double y[], int Nout, const double h[][5],
82 	    int Nsec);
83 void
84 FIdKaiserLPF (double h[], int N, double Fc, double alpha);
85 int
86 FIdReadFilt (const char Fname[], int MaxNcof, double h[], int *Ncof,
87 	     FILE *fpinfo);
88 void
89 FIdWinHamm (double win[], int N, double a);
90 void
91 FIdWinKaiser (double win[], int N, double alpha);
92 void
93 FIfBiquad (const float x[], float y[], int Nout, const float h[5]);
94 void
95 FIfConvSI (const float x[], float y[], int Nout, const float h[], int Ncof,
96 	  int mr, int Nsub, int Ir);
97 void
98 FIfConvol (const float x[], float y[], int Nout, const float h[], int Ncof);
99 void
100 FIfDeem (double a, float *Fmem, const float x[], float y[], int Nout);
101 void
102 FIfFiltAP (const float x[], float y[], int Nout, const float p[], int Np);
103 void
104 FIfFiltIIR (const float x[], float y[], int Nout, const float h[][5],
105 	    int Nsec);
106 void
107 FIfKaiserLPF (float h[], int N, double Fc, double alpha);
108 void
109 FIfPreem (double a, float *Fmem, const float x[], float y[], int Nout);
110 int
111 FIfReadFilt (const char Fname[], int MaxNcof, float h[], int *Ncof,
112 	     FILE *fpinfo);
113 void
114 FIfWinHCos (float win[], double T1, double T2, double T3, double a);
115 void
116 FIfWinHamm (float win[], int N, double a);
117 void
118 FIfWinKaiser (float win[], int N, double alpha);
119 void
120 FIfWinRCos (float win[], int N, int Nadv);
121 double
122 FIgdelFIR (double w, const float h[], int Ncof);
123 double
124 FIgdelIIR (double w, const float h[][5], int Nsec);
125 
126 /* ----- FL Prototypes ----- */
127 void
128 FLbackup (const char Fname[]);
129 int
130 FLbaseName (const char Fname[], char Bname[]);
131 int
132 FLdReadData (const char Fname[], int MaxNval, double x[]);
133 void
134 FLdWriteData (const char Fname[], const double x[], int N);
135 char *
136 FLdate (const char Fname[], int format);
137 int
138 FLdefName (const char Fi[], const char Fd[], char Fo[]);
139 int
140 FLdirName (const char Fname[], char Bname[]);
141 int
142 FLexpHome (const char Fname[], char Ename[]);
143 int
144 FLextName (const char Fname[], char Ext[]);
145 int
146 FLfReadData (const char Fname[], int MaxNval, float x[]);
147 void
148 FLfWriteData (const char Fname[], const float x[], int N);
149 char *
150 FLfileDate (FILE *fp, int format);
151 int
152 FLfullName (const char Fname[], char Fullname[]);
153 char *
154 FLgetLine (FILE *fp);
155 char *
156 FLgetRec (FILE *fp, const char CommChar[], const char ContChar[], int echo);
157 int
158 FLhomeDir (const char User[], char Home[]);
159 int
160 FLpathList (const char Fi[], const char Dlist[], char Fo[]);
161 int
162 FLpreName (const char Fname[], char Pname[]);
163 void
164 FLprompt (const char Prompt[]);
165 char *
166 FLreadLine (const char Prompt[]);
167 
168 /* ----- FN Prototypes ----- */
169 double
170 FNbessI0 (double x);
171 double
172 FNevChebP (double x, const float c[], int N);
173 long int
174 FNgcd (long int u, long int v);
175 int
176 FNiLog2 (int a);
177 double
178 FNsinc (double x);
179 
180 /* ----- MA Prototypes ----- */
181 double **
182 MAdAllocMat (int Nrow, int Ncol);
183 void
184 MAdFreeMat (double *A[]);
185 void
186 MAdPrint (FILE *fp, const char Header[], const double *A[], int Nrow,
187 	  int Ncol);
188 float **
189 MAfAllocMat (int Nrow, int Ncol);
190 int
191 MAfChSolve (const float *A[], const float b[], float x[], int N);
192 void
193 MAfFreeMat (float *A[]);
194 void
195 MAfPrint (FILE *fp, const char Header[], const float *A[], int Nrow, int Ncol);
196 float **
197 MAfSubMat (const float *A[], int n, int m, int Nrow);
198 double
199 MAfSyBilin (const float *A[], const float x[], const float y[], int N);
200 double
201 MAfSyQuad (const float *A[], const float x[], int N);
202 double
203 MAfTpQuad (const float R[], const float x[], int N);
204 int
205 MAfTpSolve (const float R[], const float g[], float c[], int N);
206 void
207 MAiPrint (FILE *fp, const char Header[], const int *A[], int Nrow,
208 	  int Ncol);
209 void
210 MAlPrint (FILE *fp, const char Header[], const long int *A[], int Nrow,
211 	  int Ncol);
212 
213 /* ----- MS Prototypes ----- */
214 int
215 MSdConvCof (const double x[], int Nx, const double y[], int Ny, double z[]);
216 int
217 MSdDeconvCof (const double u[], int Nu, const double v[], int Nv,
218 	      double q[], double r[]);
219 void
220 MSdIntLin (const double x[], const double y[], int N, const double xi[],
221 	   double yi[], int Ni);
222 void
223 MSdIntMC (const double x[], const double y[], int N, const double xi[],
224 	  double yi[], int Ni);
225 int
226 MSdLocate (double x, const double T[], int N);
227 double
228 MSdNint (double x);
229 double
230 MSdPolyInt (double x, const double xa[], const double ya[], int N,
231 	    double buff[]);
232 int
233 MSfConvCof (const float x[], int Nx, const float y[], int Ny, float z[]);
234 double
235 MSfGaussRand (double rms);
236 void
237 MSfIntLin (const float x[], const float y[], int N, const float xi[],
238 	   float yi[], int Ni);
239 void
240 MSfIntMC (const float x[], const float y[], int N, const float xi[],
241 	  float yi[], int Ni);
242 double
243 MSfUnifRand (void);
244 int
245 MSiCeil (int n, int m);
246 int
247 MSiFloor (int n, int m);
248 int
249 MSiPower (int i, int n);
250 long int
251 MSlCeil (long int n, long int m);
252 long int
253 MSlFloor (long int n, long int m);
254 void
255 MSrandSeed (int seed);
256 void
257 MSratio (double Val, long int *N, long int *D, double tol, long int MaxN,
258 	 long int MaxD);
259 
260 /* ----- SP Prototypes ----- */
261 void
262 SPautoc (const float x[], int Nx, float cor[], int Nt);
263 void
264 SPcFFT (float x[], float y[], int N, int Ifn);
265 void
266 SPcepXpc (const float cep[], float pc[], int Np);
267 void
268 SPcorBWexp (double bwexp, const float rxx[], float rxxb[], int Nc);
269 double
270 SPcorFilt (double Ed, const float rxx[], const float r[], float h[], int N);
271 double
272 SPcorFmse (const float h[], double Ed, const float rxx[], const float r[],
273 	   int N);
274 double
275 SPcorPmse (const float pc[], const float rxx[], int Np);
276 double
277 SPcorXpc (const float rxx[], float pc[], int Np);
278 double
279 SPcovCXpc (const float *Cov[], float pc[], int Np);
280 double
281 SPcovFilt (double Ed, const float *R[], const float r[], float h[], int N);
282 double
283 SPcovFmse (const float h[], double Ed, const float *R[], const float r[],
284 	   int N);
285 double
286 SPcovLXpc (const float *Cov[], float pc[], int Np);
287 double
288 SPcovMXpc (const float *Cov[], float pc[], int Np);
289 double
290 SPcovPmse (const float pc[], const float *Cov[], int Np);
291 double
292 SPcovXpc (const float *Cov[], float pc[], int Np);
293 void
294 SPcovar (const float x[], int Nx, float *Cov[], int Np);
295 void
296 SPdCFFT (double x[], double y[], int N, int Ifn);
297 int
298 SPdQuantL (double x, const double Xq[], int Nreg);
299 void
300 SPdRFFT (double x[], int N, int Ifn);
301 void
302 SPecXpc (const float ec[], float pc[], int Np);
303 void
304 SPfCFFT (float x[], float y[], int N, int Ifn);
305 void
306 SPfDCT (float x[], int N, int Ifn);
307 int
308 SPfQuantL (double x, const float Xq[], int Nreg);
309 int
310 SPfQuantU (double x, const float Xq[], int Nreg);
311 void
312 SPfRFFT (float x[], int N, int Ifn);
313 double
314 SPlpcISdist (const float pc1[], const float pc2[], int Np);
315 double
316 SPlpcLSdist (const float pc1[], const float pc2[], int Np, int Ncep);
317 void
318 SPlsfXpc (const float lsf[], float pc[], int Np);
319 void
320 SPpcBWexp (double bwexp, const float pc[], float pcb[], int Np);
321 void
322 SPpcXcep (const float pc[], int Np, float cep[], int Ncep);
323 double
324 SPpcXcor (const float pc[], int Np, float rxx[], int Ncor);
325 void
326 SPpcXec (const float pc[], float ec[], int Np);
327 void
328 SPpcXlsf (const float pc[], float lsf[], int Np);
329 double
330 SPpcXrc (const float pc[], float rc[], int Np);
331 void
332 SPfRFFT (float x[], int N, int Ifn);
333 double
334 SPrcXpc (const float rc[], float pc[], int Np);
335 
336 /* ----- ST Prototypes ----- */
337 int
338 STcatMax (const char Si[], char So[], int Maxchar);
339 int
340 STcopyMax (const char Si[], char So[], int Maxchar);
341 int
342 STcopyNMax (const char Si[], char So[], int N, int Maxchar);
343 int
344 STdec1double (const char String[], double *Dval);
345 int
346 STdec1float (const char String[], float *Fval);
347 int
348 STdec1int (const char String[], int *Ival);
349 int
350 STdec1long (const char String[], long int *Lval);
351 int
352 STdecDfrac (const char String[], double *Dval1, double *Dval2);
353 int
354 STdecIfrac (const char String[], int *Ival1, int *Ival2);
355 int
356 STdecIrange (const char String[], int *Ival1, int *Ival2);
357 int
358 STdecLrange (const char String[], long int *Lval1, long int *Lval2);
359 int
360 STdecNdouble (const char String[], int Nmin, int Nmax, double Dval[], int *N);
361 int
362 STdecNfloat (const char String[], int Nmin, int Nmax, float Fval[], int *N);
363 int
364 STdecNint (const char String[], int Nmin, int Nmax, int Ival[], int *N);
365 int
366 STdecNlong (const char String[], int Nmin, int Nmax, long int Lval[],
367 	    int *N);
368 char *
369 STfindToken (const char String[], const char Delims[], const char Quotes[],
370 	     char Token[], int WSFlag, int Maxchar);
371 int
372 STkeyMatch (const char String[], const char *KeyTable[]);
373 int
374 STkeyXpar (const char Line[], const char Delims[], const char Quotes[],
375 	   const char *Keytable[], char Par[]);
376 int
377 STstrLC (const char Si[], char So[]);
378 int
379 STtrim (const char Si[], char So[]);
380 int
381 STunQuote (const char Si[], const char Quotes[], char So[]);
382 
383 /* ----- UT Prototypes ----- */
384 char *
385 UTdate (int format);
386 void
387 UTerror (const char Errmsg[], ...);
388 void
389 UTfree (void *ptr);
390 int
391 UTgetOption (int *Index, const int argc, const char *argv[],
392 	     const char *OptTable[], const char **OptArg);
393 char *
394 UTgetProg (void);
395 void
396 UThalt (const char Errmsg[], ...);
397 void *
398 UTmalloc (int size);
399 void *
400 UTrealloc (void *ptr, int size);
401 void
402 UTsetProg (const char Program[]);
403 void
404 UTsysMsg (const char Warnmsg[], ...);
405 char *
406 UTuserName (void);
407 void
408 UTwarn (const char Warnmsg[], ...);
409 
410 /* ----- VR Prototypes ----- */
411 void
412 VRdAdd (const double x1[], const double x2[], double y[], int N);
413 void
414 VRdCopy (const double x[], double y[], int N);
415 double
416 VRdCorSym (const double x[], int N);
417 double
418 VRdDotProd (const double x1[], const double x2[], int N);
419 void
420 VRdLinInc (double xmin, double xmax, double x[], int N);
421 void
422 VRdMult (const double x1[], const double x2[], double y[], int N);
423 void
424 VRdPrint (FILE *fp, const char Header[], const double x[], int N);
425 void
426 VRdRFFTMSq (const double X[], double X2[], int N);
427 void
428 VRdScale (double a, const double x[], double y[], int N);
429 void
430 VRdSet (double a, double y[], int N);
431 void
432 VRdShift (double x[], int Nkeep, int Nshift);
433 void
434 VRdSymPart (int Sym, const double x[], double y[], int N);
435 void
436 VRdZero (double y[], int N);
437 void
438 VRfAdd (const float x1[], const float x2[], float y[], int N);
439 void
440 VRfAmpldB (const float ampl[], float dB[], int N);
441 void
442 VRfCopy (const float x[], float y[], int N);
443 double
444 VRfCorSym (const float x[], int N);
445 void
446 VRfDiff (const float x1[], const float x2[], float y[], int N);
447 double
448 VRfDiffSq (const float x1[], const float x2[], int N);
449 double
450 VRfDotProd (const float x1[], const float x2[], int N);
451 void
452 VRfLog10 (const float x[], float y[], int N);
453 double
454 VRfMax (const float x[], int N);
455 double
456 VRfMin (const float x[], int N);
457 void
458 VRfMult (const float x1[], const float x2[], float y[], int N);
459 void
460 VRfPow10 (const float x[], float y[], int N);
461 void
462 VRfPrint (FILE *fp, const char Header[], const float x[], int N);
463 void
464 VRfRev (const float x[], float y[], int N);
465 void
466 VRfScale (double a, const float x[], float y[], int N);
467 void
468 VRfSet (double a, float y[], int N);
469 void
470 VRfShift (float x[], int Nkeep, int Nshift);
471 double
472 VRfSum (const float x[], int N);
473 void
474 VRfZero (float y[], int N);
475 void
476 VRiPrint (FILE *fp, const char Header[], const int x[], int N);
477 void
478 VRiZero (int y[], int N);
479 void
480 VRlPrint (FILE *fp, const char Header[], const long int x[], int N);
481 
482 #ifdef __cplusplus
483 }
484 #endif
485 
486 #endif /* libtsp_h_ */
487