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