]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/audio-preprocessing.git/blob - file_demo/da830/test/src/vausim.c
Update the GEL file, readme.txt files and directory name change
[processor-sdk/audio-preprocessing.git] / file_demo / da830 / test / src / vausim.c
1 /**\r
2  *  @file   vausim.c\r
3  *  @brief  VAU test\r
4  *  @remarks This test feeds an input speech file to vau and creates one output file \r
5  *           of vau decision and another output speech samples going through the vau.\r
6  *\r
7  *        Copyright (c) 2016 Texas Instruments Incorporated
8  *                                                                                
9  *              All rights reserved not granted herein.                           
10  *                                                                                
11  *                         Limited License.                                       
12  *                                                                                
13  *  Texas Instruments Incorporated grants a world-wide, royalty-free,             
14  *  non-exclusive license under copyrights and patents it now or hereafter owns   
15  *  or controls to make, have made, use, import, offer to sell and sell           
16  *  ("Utilize") this software subject to the terms herein.  With respect to the   
17  *  foregoing patent license, such license is granted solely to the extent that   
18  *  any such patent is necessary to Utilize the software alone.  The patent       
19  *  license shall not apply to any combinations which include this software,      
20  *  other than combinations with devices manufactured by or for TI (\93TI           
21  *  Devices\94).  No hardware patent is licensed hereunder.                         
22  *                                                                                
23  *  Redistributions must preserve existing copyright notices and reproduce this   
24  *  license (including the above copyright notice and the disclaimer and (if      
25  *  applicable) source code license limitations below) in the documentation       
26  *  and/or other materials provided with the distribution                         
27  *                                                                                
28  *  Redistribution and use in binary form, without modification, are permitted    
29  *  provided that the following conditions are met:                               
30  *                                                                                
31  *    *  No reverse engineering, decompilation, or disassembly of this software   
32  *  is permitted with respect to any software provided in binary form.            
33  *                                                                                
34  *    *  any redistribution and use are licensed by TI for use only with TI       
35  *  Devices.                                                                      
36  *                                                                                
37  *    *  Nothing shall obligate TI to provide you with source code for the        
38  *  software licensed and provided to you in object code.                         
39  *                                                                                
40  *  If software source code is provided to you, modification and redistribution   
41  *  of the source code are permitted provided that the following conditions are   
42  *  met:                                                                          
43  *                                                                                
44  *    *  any redistribution and use of the source code, including any resulting   
45  *  derivative works, are licensed by TI for use only with TI Devices.            
46  *                                                                                
47  *    *  any redistribution and use of any object code compiled from the source   
48  *  code and any resulting derivative works, are licensed by TI for use only      
49  *  with TI Devices.                                                              
50  *                                                                                
51  *  Neither the name of Texas Instruments Incorporated nor the names of its       
52  *  suppliers may be used to endorse or promote products derived from this        
53  *  software without specific prior written permission.                           
54  *                                                                                
55  *  DISCLAIMER.                                                                   
56  *                                                                                
57  *  THIS SOFTWARE IS PROVIDED BY TI AND TI\92S LICENSORS "AS IS" AND ANY EXPRESS    
58  *  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED             
59  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        
60  *  DISCLAIMED. IN NO EVENT SHALL TI AND TI\92S LICENSORS BE LIABLE FOR ANY         
61  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    
62  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR            
63  *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER    
64  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT            
65  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY     
66  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   
67  *  DAMAGE.                                                                       \r
68  */\r
69 \r
70 /** @defgroup  VAUTEST */\r
71 \r
72 /** @ingroup VAUTEST */\r
73 /* @{ */\r
74 \r
75 #include <ti/mas/noise-reduction/test/src/bf_asnr_mss_vau.h>\r
76 \r
77 siuInstVau_t siuInstVau;\r
78 \r
79 void siu_open(void)\r
80 {\r
81   memset(&siuInstVau, 0, sizeof(siuInstVau_t));\r
82 \r
83   siu_init_heaps();\r
84 \r
85   if ((siuInstVau.outVauDecisionFilePtr =\r
86     fopen(nmu_SIM_OUTDEC_FNAME, "wt")) == NULL) {\r
87     printf(" Error opening out.raw\n");\r
88     exit(0);\r
89   }\r
90 \r
91 #ifdef DBG\r
92   if ((siuInstVau.vauDbgLogFilePtr =\r
93     fopen(nmu_SIM_LOG_FNAME, "wt")) == NULL) {\r
94     printf(" Error opening log.txt\n");\r
95     exit(0);\r
96   }\r
97 #endif  \r
98 }\r
99 \r
100 void siu_dealloc_vau_xdais_mem (IALG_Fxns *ialgFxnsPtr, IALG_Handle xdaisInstPtr, \r
101                                 tulong *mallocedSizeCounter)\r
102 {\r
103   Int nbufs;\r
104   IALG_MemRec *xdaisBufsPtr;\r
105   \r
106   nbufs = ialgFxnsPtr->algNumAlloc();\r
107   xdaisBufsPtr = (IALG_MemRec *) malloc(nbufs * sizeof(IALG_MemRec));\r
108 \r
109   nbufs = ialgFxnsPtr->algFree(xdaisInstPtr, xdaisBufsPtr);\r
110   \r
111   siu_dealloc_xdais_mem ((tint) nbufs, xdaisBufsPtr, mallocedSizeCounter);\r
112   \r
113   free(xdaisBufsPtr);\r
114 }\r
115 \r
116 void siu_close(void)\r
117 {\r
118   fclose(siuInstVau.outVauDecisionFilePtr);\r
119   \r
120 \r
121 #ifdef DBG\r
122   fclose(siuInstVau.vauDbgLogFilePtr);\r
123 #endif\r
124   \r
125   if (config.xdaisFlag) {\r
126     siu_dealloc_vau_xdais_mem (&vauXdaisCallTable.ialg, siuInstVau.vauXdaisInst,\r
127                            &siuInstVau.xdaisBufsMallocFreeCounter);\r
128     if (siuInstVau.xdaisBufsMallocFreeCounter) {\r
129       printf(" Error: mismatched malloc-free\n");\r
130     }\r
131   }\r
132   \r
133   memset(&siuInstVau, 0, sizeof(siuInstVau_t));\r
134 }\r
135 \r
136 void siu_new_open_config_modules(config_t * config)\r
137 {\r
138   tint      nbufs, ret;\r
139   const ecomemBuffer_t *sizeBufs;\r
140   ecomemBuffer_t ecoBufs[SIU_MAX_MODULE_NBUFS];\r
141   const IALG_Params *paramsPtr;\r
142   IALG_MemRec *xdaisBufsPtr;\r
143 \r
144   vauSizeConfig_t vauSizeCfg;\r
145   vauOpenConfig_t vauOpenCfg;\r
146 \r
147   vauXdaisInitParams_t vauXdaisInitParams;\r
148 \r
149   vauXdaisInitParams.param.size = (Int) sizeof(vauXdaisInitParams_t);\r
150                                                         \r
151   printf("Querying VAU Memory Requirements\n");\r
152 \r
153   vauSizeCfg.max_frame_size = config->frameSize;\r
154   vauSizeCfg.max_sampling_rate_8k_multiple = config->samp_rate_8k_multiple;\r
155   \r
156   if (config->xdaisFlag) {\r
157     nbufs = (tint) vauXdaisCallTable.ialg.algNumAlloc();\r
158     if (nbufs == 0) {\r
159       printf(" algNumAlloc error, exiting\n");\r
160       exit(0);\r
161     }\r
162     \r
163     xdaisBufsPtr = (IALG_MemRec *) malloc(nbufs * sizeof(IALG_MemRec));\r
164     if (xdaisBufsPtr == NULL) {\r
165       printf("Not enough heap for VAU memory records, exiting\n");\r
166       exit(0);    \r
167     }\r
168     if (config->xdaisDefaultCfgFlag) {\r
169       paramsPtr = NULL;\r
170     }\r
171     else {\r
172       /* currently no config supported in vau for alloc, but if introduce in\r
173          future, refer to that configuration */\r
174       paramsPtr = NULL;\r
175     }    \r
176     vauXdaisCallTable.ialg.algAlloc (paramsPtr, NULL, xdaisBufsPtr); \r
177   }\r
178   else {\r
179     if (vauGetSizes(&nbufs, &sizeBufs, &vauSizeCfg) != vau_NOERR) {\r
180       printf(" Vau get sizes error, exiting \n");\r
181       exit(0);\r
182     }\r
183   }\r
184 \r
185   printf("Allocating VAU memory..\n");\r
186   \r
187   if (config->xdaisFlag) {\r
188     siu_alloc_xdais_mem (nbufs, xdaisBufsPtr, &siuInstVau.xdaisBufsMallocFreeCounter);\r
189     siuInstVau.vauXdaisInst = (IALG_Handle) xdaisBufsPtr[0].base;\r
190   }\r
191   else {\r
192     siu_alloc_eco_mem(nbufs, sizeBufs, ecoBufs);\r
193   }  \r
194 \r
195   vauOpenCfg.frame_size = config->frameSize;\r
196   vauOpenCfg.sampling_rate_8k_multiple = config->samp_rate_8k_multiple;\r
197   vauOpenCfg.config = config->vauConfig;\r
198 \r
199   if (config->xdaisFlag) {\r
200     if (config->xdaisDefaultCfgFlag) {\r
201       paramsPtr = NULL;\r
202     }\r
203     else {\r
204       vauXdaisInitParams.cfgOpen = vauOpenCfg;\r
205       paramsPtr = (IALG_Params *) &vauXdaisInitParams;\r
206     }\r
207     ret = vauXdaisCallTable.ialg.algInit(siuInstVau.vauXdaisInst,\r
208                                    xdaisBufsPtr, NULL, paramsPtr); \r
209 \r
210     free(xdaisBufsPtr);\r
211 \r
212     if (ret == IALG_EFAIL) {\r
213       printf("algInit() failure, exiting\n");\r
214       exit(0);\r
215     }\r
216   }\r
217   else {\r
218     if (vauNew(&(siuInstVau.vauInst), nbufs, ecoBufs) != vau_NOERR) {\r
219       printf(" Vau New error, exiting \n");\r
220       exit(0);\r
221     }\r
222     vauOpen(siuInstVau.vauInst, &vauOpenCfg);\r
223   }\r
224   \r
225   if (config->xdaisFlag) {\r
226     vauXdaisCallTable.control (siuInstVau.vauXdaisInst, &(config->vauConfig), &(config->vauControl));\r
227   }\r
228   else {\r
229     vauControl(siuInstVau.vauInst, &(config->vauConfig), &(config->vauControl));\r
230   }  \r
231 }\r
232 \r
233 #ifdef AZ_INFO_AVAILABLE\r
234 extern tint glob_Az[];\r
235 #endif\r
236 \r
237 void siu_process(linSample * framePtr, linSample ** outFramePtr)\r
238 {\r
239   linSample *vauOutSamplesPtr = *outFramePtr;\r
240   ISPHENC1_FrameType vauFrameType;\r
241   tbool     vauAlertFlag = FALSE;\r
242 \r
243 #ifdef USE_CACHE\r
244   if (config.doCacheFlush) {\r
245     memarchcfg_cacheFlush();\r
246   }\r
247 #endif\r
248 \r
249   if (config.xdaisFlag) {\r
250     vauAlertFlag =\r
251     vauXdaisCallTable.process(siuInstVau.vauXdaisInst, framePtr, &vauOutSamplesPtr,\r
252                 &vauFrameType);\r
253   }\r
254   else {\r
255     vauAlertFlag =\r
256     vauProcess(siuInstVau.vauInst, framePtr, &vauOutSamplesPtr,\r
257               &vauFrameType);\r
258   }\r
259 \r
260   /* output when something changes and on first occurrence */\r
261   if ( (siuInstVau.frameCount == 1) || (vauFrameType != siuInstVau.vauFrameTypePrev) ||\r
262        (vauAlertFlag != siuInstVau.vauAlertFlagPrev)) {\r
263 \r
264     fprintf(siuInstVau.outVauDecisionFilePtr, "%ld, %d, %d\n", (long) siuInstVau.frameCount,\r
265             vauFrameType, vauAlertFlag);\r
266     \r
267     switch (vauFrameType) {\r
268       case ISPHENC1_FTYPE_SPEECH:\r
269         printf(" At frame %ld, %s, %s\n", (long) siuInstVau.frameCount, "SPEECH",\r
270                              (vauAlertFlag == TRUE)? "ALERT ON": "ALERT OFF");       \r
271       break;\r
272       \r
273       case ISPHENC1_FTYPE_NODATA:\r
274         if ((siuInstVau.frameCount > 1) && (siuInstVau.vauAlertFlagPrev == FALSE)) {\r
275           printf(" Noise frame arrived without a previous alert flag on SPEECH, exiting");\r
276           exit(0);\r
277         }\r
278         else {\r
279           printf(" At frame %ld, %s\n", (long) siuInstVau.frameCount, "NOISE");\r
280         }  \r
281       break;\r
282       \r
283       default:\r
284         printf(" Invalid Frame Type %d\n detected, exiting", vauFrameType);\r
285         exit(0);\r
286       break;    \r
287     }\r
288 \r
289     siuInstVau.vauFrameTypePrev = vauFrameType;\r
290     siuInstVau.vauAlertFlagPrev = vauAlertFlag;\r
291   }\r
292 \r
293 #ifdef DBG\r
294   fprintf(siuInstVau.vauDbgLogFilePtr, "%ld %ld\n", (long) gVauEnergy, (long) gVauThreshold);\r
295 #endif\r
296 \r
297   *outFramePtr = vauOutSamplesPtr;\r
298 }\r
299 \r
300 void hw_init(void)\r
301 {\r
302 #ifdef PROFILE_CYCLES\r
303   if (!profile_initCycleProfiling()) {\r
304     printf("Could not acquire profiling resources..Exiting\n");\r
305     exit(0);\r
306   }\r
307 #endif\r
308 \r
309 #ifdef USE_CACHE\r
310   if (config.doCacheEnable) {\r
311     memarchcfg_cacheEnable();\r
312   }\r
313 #endif\r
314 }\r
315 \r
316 linSample inFrame[MAX_FRAME_SIZE], outFrame[MAX_FRAME_SIZE];\r
317 \r
318 /* @} */ /* ingroup */\r
319 \r
320 /* Nothing past this point */\r