]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/audio-preprocessing.git/blob - common/components/sys.h
add realtime_demo_bios/k2g for CMB
[processor-sdk/audio-preprocessing.git] / common / components / sys.h
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          7       /* 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_ADC_FS_HZ         48000   /* ADC sampling rate in Hz */\r
51 #define SYS_FS_HZ             16000   /* Sampling rate in Hz */\r
52 #define SYS_FS_RATIO          SYS_ADC_FS_HZ/SYS_FS_HZ   /* Sampling rate ratio */\r
53 #define SYS_FRAME_DURATION_MS 10      /* Frame duration in ms */\r
54 #define SYS_FRAME_LENGTH      (1L*SYS_FS_HZ*SYS_FRAME_DURATION_MS/1000)             /* Frame length in samples */\r
55 #define SYS_FRAME_SIZE        (TYP_LINSAMPLE_SIZE*SYS_FRAME_LENGTH/TYP_TWORD_SIZE)  /* Frame size in bytes */\r
56 #define SYS_IN_LENGTH         (2L*SYS_FRAME_LENGTH*SYS_MICS_MAX)                    /* Input buffer length (dual) */\r
57 #define SYS_IN_SIZE           (TYP_LINSAMPLE_SIZE*SYS_IN_LENGTH/TYP_TWORD_SIZE)     /* # of words in input buffer */\r
58 \r
59 /*======================================================================\r
60  * Bit masks, bit-mask handling macros, error codes\r
61  *======================================================================*/\r
62 \r
63 /* Bit masks for sysPrintConfig */\r
64 #define SYSM_SCOPE_STATIC   0x1     /* Static system information */\r
65 #define SYSM_SCOPE_DYNAMIC  0x2     /* Dynamic system onfirmation */\r
66 \r
67 /* Macros for bit-mask manipulations */\r
68 #define SYS_MASK_GET(value,mask)    ((value)&(mask))\r
69 #define SYS_MASK_SET(value,mask)    ((value)|(mask))\r
70 #define SYS_MASK_TEST(value,mask)   (SYS_MASK_GET(value,mask)!=0)\r
71 \r
72 /* System error codes */\r
73 #define SYS_ERR_SUCCESS       0\r
74 #define SYS_ERR_BADCONFIG     (-1)\r
75 #define SYS_INV_HANDLE        (-2)\r
76 #define SYS_INV_LOGIC         (-3)\r
77 #define SYS_ERR_BUFLENGTH     (-4)\r
78 #define SYS_ERR_FOPEN         (-5)\r
79 #define SYS_ERR_FLOAD         (-6)\r
80 #define SYS_ERR_FMAXBUF       (-7)\r
81 #define SYS_ERR_FREAD         (-8)\r
82 #define SYS_ERR_HEAPINIT      (-9)\r
83 #define SYS_ERR_INVHEAPCLASS  (-10)\r
84 #define SYS_ERR_BFERROR       (-11)\r
85 #define SYS_ERR_EOF           (-12)\r
86 #define SYS_ERR_ASNRERROR     (-13)\r
87 #define SYS_ERR_MSSERROR      (-14)\r
88 #define SYS_ERR_MSSDEBUG      (-15)\r
89 #define SYS_ERR_ANGLECONFIG   (-16)\r
90 #define SYS_ERR_VAUERROR      (-17)\r
91 \r
92 /*======================================================================\r
93  * System Data Types\r
94  *======================================================================*/\r
95 \r
96 /* System Configuration Structure */\r
97 struct sysConfig_stc {\r
98   tint  nmics;        /* The actual number of microphones in ths system */\r
99   tint  nvmics;       /* The acutal number of virtual microphones in the system */\r
100   tbool use_fileio;   /* Use file I/O to load microphone files */\r
101   tbool use_default;  /* Use default angles for virtual microphones */\r
102 };\r
103 typedef struct sysConfig_stc sysConfig_t;\r
104 \r
105 /* System Context Structure */\r
106 struct sysContext_stc {\r
107   tint  nmics;    /* The actual number of microphones in ths system */\r
108   tint  nvmics;   /* The acutal number of virtual microphones in the system */\r
109 \r
110   /* heap handles (point to head header) */\r
111   void *heapEP;\r
112   void *heapES;\r
113   void *heapIP;\r
114   void *heapIS;\r
115 \r
116   /* used heap */\r
117   tulong heapEP_used;     /* how many used in words */\r
118   tulong heapES_used;\r
119   tulong heapIP_used;\r
120   tulong heapIS_used;\r
121 \r
122   /* Mic input buffer */\r
123   /* This is a dual buffer. Each part has SYS_FRAME_LENGTH*SYS_MICS_MAX samples\r
124    * to accomodate all microphone inputs. The samples are written contiguously\r
125    * without any gaps. Channel after channel.\r
126    */\r
127   void *in_w;     /* Mic input buffer being written to */\r
128   void *in_r;     /* Mic input buffer being read from */\r
129   void *in_lo;    /* Low part of mic input buffer */\r
130   void *in_hi;    /* High part of mic input buffer */\r
131 \r
132   linSample *vmicfrm[SYS_VMICS_MAX];  /* Virtual mic frames */\r
133 \r
134   /* Instance pointers */\r
135   void *bfInst_p[SYS_VMICS_MAX];      /* beamformer instance pointers */\r
136   void *asnrInst_p[SYS_VMICS_MAX];    /* ASNR instance pointers */\r
137   void *mssInst_p;                    /* MSS instance pointer */\r
138   void *vauInst_p;                    /* VAU instance pointer */\r
139 \r
140   tint vmicangles[SYS_VMICS_MAX];     /* use SYS_BF_ANGLE_xxx from sysbfflt.h */\r
141 \r
142   tbool use_fileio;   /* Use file I/O to load microphone files */\r
143   tbool eof;          /* End of file reached */\r
144   tbool use_default;  /* Use default vmic angles (4,6,8,12 vmics supported only) */\r
145 };\r
146 typedef struct sysContext_stc  sysContext_t;\r
147 \r
148 /*======================================================================\r
149  * Global variable declarations\r
150  *======================================================================*/\r
151 \r
152 extern sysContext_t sysContext;         /* Defined in sys.c */\r
153 extern tint         sysBfVMicAngles[];  /* Defined in sys.c */\r
154 \r
155 /* Buffer descriptor array for memory allocations */\r
156 #define SYS_COMP_MAXBUFS    10\r
157 extern ecomemBuffer_t sysCompBufs[];\r
158 \r
159 /*======================================================================\r
160  * Additional Macros\r
161  *======================================================================*/\r
162 \r
163 /* Misc macros */\r
164 #define SYS_CHECK_ERROR(err)    if((err)<0){sysError(err);}\r
165 \r
166 /*======================================================================\r
167  * API Prototypes\r
168  *======================================================================*/\r
169 \r
170 /* sys.c */\r
171 extern int  sysCreate(sysConfig_t*);              /* Initialize system context */\r
172 extern void sysError(int);                        /* Printf error code and exit */\r
173 extern int  sysHeapAlloc(void*, tint);            /* Allocate from appropriate heap */\r
174 extern int  sysHeapAllocAll(tint, void*, const void*);  /* Allocate ALL buffers */\r
175 extern int  sysPrintConfig(tuint);                /* Print system configuration */\r
176 \r
177 /* sysbf.c */\r
178 extern void sysBfCreate(void);        /* Create all active beamformers */\r
179 \r
180 /* sysasnr.c */\r
181 extern void sysAsnrCreate(void);      /* Create all active ASNR's */\r
182 \r
183 /* sysmss.c */\r
184 extern void sysMssCreate(void);       /* Create the MSS module */\r
185 \r
186 /* sysvau.c */\r
187 extern void sysVauCreate(void);       /* Create the VAU module */\r
188 \r
189 #endif\r
190 /* nothing past this point */\r
191 \r