/*------------ Telecommunications & Signal Processing Lab --------------
                         McGill University

Routine:
  AFfiles.h

Description:
  Function prototypes for the TSP library AF file internal routines

Author / revision:
  P. Kabal  Copyright (C) 1999
  $Revision: 1.22 $  $Date: 1999/06/04 23:27:17 $

----------------------------------------------------------------------*/

#ifndef AFfile_h_
#define AFfile_h_

#include <stdio.h>	/* typedef for FILE */
#include <setjmp.h>	/* typedef for jmp_buf */

struct AF_opt;				/* Audio file routine options */
struct AF_NHpar;			/* Headerless audio file parameters */
struct AF_infox;			/* Header information string */
struct AF_info;				/* Header information string */
struct AF_read;				/* File format and data parameters */
struct AF_write;			/* File format and data parameters */

#ifndef	AFILE_t_
#  define AFILE_t_
typedef struct AF_filepar AFILE;	/* Audio file parameters */
#endif

/* Header read/write definitions */
#define RHEAD_S(fp,string) \
	AFreadHead (fp, (void *)(string), 1, (int) (sizeof (string)), \
		    DS_NATIVE)
#define RHEAD_SN(fp,string,N) \
	AFreadHead (fp, (void *) (string), 1, (int) (N), DS_NATIVE)
#define RHEAD_V(fp,value,swap) \
	AFreadHead (fp, (void *) &(value), (int) (sizeof (value)), 1, \
		    (int) (swap))
#define RSKIP(fp,nbytes) \
	AFreadHead (fp, NULL, 1, (int) (nbytes), DS_NATIVE)
#define WHEAD_S(fp,string) \
	AFwriteHead (fp, (const void *) (string), 1, (int) (sizeof (string)), \
		     DS_NATIVE)
#define WHEAD_SN(fp,string,N) \
	AFwriteHead (fp, (const void *) (string), 1, (int) (N), DS_NATIVE)
#define WHEAD_P(fp,string) \
	AFwriteHead (fp, (const void *) (string), 1, (int) (strlen (string)), \
		     DS_NATIVE)
#define WHEAD_V(fp,value,swap) \
	AFwriteHead (fp, (const void *) &(value), (int) (sizeof (value)), 1, \
		     (int) (swap))

#ifdef __cplusplus
extern "C" {
#endif

int
AFfindType (FILE *fp);
struct AF_info *
AFgenHinfo (double Sfreq);
const char *
AFgetHrec (const char name[], const struct AF_info *Hinfo);
int
AFgetSPrec (const char name[], int type, void *data, int erropt,
	    const char head[], int N);
struct AF_opt *
AFoptions (void);
void
AFprAFpar (AFILE *AFp, const char Fname[], FILE *fpinfo);
AFILE *
AFrdAIhead (FILE *fp);
AFILE *
AFrdAUhead (FILE *fp);
AFILE *
AFrdBLhead (FILE *fp);
AFILE *
AFrdEShead (FILE *fp);
int
AFrdHinfo (FILE *fp, int Size, struct AF_info *Hinfo, int Align);
int
AFrdHtext (FILE *fp, int Size, const char Ident[], struct AF_info *Hinfo,
	   int Align);
AFILE *
AFrdINhead (FILE *fp);
AFILE *
AFrdSFhead (FILE *fp);
AFILE *
AFrdSPhead (FILE *fp);
AFILE *
AFrdSWhead (FILE *fp);
AFILE *
AFrdTAhead (FILE *fp);
AFILE *
AFrdWVhead (FILE *fp);
int
AFreadHead (FILE *fp, void *Buf, int size, int Nelem, int Swapb);
AFILE *
AFsetNHread (FILE *fp, const char Fname[]);
AFILE *
AFsetNHwrite (FILE *fp, int Dformat, int Swapb, long int Nchan, double Sfreq);
AFILE *
AFsetRead (FILE *fp, int Ftype, struct AF_read *AFr, int Fix);
AFILE *
AFsetWrite (FILE *fp, int Ftype, struct AF_write *AFw);
int
AFupdAIhead (AFILE *AFp);
int
AFupdAUhead (AFILE *AFp);
int
AFupdHead (AFILE *AFp);
int
AFupdWVhead (AFILE *AFp);
AFILE *
AFwrAIhead (FILE *fp, int Format, long int Nframe, long int Nchan,
	    double Sfreq);
AFILE *
AFwrAUhead (FILE *fp, int Format, long int Nframe, long int Nchan,
	    double Sfreq);
AFILE *
AFwrWVhead (FILE *fp, int Format, long int Nframe, long int Nchan,
	    double Sfreq);
int
AFwriteHead (FILE *fp, const void *Buf, int Size, int Nv, int Swapb);

#ifdef __cplusplus
}
#endif

#endif /* AFfile_h_ */
