1 /* \r
2 * fil.h: Definitions for file handling functions (file stored in memory!)\r
3 */\r
4 #ifndef _FIL_H\r
5 #define _FIL_H\r
6 \r
7 #include <xdc/std.h> /* required for types.h */\r
8 #include <ti/mas/types/types.h>\r
9 \r
10 #include "sys.h" /* for eampling rate, etc. */\r
11 \r
12 /*======================================================================\r
13 * File related constants\r
14 *======================================================================*/\r
15 \r
16 #define FIL_MAX SYS_MICS_MAX /* Maximum number of files */\r
17 \r
18 #define FIL_L_ENDIAN (FALSE) /* Little endian byte ordering in file */\r
19 #define FIL_B_ENDIAN (TRUE)1 /* Big endian byte ordering in file */\r
20 \r
21 #define FIL_DURATION_MAX_MS (60*1000L) /* 1min max duration */\r
22 #define FIL_LENGTH_MAX (SYS_FS_HZ*FIL_DURATION_MAX_MS/1000) /* max length in samples */\r
23 #define FIL_OUTDURATION_MAX_MS (FIL_DURATION_MAX_MS+1*1000L) /* 1s longer than input */\r
24 #define FIL_OUTLEN_MAX (SYS_FS_HZ*FIL_OUTDURATION_MAX_MS/1000) /* in samples */\r
25 \r
26 /*======================================================================\r
27 * Bit masks, byte swapping macros, error codes\r
28 *======================================================================*/\r
29 \r
30 /* Bit masks for byte swapping */\r
31 #define FIL_LOW_BYTE 0x00FFu\r
32 #define FIL_HIGH_BYTE 0xFF00u\r
33 \r
34 /* Macros for bit-mask manipulations */\r
35 #define FIL_GET_LOW(x) ((x)&FIL_LOW_BYTE)\r
36 #define FIL_GET_HIGH(x) (((x)>>8)&FIL_LOW_BYTE)\r
37 #define FIL_SWAP_BYTES(x) ((FIL_GET_LOW(x)<<8)|FIL_GET_HIGH(x))\r
38 \r
39 /*======================================================================\r
40 * File related types\r
41 *======================================================================*/\r
42 \r
43 /* File Configuration Structure */\r
44 struct filConfig_stc {\r
45 tlong length; /* number of samples in the input files */\r
46 tint nfiles; /* number of memory input files to create */\r
47 tbool big; /* TRUE: big endian, FALSE: little endian byte order */\r
48 tbool wrap; /* TRUE: do wrap-around, FALSE: do not wrap-around */\r
49 tlong outlen; /* number of samples in the output file */\r
50 };\r
51 typedef struct filConfig_stc filConfig_t;\r
52 \r
53 /* File Descriptor Structure (handles all files) */\r
54 struct filDescriptor_stc {\r
55 tlong r_idx; /* current read index (sample based) */\r
56 tlong w_idx; /* current write index (sample based) */\r
57 tlong length; /* number of samples in an input file (does not apply to output!) */\r
58 tint nfiles; /* numbner of configured files */\r
59 \r
60 void *filbase[FIL_MAX]; /* base addresses of file buffers */\r
61 \r
62 /* Use 'big' for both R&W */\r
63 tbool big; /* TRUE: big endian, FALSE: little endian byte order */\r
64 tbool wrap; /* TRUE: do wrap-around, FLASE: do not wrap-around (input only) */\r
65 \r
66 /* WRITE Part */\r
67 tlong outlen; /* Output buffer length in samples */\r
68 void *outbuf; /* A pointer to the output buffer */\r
69 };\r
70 typedef struct filDescriptor_stc filDescriptor_t;\r
71 \r
72 /*======================================================================\r
73 * API Prototypes\r
74 *======================================================================*/\r
75 \r
76 extern int filCreate(void**,filConfig_t*); /* Initialize file descriptor */\r
77 extern void *filGetHandle(void); /* Return file handle */\r
78 extern tlong filLoad(char*, tlong, int); /* Load file into memory */\r
79 extern int filRead(void*,int,linSample*,int); /* Read samples from files */\r
80 extern int filWrite(void*, int, linSample*); /* Write sample into file */\r
81 \r
82 #endif\r
83 /* nothing past this point */\r
84 \r