1 /*
2 * Copyright (c) 2016, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33 \r
34 /* \r
35 sys.h: System constants, data types, prototypes.\r
36 */\r
37 #ifndef _SYS_H\r
38 #define _SYS_H\r
39 \r
40 #include <xdc/std.h> /* required for types.h */\r
41 #include <ti/mas/types/types.h>\r
42 #include <ti/mas/util/ecomem.h>\r
43 \r
44 /*======================================================================\r
45 * Static system configuration parameters\r
46 *======================================================================*/\r
47 \r
48 #define SYS_MICS_MAX 8 /* Maximum number of microphones in the system */\r
49 #define SYS_VMICS_MAX 12 /* Maximum number of virtual microphones in the system */\r
50 #define SYS_FS_HZ 16000 /* Sampling rate in Hz */\r
51 #define SYS_FRAME_DURATION_MS 10 /* Frame duration in ms */\r
52 #define SYS_FRAME_LENGTH (1L*SYS_FS_HZ*SYS_FRAME_DURATION_MS/1000) /* Frame length in samples */\r
53 #define SYS_FRAME_SIZE (TYP_LINSAMPLE_SIZE*SYS_FRAME_LENGTH/TYP_TWORD_SIZE) /* Frame size in bytes */\r
54 #define SYS_IN_LENGTH (2L*SYS_FRAME_LENGTH*SYS_MICS_MAX) /* Input buffer length (dual) */\r
55 #define SYS_IN_SIZE (TYP_LINSAMPLE_SIZE*SYS_IN_LENGTH/TYP_TWORD_SIZE) /* # of words in input buffer */\r
56 \r
57 /*======================================================================\r
58 * Bit masks, bit-mask handling macros, error codes\r
59 *======================================================================*/\r
60 \r
61 /* Bit masks for sysPrintConfig */\r
62 #define SYSM_SCOPE_STATIC 0x1 /* Static system information */\r
63 #define SYSM_SCOPE_DYNAMIC 0x2 /* Dynamic system onfirmation */\r
64 \r
65 /* Macros for bit-mask manipulations */\r
66 #define SYS_MASK_GET(value,mask) ((value)&(mask))\r
67 #define SYS_MASK_SET(value,mask) ((value)|(mask))\r
68 #define SYS_MASK_TEST(value,mask) (SYS_MASK_GET(value,mask)!=0)\r
69 \r
70 /* System error codes */\r
71 #define SYS_ERR_SUCCESS 0\r
72 #define SYS_ERR_BADCONFIG (-1)\r
73 #define SYS_INV_HANDLE (-2)\r
74 #define SYS_INV_LOGIC (-3)\r
75 #define SYS_ERR_BUFLENGTH (-4)\r
76 #define SYS_ERR_FOPEN (-5)\r
77 #define SYS_ERR_FLOAD (-6)\r
78 #define SYS_ERR_FMAXBUF (-7)\r
79 #define SYS_ERR_FREAD (-8)\r
80 #define SYS_ERR_HEAPINIT (-9)\r
81 #define SYS_ERR_INVHEAPCLASS (-10)\r
82 #define SYS_ERR_BFERROR (-11)\r
83 #define SYS_ERR_EOF (-12)\r
84 #define SYS_ERR_ASNRERROR (-13)\r
85 #define SYS_ERR_MSSERROR (-14)\r
86 #define SYS_ERR_MSSDEBUG (-15)\r
87 #define SYS_ERR_ANGLECONFIG (-16)\r
88 #define SYS_ERR_VAUERROR (-17)\r
89 \r
90 /*======================================================================\r
91 * System Data Types\r
92 *======================================================================*/\r
93 \r
94 /* System Configuration Structure */\r
95 struct sysConfig_stc {\r
96 tint nmics; /* The actual number of microphones in ths system */\r
97 tint nvmics; /* The acutal number of virtual microphones in the system */\r
98 tbool use_fileio; /* Use file I/O to load microphone files */\r
99 tbool use_default; /* Use default angles for virtual microphones */\r
100 };\r
101 typedef struct sysConfig_stc sysConfig_t;\r
102 \r
103 /* System Context Structure */\r
104 struct sysContext_stc {\r
105 tint nmics; /* The actual number of microphones in ths system */\r
106 tint nvmics; /* The acutal number of virtual microphones in the system */\r
107 \r
108 /* heap handles (point to head header) */\r
109 void *heapEP;\r
110 void *heapES;\r
111 void *heapIP;\r
112 void *heapIS;\r
113 \r
114 /* used heap */\r
115 tulong heapEP_used; /* how many used in words */\r
116 tulong heapES_used;\r
117 tulong heapIP_used;\r
118 tulong heapIS_used;\r
119 \r
120 /* Mic input buffer */\r
121 /* This is a dual buffer. Each part has SYS_FRAME_LENGTH*SYS_MICS_MAX samples\r
122 * to accomodate all microphone inputs. The samples are written contiguously\r
123 * without any gaps. Channel after channel.\r
124 */\r
125 void *in_w; /* Mic input buffer being written to */\r
126 void *in_r; /* Mic input buffer being read from */\r
127 void *in_lo; /* Low part of mic input buffer */\r
128 void *in_hi; /* High part of mic input buffer */\r
129 \r
130 linSample *vmicfrm[SYS_VMICS_MAX]; /* Virtual mic frames */\r
131 \r
132 /* Instance pointers */\r
133 void *bfInst_p[SYS_VMICS_MAX]; /* beamformer instance pointers */\r
134 void *asnrInst_p[SYS_VMICS_MAX]; /* ASNR instance pointers */\r
135 void *mssInst_p; /* MSS instance pointer */\r
136 void *vauInst_p; /* VAU instance pointer */\r
137 \r
138 tint vmicangles[SYS_VMICS_MAX]; /* use SYS_BF_ANGLE_xxx from sysbfflt.h */\r
139 \r
140 tbool use_fileio; /* Use file I/O to load microphone files */\r
141 tbool eof; /* End of file reached */\r
142 tbool use_default; /* Use default vmic angles (4,6,8,12 vmics supported only) */\r
143 };\r
144 typedef struct sysContext_stc sysContext_t;\r
145 \r
146 /*======================================================================\r
147 * Global variable declarations\r
148 *======================================================================*/\r
149 \r
150 extern sysContext_t sysContext; /* Defined in sys.c */\r
151 extern tint sysBfVMicAngles[]; /* Defined in sys.c */\r
152 \r
153 /* Buffer descriptor array for memory allocations */\r
154 #define SYS_COMP_MAXBUFS 10\r
155 extern ecomemBuffer_t sysCompBufs[];\r
156 \r
157 /*======================================================================\r
158 * Additional Macros\r
159 *======================================================================*/\r
160 \r
161 /* Misc macros */\r
162 #define SYS_CHECK_ERROR(err) if((err)<0){sysError(err);}\r
163 \r
164 /*======================================================================\r
165 * API Prototypes\r
166 *======================================================================*/\r
167 \r
168 /* sys.c */\r
169 extern int sysCreate(sysConfig_t*); /* Initialize system context */\r
170 extern void sysError(int); /* Printf error code and exit */\r
171 extern int sysHeapAlloc(void*, tint); /* Allocate from appropriate heap */\r
172 extern int sysHeapAllocAll(tint, void*, const void*); /* Allocate ALL buffers */\r
173 extern int sysPrintConfig(tuint); /* Print system configuration */\r
174 \r
175 /* sysbf.c */\r
176 extern void sysBfCreate(void); /* Create all active beamformers */\r
177 \r
178 /* sysasnr.c */\r
179 extern void sysAsnrCreate(void); /* Create all active ASNR's */\r
180 \r
181 /* sysmss.c */\r
182 extern void sysMssCreate(void); /* Create the MSS module */\r
183 \r
184 /* sysvau.c */\r
185 extern void sysVauCreate(void); /* Create the VAU module */\r
186 \r
187 #endif\r
188 /* nothing past this point */\r
189 \r