//
//	File interface structures and prototypes
//
//	  Copyright (c) 2002 Jim Peters.  Released under the GNU
//	  GPL version 2.  See the file COPYING for details.
//

typedef struct BWFile BWFile;
typedef struct BWBlock BWBlock;
typedef struct FormatInfo FormatInfo;

struct BWFile {
   FILE *fp;		// File pointer for reading
   fpos_t *blk;		// Block offsets in file
   int m_blk;		// Max blocks in blk[] (i.e. size of array)
   int n_blk;		// Number of block-offsets stored in blk[].
   fpos_t pos;		// Position to find next block after n_blk
   int eof;		// Hit EOF yet ?

   int bsiz;		// Block size in samples
   int max_unref;	// Maximum number of unreferenced blocks in cache

   int (*read)(BWFile*,BWBlock*,FILE*,float**,char*,int);  // Format-specific read routine
   void *read_data;	// Special format-specific data, or 0.  Released with free()
   double rate;		// Sample rate of file
   int chan;		// Number of channels in the file
   int len;		// Length of file in samples, or -1 if end not reached yet
   
   BWBlock *cache;	// Cached block list, or 0
   int use;		// Use counter, used to find old blocks to delete
};

struct BWBlock {
   BWBlock *nxt;	// Next in list, or 0
   int num;		// Block number in file, counting from 0
   int ref;		// Reference count
   int last_used;	// Set from BWFile.use when ref goes to 0
   int len;		// Number of samples in this block
   float **chan;	// Array of float data for channels
   char *err;		// Array of error flags for the data: 0 no error, 1 sync error
};

struct FormatInfo {
   int (*setup)(BWFile *ff, FILE *in, char *fmt, char *arg);
   char *desc;
};


// END //

