b0dffe27a6f2e8c34b43983872514afebef15543
1 /*-----------------------------------------------------------------\r
2 * Filename: bf_asnr_mss_vau.c\r
3 * \r
4 * Description: Demo for the BF, ASNR, MSS and VAU API functions.\r
5 * \r
6 * Copyright (c) 2016 Texas Instruments Incorporated\r
7 * \r
8 * All rights reserved not granted herein. \r
9 * \r
10 * Limited License. \r
11 * \r
12 * Texas Instruments Incorporated grants a world-wide, royalty-free, \r
13 * non-exclusive license under copyrights and patents it now or hereafter owns \r
14 * or controls to make, have made, use, import, offer to sell and sell \r
15 * ("Utilize") this software subject to the terms herein. With respect to the \r
16 * foregoing patent license, such license is granted solely to the extent that \r
17 * any such patent is necessary to Utilize the software alone. The patent \r
18 * license shall not apply to any combinations which include this software, \r
21 * \r
22 * Redistributions must preserve existing copyright notices and reproduce this \r
23 * license (including the above copyright notice and the disclaimer and (if \r
24 * applicable) source code license limitations below) in the documentation \r
25 * and/or other materials provided with the distribution \r
26 * \r
27 * Redistribution and use in binary form, without modification, are permitted \r
28 * provided that the following conditions are met: \r
29 * \r
30 * * No reverse engineering, decompilation, or disassembly of this software \r
31 * is permitted with respect to any software provided in binary form. \r
32 * \r
33 * * any redistribution and use are licensed by TI for use only with TI \r
34 * Devices. \r
35 * \r
36 * * Nothing shall obligate TI to provide you with source code for the \r
37 * software licensed and provided to you in object code. \r
38 * \r
39 * If software source code is provided to you, modification and redistribution \r
40 * of the source code are permitted provided that the following conditions are \r
41 * met: \r
42 * \r
43 * * any redistribution and use of the source code, including any resulting \r
44 * derivative works, are licensed by TI for use only with TI Devices. \r
45 * \r
46 * * any redistribution and use of any object code compiled from the source \r
47 * code and any resulting derivative works, are licensed by TI for use only \r
48 * with TI Devices. \r
49 * \r
50 * Neither the name of Texas Instruments Incorporated nor the names of its \r
51 * suppliers may be used to endorse or promote products derived from this \r
52 * software without specific prior written permission. \r
53 * \r
54 * DISCLAIMER. \r
55 * \r
57 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
58 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
60 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
61 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR \r
62 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER \r
63 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \r
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH \r
66 * DAMAGE. \r
67 *-----------------------------------------------------------------*/\r
68 \r
69 /* ANSI C headers */\r
70 #include <stdlib.h>\r
71 #include <stdio.h>\r
72 #include <string.h>\r
73 \r
74 /* RTSC headers */\r
75 #include <ti/mas/types/types.h>\r
76 #include <ti/mas/fract/fract.h>\r
77 #include <ti/mas/types/const.h>\r
78 #include <ti/mas/util/ecomem.h>\r
79 \r
80 /* for signal generator */\r
81 #include <ti/mas/sdk/sgn.h>\r
82 \r
83 #include <ti/mas/bf_asnr_mss_vau/test/src/bf_asnr_mss_vau.h>\r
84 #include "ti/mas/bf_asnr_mss_vau/test/src/sysbfflt.h"\r
85 #include "ti/mas/bf_asnr_mss_vau/test/src/siubf.h"\r
86 #include "ti/mas/bf_asnr_mss_vau/test/src/siuloc.h"\r
87 #include "ti/mas/bf_asnr_mss_vau/test/src/siuport.h"\r
88 \r
89 #if _VPESIM_C64||_VPESIM_C64_BIG_ENDIAN||_VPESIM_C64P||_VPESIM_C64P_BIG_ENDIAN |_VPESIM_C66||_VPESIM_C66_BIG_ENDIAN\r
90 #include <ti/mas/sdk/memArchCfg.h>\r
91 #endif\r
92 \r
93 /* Global Varibles */\r
94 \r
95 /* Global PCM data buffers */\r
96 linSample sigInBuffer[NUM_BF_VIRTUAL_MIC][vpe_SIM_MAX_SAMPLES];\r
97 linSample sigOutBuffer[vpe_SIM_MAX_SAMPLES];\r
98 linSample sigOutBufferMss[vpe_SIM_MAX_SAMPLES];\r
99 linSample *buf_Inptr[NUM_BF_VIRTUAL_MIC];\r
100 linSample *buf_Outptr;\r
101 linSample *buf_OutptrMss;\r
102 linSample *buf_Outptr2;\r
103 \r
104 /* varibles for BF */\r
105 tint fltIdx[2][16] = {\r
106 {0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 0, 0, 0, 0}, /* 12 virtual mics 30 degree apart */\r
107 {0, 2, 4, 6, 8, 10, 12, 0, 0, 0, 0, 0, 0, 0, 0}, /* 8 virtual mics 45 degree apart */\r
108 };\r
109 void *bfInst[NUM_BF_VIRTUAL_MIC];\r
110 tword bfIntMem[bf_INT_HEAP_SIZE];\r
111 tword bfExtMem[bf_EXT_HEAP_SIZE];\r
112 bfMemHeap_t bfIntHeap;\r
113 bfMemHeap_t bfExtHeap;\r
114 tint num_bufs_req_by_bf;\r
115 const ecomemBuffer_t *bufs_req_by_bf;\r
116 ecomemBuffer_t bufs_aloc_for_bf[MAX_NUM_BF_BUFFS];\r
117 bfNewConfig_t bf_new_cfg;\r
118 linSample bfInFrame[NUM_BF_ANALOG_MIC][vpe_SIM_MAX_SAMPLES];\r
119 linSample *inFramePtr[NUM_BF_ANALOG_MIC];\r
120 #define bf_MIC_INPUT_SAMP_SIZE AUDIO_FILE_IN_SEC*AUDIO_SMAPLE_FREQ\r
121 #define bf_MIC_INPUT_SAMP_PAD AUDIO_SMAPLE_FREQ\r
122 #pragma DATA_SECTION (fileInBufs, ".fileInBufs")\r
123 #pragma DATA_ALIGN(fileInBufs, 8)\r
124 linSample fileInBufs[NUM_BF_ANALOG_MIC][bf_MIC_INPUT_SAMP_SIZE+bf_MIC_INPUT_SAMP_PAD];\r
125 tlong fileInSampleNum = bf_MIC_INPUT_SAMP_SIZE;\r
126 tlong fileInSampleIdx = 0;\r
127 #pragma DATA_SECTION (fileOutBufs, ".fileOutBufs")\r
128 #pragma DATA_ALIGN(fileOutBufs, 8)\r
129 linSample fileOutBufs[bf_MIC_INPUT_SAMP_SIZE+bf_MIC_INPUT_SAMP_PAD];\r
130 tlong fileOutSampleNum = bf_MIC_INPUT_SAMP_SIZE;\r
131 tlong fileOutSampleIdx = 0;\r
132 \r
133 /* varibles for ASNR */\r
134 void *asnrInst[NUM_BF_VIRTUAL_MIC];\r
135 void *nr_handle[NUM_BF_VIRTUAL_MIC];\r
136 linSample vpeIOBufs[vpe_SIM_MAX_SAMPLES];\r
137 vpeSimConfig_t vpeSimC = {\r
138 TRUE, /* bf_on */\r
139 TRUE, /* nr_on */\r
140 TRUE, /* mss_on */\r
141 TRUE, /* vau_on */\r
142 0, /* sample_cnt */\r
143 16000, /* Sampling rate in Hz */\r
144 /* BF size configure parameters */\r
145 {\r
146 bf_SAMP_RATE_16K,\r
147 NUM_BF_ANALOG_MIC,\r
148 SYS_BF_FILTER_LENGTH,\r
149 bf_TYPE_FIXED,\r
150 },\r
151 /* BF control parameters */\r
152 {\r
153 bf_CTL_CONFIG|bf_CTL_MICS, /* Enable BF, operation mode change */\r
154 bf_CTL_CFG_ENABLE|bf_CTL_CFG_OPERATION,\r
155 bf_ENABLE|bf_OPT_NORMAL,\r
156 0x00ff, /* 8 analog mics */\r
157 },\r
158 /* ASNR parameters */\r
159 {\r
160 1, /* Sampling frequency 0: 8Khz; 1: 16Khz */\r
161 5, /* ASNR Signal delay */\r
162 10, /* ASNR Frequency bands boundary bin 1 */\r
163 32, /* ASNR Frequency bands boundary bin 2 */\r
164 9, /* ASNR Maximum attenuation in band 1 */\r
165 9, /* ASNR Maximum attenuation in band 2 */\r
166 9, /* ASNR Maximum attenuation in band 3 */\r
167 31129, /* ASNR Maximum signal update rate */\r
168 29818, /* ASNR Minimum signal update rate */\r
169 -75, /* ASNR Noise threshold */\r
170 150, /* ASNR Noise hangover */\r
171 },\r
172 /* MSS control parameters */\r
173 {\r
174 mss_CTL_SWITCH_THRESH|mss_CTL_SWITCH_DURATION|mss_CTL_SWITCH_HNAGOVER, /* bitfield */\r
175 {0x0003, mss_CTL_MODES_DEFAULT}, /* mode {mask, value} */\r
176 {mss_SRC_MIC_FIXED, 0}, /* source {group, index} */\r
177 250, /* switch thresh */\r
178 500, /* switch duration */\r
179 500, /* switch hangover */\r
180 },\r
181 TRUE, /* Flag indicating more samples for simulation*/\r
182 160, /* Simulation frame size, input */\r
183 160, /* Simulation frame size, output */\r
184 0, /* to measure fixed overhead in cycle measurement */\r
185 {0, 0}, /* BF's cycle statistics */\r
186 {0, 0}, /* ASNR's cycle statistics */\r
187 {0, 0}, /* MSS's cycle statistics */\r
188 {0, 0}, /* VAU's cycle statistics */\r
189 0, /* cycle output file pointer */\r
190 };\r
191 vpeSimConfig_t *vpeSim = &vpeSimC;\r
192 \r
193 /* Allocate memory for NR buffers - size and alignment, for C55x/C6x */\r
194 #pragma DATA_ALIGN (nr_buff0, NR_SIM_BUF0_ALGN)\r
195 tword nr_buff0[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF0_SIZE];\r
196 #pragma DATA_ALIGN (nr_buff1, NR_SIM_BUF1_ALGN)\r
197 tword nr_buff1[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF1_SIZE];\r
198 #pragma DATA_ALIGN (nr_buff2, NR_SIM_BUF2_ALGN)\r
199 tword nr_buff2[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF2_SIZE];\r
200 #pragma DATA_ALIGN (nr_buff3, NR_SIM_BUF3_ALGN)\r
201 tword nr_buff3[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF3_SIZE];\r
202 #pragma DATA_ALIGN (nr_buff4, NR_SIM_BUF4_ALGN)\r
203 tword nr_buff4[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF4_SIZE];\r
204 #pragma DATA_ALIGN (nr_buff5, NR_SIM_BUF5_ALGN)\r
205 tword nr_buff5[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF5_SIZE];\r
206 #pragma DATA_ALIGN (nr_buff6, NR_SIM_BUF6_ALGN)\r
207 tword nr_buff6[NUM_BF_VIRTUAL_MIC][NR_SIM_BUF6_SIZE];\r
208 \r
209 /* varibles for MSS */\r
210 void *mssInst;\r
211 #pragma DATA_ALIGN(mss_buf, 8);\r
212 mssbuf_t mss_buf;\r
213 void *beam_mics[NUM_BF_VIRTUAL_MIC];\r
214 linSample data_rx_sync[vpe_SIM_MAX_SAMPLES]; /* reference signal */\r
215 \r
216 /* varibles for VAU */\r
217 config_t config = {\r
218 0, /* xdaisFlag */\r
219 0, /* don't use default configuration for xdais */\r
220 80, /* 10 ms default frame size at 8 KHz */\r
221 2, /* 8 KHz */\r
222 \r
223 /* vauConfig */\r
224 {\r
225 ifvau_VALID_TYPE | ifvau_VALID_THRESH_OFFSET | ifvau_VALID_HOLD_OVER,\r
226 ifvau_TYPE_ADAPTIVE,\r
227 0,\r
228 180},\r
229 \r
230 /* vauControl */\r
231 {\r
232 ifvau_VALID_CONTROL,\r
233 ifvau_ENABLE\r
234 }\r
235 #ifdef USE_CACHE\r
236 ,1, /* doCacheFlush */\r
237 1 /* doCacheEnable */\r
238 #endif\r
239 };\r
240 \r
241 tint siu_alloc_bf_buffs(const ecomemBuffer_t *bufs_req, ecomemBuffer_t *bufs_aloc,\r
242 tint num_bufs);\r
243 \r
244 /* Global simulation data */\r
245 char vpe_sim_global_str[vpe_SIM_MAX_STRING];\r
246 char vpe_sim_print_str[vpe_SIM_MAX_STRING];\r
247 \r
248 /*-----------------------------------------------------------------\r
249 * Function: vpe_print\r
250 *\r
251 * Description: Utility to provide static progress information.\r
252 *-----------------------------------------------------------------*/\r
253 void vpe_print (char *str)\r
254 {\r
255 printf (str);\r
256 }\r
257 \r
258 /*-----------------------------------------------------------------\r
259 * Function: vpe_iprint\r
260 *\r
261 * Description: Utility to provide integer progress information.\r
262 *-----------------------------------------------------------------*/\r
263 void vpe_iprint (char *str, tlong ivar)\r
264 {\r
265 sprintf (vpe_sim_print_str, str, ivar);\r
266 vpe_print (vpe_sim_print_str);\r
267 }\r
268 \r
269 /*-----------------------------------------------------------------\r
270 * Function: vpe_halt\r
271 *\r
272 * Description: Utility to provide simulation breakpoint.\r
273 *-----------------------------------------------------------------*/\r
274 void vpe_halt (tbool *exec)\r
275 {\r
276 /* Wait for further actions - exit when user sets "halt" to FALSE */\r
277 while (!(*exec)) {\r
278 asm (" NOP");\r
279 asm ("Set_BP_Here: ");\r
280 asm (" NOP");\r
281 asm (" NOP");\r
282 }\r
283 }\r
284 \r
285 void vpe_sim_flush_cache() {\r
286 #if _VPESIM_C64||_VPESIM_C64_BIG_ENDIAN||_VPESIM_C64P||_VPESIM_C64P_BIG_ENDIAN |_VPESIM_C66||_VPESIM_C66_BIG_ENDIAN\r
287 /* flush cache */\r
288 memarchcfg_cacheFlush();\r
289 #endif\r
290 }\r
291 \r
292 /*-----------------------------------------------------------------\r
293 * Function: vpe_banner_print\r
294 * \r
295 * Description: Utility to provide major progress information.\r
296 *-----------------------------------------------------------------*/\r
297 static inline void vpe_banner_print (char *str)\r
298 {\r
299 vpe_print ("\n");\r
300 vpe_print ("------------------------------\n");\r
301 vpe_print (str);\r
302 vpe_print ("------------------------------\n");\r
303 vpe_print ("\n");\r
304 }\r
305 \r
306 void siu_print_buff_usage(const ecomemBuffer_t *bufs, tint num_bufs)\r
307 {\r
308 int i;\r
309 \r
310 printf(" Buffer Size(twords) Alignment Volatile address\n");\r
311 for(i=0; i<num_bufs; i++) {\r
312 printf(" %3d %7d %4d ",\r
313 i, (int)bufs[i].size, (int)bufs[i].log2align);\r
314 if(bufs[i].volat)\r
315 printf(" yes");\r
316 else\r
317 printf(" no ");\r
318 \r
319 printf(" 0x%x\n", bufs[i].base);\r
320 }\r
321 }\r
322 \r
323 void siu_print_cycles(void)\r
324 {\r
325 siu_print_cycles_util(&vpeSim->cyclesBf, "BF", vpeSim->cyclesOverhead);\r
326 siu_print_cycles_util(&vpeSim->cyclesAsnr, "ASNR", vpeSim->cyclesOverhead);\r
327 siu_print_cycles_util(&vpeSim->cyclesMss, "MSS", vpeSim->cyclesOverhead);\r
328 siu_print_cycles_util(&vpeSim->cyclesVau, "VAU", vpeSim->cyclesOverhead);\r
329 }\r
330 \r
331 /******************************************************************************\r
332 * FUNCTION PURPOSE: Init heap memory.\r
333 ******************************************************************************\r
334 * DESCRIPTION:\r
335 *\r
336 * void bf_mem_heap_init (\r
337 * bfMemHeap_t *ptr,\r
338 * tword *heapBase,\r
339 * tulong size) - channel number (1 to SIU_MAX_CHANNELS)\r
340 *\r
341 *****************************************************************************/\r
342 \r
343 void bf_mem_heap_init (bfMemHeap_t *ptr, tword *heapBase, tulong size)\r
344 {\r
345 ptr->base = heapBase;\r
346 ptr->size = size;\r
347 ptr->indx = 0;\r
348 /* Note : memory is not initialized deliberately to expose\r
349 uninitialized memory read problems */\r
350 }\r
351 \r
352 void bf_mem_init_heap (void)\r
353 {\r
354 /* Internal heap */\r
355 bf_mem_heap_init (&bfIntHeap, bfIntMem, bf_INT_HEAP_SIZE);\r
356 /* External heap */\r
357 bf_mem_heap_init (&bfExtHeap, bfExtMem, bf_EXT_HEAP_SIZE);\r
358 }\r
359 \r
360 /******************************************************************************\r
361 * FUNCTION PURPOSE: align memory\r
362 ******************************************************************************\r
363 * DESCRIPTION:\r
364 *\r
365 * void *bf_mem_align (\r
366 * void *addr,\r
367 * tuint lin_align) - channel number (1 to SIU_MAX_CHANNELS)\r
368 *\r
369 *****************************************************************************/\r
370 \r
371 void *bf_mem_align (void *addr, tuint lin_align)\r
372 {\r
373 tulong align_addr;\r
374 \r
375 align_addr = ((tulong) addr + lin_align - 1UL) & (0xFFFFFFFFUL - lin_align + 1UL);\r
376 return ((void *) align_addr);\r
377 }\r
378 \r
379 /******************************************************************************\r
380 * FUNCTION PURPOSE: allocate heap memory\r
381 ******************************************************************************\r
382 * DESCRIPTION:\r
383 *\r
384 * tword *bf_mem_heap_alloc (\r
385 * bfMemHeap_t *ptr,\r
386 * tint size) - channel number (1 to SIU_MAX_CHANNELS)\r
387 *\r
388 *****************************************************************************/\r
389 \r
390 tword *bf_mem_heap_alloc (bfMemHeap_t *ptr, tint size)\r
391 {\r
392 tword *alloc = NULL;\r
393 \r
394 if ((ptr->indx + size) <= ptr->size) {\r
395 alloc = &ptr->base[ptr->indx];\r
396 ptr->indx += size;\r
397 }\r
398 return (alloc);\r
399 }\r
400 \r
401 void *bf_mem_alloc_align (tint size, tint mclass, tint linAlign)\r
402 {\r
403 void *allocPtr;\r
404 bfMemHeap_t *ptr;\r
405 \r
406 if (mclass == ecomem_CLASS_INTERNAL) {\r
407 ptr = &bfIntHeap;\r
408 }\r
409 else if (mclass == ecomem_CLASS_EXTERNAL) {\r
410 ptr = &bfExtHeap;\r
411 }\r
412 else {\r
413 printf("Unrecognized memory class, exiting\n");\r
414 exit (0);\r
415 }\r
416 \r
417 if ((allocPtr = (void *) bf_mem_heap_alloc (ptr, size + linAlign - 1)) == NULL) {\r
418 printf("Not enough heap, exiting\n");\r
419 exit (0);\r
420 }\r
421 \r
422 return (bf_mem_align (allocPtr, linAlign));\r
423 }\r
424 \r
425 /******************************************************************************\r
426 * FUNCTION PURPOSE: Allocate buffers for bf instance\r
427 *\r
428 *****************************************************************************/\r
429 tint siu_alloc_bf_buffs(const ecomemBuffer_t *bufs_req, ecomemBuffer_t *bufs_aloc,\r
430 tint num_bufs)\r
431 {\r
432 tint err_code;\r
433 tint i;\r
434 tuint linAlign, log2align;\r
435 \r
436 err_code = bf_NOERR;\r
437 for (i = 0; i < num_bufs; i++) {\r
438 log2align = bufs_req[i].log2align;\r
439 linAlign = (tuint) 1 << log2align;\r
440 \r
441 bufs_aloc[i].mclass = bufs_req[i].mclass; /* internal memory for all */\r
442 bufs_aloc[i].log2align = bufs_req[i].log2align;/* meet alignment requirement */\r
443 bufs_aloc[i].volat = FALSE; /* initialized to permanent */\r
444 bufs_aloc[i].size = bufs_req[i].size; /* size of the buffer */\r
445 bufs_aloc[i].base = bf_mem_alloc_align (bufs_aloc[i].size, bufs_aloc[i].mclass, linAlign);\r
446 }\r
447 \r
448 bufs_aloc[3].volat = TRUE; /* initialized to permanent */\r
449 bufs_aloc[4].volat = TRUE; /* initialized to permanent */\r
450 \r
451 return(err_code);\r
452 } /* siu_alloc_bf_buffs */\r
453 \r
454 Fract spchLevdB = frct_MAX, noiseLevdB = frct_MAX;\r
455 UFract Nthresh = frct_MAX;\r
456 \r
457 tbool bf_getNextFrame(void *framePtr[], tint num_tuint_in)\r
458 {\r
459 tint i, j;\r
460 linSample *tempFramePtr;\r
461 tuint temp;\r
462 \r
463 /* do we have enough samples */\r
464 if (fileInSampleNum<(fileInSampleIdx+num_tuint_in))\r
465 return FALSE;\r
466 \r
467 /* read one frame from each mic */\r
468 for (i=0; i<NUM_BF_ANALOG_MIC; i++)\r
469 {\r
470 tempFramePtr = (linSample *)framePtr[i];\r
471 for (j=0; j<num_tuint_in; j++)\r
472 {\r
473 temp = fileInBufs[i][fileInSampleIdx+j];\r
474 *(tempFramePtr+j) = (((temp&0xFF00)>>8)|((temp&0x00FF)<<8));\r
475 }\r
476 }\r
477 fileInSampleIdx += num_tuint_in;\r
478 return TRUE;\r
479 }\r
480 \r
481 tbool bf_putNextFrame(void *framePtr, tint num_tuint_in)\r
482 {\r
483 tint j;\r
484 linSample *tempFramePtr;\r
485 tuint temp;\r
486 \r
487 /* do we have enough samples */\r
488 if (fileOutSampleNum<(fileOutSampleIdx+num_tuint_in))\r
489 return FALSE;\r
490 \r
491 /* write one frame */\r
492 tempFramePtr = (linSample *)framePtr;\r
493 for (j=0; j<num_tuint_in; j++)\r
494 {\r
495 temp = *(tempFramePtr+j);\r
496 fileOutBufs[fileOutSampleIdx+j] = (((temp&0xFF00)>>8)|((temp&0x00FF)<<8));\r
497 }\r
498 fileOutSampleIdx += num_tuint_in;\r
499 return TRUE;\r
500 }\r
501 \r
502 void bf_init(void)\r
503 {\r
504 tint i;\r
505 \r
506 /* frame buffer and pointers init */\r
507 for (i=0; i<NUM_BF_ANALOG_MIC; i++)\r
508 {\r
509 inFramePtr[i] = bfInFrame[i];\r
510 }\r
511 \r
512 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
513 {\r
514 buf_Inptr[i] = (linSample *)sigInBuffer[i];\r
515 }\r
516 buf_Outptr = (linSample *)sigOutBuffer;\r
517 buf_OutptrMss = (linSample *)sigOutBufferMss;\r
518 \r
519 bf_mem_init_heap();\r
520 }\r
521 \r
522 void bf_setup(tint virMicNum)\r
523 {\r
524 tint i, err_code;\r
525 bfConfig_t bfCfg;\r
526 Fract *filterPtr;\r
527 \r
528 /* Get buffer size for BF */\r
529 err_code = bfGetSizes(&num_bufs_req_by_bf, &bufs_req_by_bf, &vpeSim->bf_size_cfg);\r
530 if (err_code != bf_NOERR) {\r
531 printf("Error when calling bfGetSizes() with error code %d!\n", err_code);\r
532 exit(1);\r
533 }\r
534 \r
535 printf("bf required buffers:\n");\r
536 siu_print_buff_usage(bufs_req_by_bf, num_bufs_req_by_bf);\r
537 \r
538 /* Check if there is enough memory allocated for bf */\r
539 if (num_bufs_req_by_bf > MAX_NUM_BF_BUFFS) {\r
540 printf("Memory allocated by SIU is not enough for bf!\n");\r
541 exit(0);\r
542 }\r
543 \r
544 /* Provide memory to bf through bfNew() */\r
545 err_code = siu_alloc_bf_buffs(bufs_req_by_bf, bufs_aloc_for_bf,\r
546 num_bufs_req_by_bf);\r
547 if (err_code != bf_NOERR) {\r
548 printf("Error when allocating buffers for bf with error code %d!\n", err_code);\r
549 exit(1);\r
550 }\r
551 printf("Buffers allocated by SIU for bf:\n");\r
552 siu_print_buff_usage(bufs_aloc_for_bf, num_bufs_req_by_bf);\r
553 \r
554 /* Set up configurations for bfNew() */\r
555 bf_new_cfg.handle = (void *) siuMakeID(SIU_MID_BF, virMicNum);\r
556 bf_new_cfg.sizeCfg = vpeSim->bf_size_cfg;\r
557 \r
558 /* Create a new BF instance */\r
559 err_code = bfNew (&bfInst[virMicNum], num_bufs_req_by_bf, bufs_aloc_for_bf, &bf_new_cfg);\r
560 if (err_code != bf_NOERR) {\r
561 printf("Error when calling bfNew() with error code %d!\n", err_code);\r
562 exit(1);\r
563 }\r
564 \r
565 /* Open the BF instance */\r
566 bfCfg.sampling_rate = vpeSim->bf_size_cfg.max_sampling_rate;\r
567 bfCfg.num_mics = vpeSim->bf_size_cfg.max_num_mics;\r
568 \r
569 /* Call bf API to open the bf instance */\r
570 err_code = bfOpen (bfInst[virMicNum], &bfCfg);\r
571 if (err_code != bf_NOERR) {\r
572 printf("Error when calling bfOpen()with error code %d!\n", err_code);\r
573 exit(1);\r
574 }\r
575 \r
576 /* Put in filter coefficients for BF */\r
577 if (bfCfg.num_mics==12)\r
578 {\r
579 filterPtr = sysBfFilters[fltIdx[0][virMicNum]];\r
580 } else if (bfCfg.num_mics==8)\r
581 {\r
582 filterPtr = sysBfFilters[fltIdx[1][virMicNum]];\r
583 } else\r
584 {\r
585 printf("Error incorrect virtual mics(%d)!\n", bfCfg.num_mics);\r
586 exit(1);\r
587 }\r
588 \r
589 for (i=0; i<bfCfg.num_mics; i++)\r
590 {\r
591 bfPutFilter(bfInst[virMicNum], &filterPtr[SYS_BF_FILTER_LENGTH*i], bf_FG_BF, i, SYS_BF_FILTER_LENGTH);\r
592 }\r
593 \r
594 /* Enable the BF instance */\r
595 err_code = bfControl(bfInst[virMicNum], &vpeSim->bf_ctl);\r
596 if (err_code != bf_NOERR) {\r
597 printf("Error when configure BF with error code %d!\n", err_code);\r
598 exit(1);\r
599 }\r
600 }\r
601 \r
602 void bf_closedown(tint virMicNum)\r
603 {\r
604 tint err_code,i;\r
605 ecomemBuffer_t bufs[MAX_NUM_BF_BUFFS];\r
606 \r
607 /* Close the BF instance */\r
608 err_code = bfClose(bfInst[virMicNum]); /* the instance state is set to bf_CLOSED */\r
609 if (err_code != bf_NOERR) {\r
610 printf("Error when calling bfClose() with error code %d!\n", err_code);\r
611 exit(1);\r
612 }\r
613 \r
614 err_code = bfDelete (&bfInst[virMicNum], MAX_NUM_BF_BUFFS, bufs);\r
615 if (err_code != bf_NOERR) {\r
616 printf("Error when calling bfDelete() with error code %d!\n", err_code);\r
617 exit(1);\r
618 }\r
619 \r
620 for(i=0;i<MAX_NUM_BF_BUFFS;i++)\r
621 {\r
622 free(bufs[i].base);\r
623 }\r
624 }\r
625 \r
626 void asnr_setup(tint virMicNum)\r
627 {\r
628 const ecomemBuffer_t *bufs_req_by_nr;\r
629 ecomemBuffer_t bufs_alloc_for_nr[VPE_NR_NUM_BUFS];\r
630 asnrSizeConfig_t nr_size_cfg;\r
631 asnrNewConfig_t nr_new_cfg;\r
632 asnrOpenConfig_t nr_open_cfg;\r
633 tint num_bufs_req_by_nr, status;\r
634 int i;\r
635 tint srate;\r
636 asnrControl_t nr_control_cfg;\r
637 \r
638 if (vpeSim->Fs == VPE_SIM_SAMPLE_FREQ_8000) {\r
639 srate = asnr_SRATE_8K;\r
640 }\r
641 else {\r
642 srate = asnr_SRATE_16K;\r
643 }\r
644 \r
645 /* Get NR memory buffer requirements */\r
646 nr_size_cfg.max_sampling_rate=srate;\r
647 status = asnrGetSizes(&num_bufs_req_by_nr, &bufs_req_by_nr, &nr_size_cfg);\r
648 if(status != asnr_NOERR) {\r
649 printf("Error returned by asnrGetSizes() = %d\n",status);\r
650 exit(0);\r
651 }\r
652 \r
653 if(num_bufs_req_by_nr != VPE_NR_NUM_BUFS) {\r
654 printf("NR needs %d buffers, but %d buffers are allocated!\n",\r
655 num_bufs_req_by_nr, VPE_NR_NUM_BUFS);\r
656 exit(0);\r
657 }\r
658 \r
659 printf("Buffers requested by NR:\n");\r
660 printf(" Buffer Size(twords) Alignment Volatile\n");\r
661 for(i=0; i<num_bufs_req_by_nr; i++) {\r
662 printf(" %3d %7d %4d ",\r
663 i, (int)bufs_req_by_nr[i].size, (int)bufs_req_by_nr[i].log2align);\r
664 if(bufs_req_by_nr[i].volat)\r
665 printf(" yes\n");\r
666 else\r
667 printf(" no \n");\r
668 }\r
669 \r
670 /* Statically allocate buffers for NR */\r
671 for (i=0; i<num_bufs_req_by_nr; i++) {\r
672 bufs_alloc_for_nr[i].mclass = ecomem_CLASS_INTERNAL;\r
673 bufs_alloc_for_nr[i].volat = FALSE; /* initialized to permanent */\r
674 }\r
675 bufs_alloc_for_nr[0].base = &nr_buff0[virMicNum][0];\r
676 bufs_alloc_for_nr[0].size = NR_SIM_BUF0_SIZE;\r
677 bufs_alloc_for_nr[0].log2align = NR_SIM_BUF0_ALGN_LOG2;\r
678 \r
679 bufs_alloc_for_nr[1].base = &nr_buff1[virMicNum][0];\r
680 bufs_alloc_for_nr[1].size = NR_SIM_BUF1_SIZE;\r
681 bufs_alloc_for_nr[1].log2align = NR_SIM_BUF1_ALGN_LOG2;\r
682 bufs_alloc_for_nr[1].volat = TRUE;\r
683 \r
684 bufs_alloc_for_nr[2].base = &nr_buff2[virMicNum][0];\r
685 bufs_alloc_for_nr[2].size = NR_SIM_BUF2_SIZE;\r
686 bufs_alloc_for_nr[2].log2align = NR_SIM_BUF2_ALGN_LOG2;\r
687 bufs_alloc_for_nr[2].volat = TRUE;\r
688 \r
689 bufs_alloc_for_nr[3].base = &nr_buff3[virMicNum][0];\r
690 bufs_alloc_for_nr[3].size = NR_SIM_BUF3_SIZE;\r
691 bufs_alloc_for_nr[3].log2align = NR_SIM_BUF3_ALGN_LOG2;\r
692 bufs_alloc_for_nr[3].volat = TRUE;\r
693 \r
694 bufs_alloc_for_nr[4].base = &nr_buff4[virMicNum][0];\r
695 bufs_alloc_for_nr[4].size = NR_SIM_BUF4_SIZE;\r
696 bufs_alloc_for_nr[4].log2align = NR_SIM_BUF4_ALGN_LOG2;\r
697 \r
698 bufs_alloc_for_nr[5].base = &nr_buff5[virMicNum][0];\r
699 bufs_alloc_for_nr[5].size = NR_SIM_BUF5_SIZE;\r
700 bufs_alloc_for_nr[5].log2align = NR_SIM_BUF5_ALGN_LOG2;\r
701 \r
702 bufs_alloc_for_nr[6].base = &nr_buff6[virMicNum][0];\r
703 bufs_alloc_for_nr[6].size = NR_SIM_BUF6_SIZE;\r
704 bufs_alloc_for_nr[6].log2align = NR_SIM_BUF6_ALGN_LOG2;\r
705 \r
706 /* Create NR instance */\r
707 nr_new_cfg.handle = &nr_handle[virMicNum];\r
708 nr_new_cfg.sizeCfg = nr_size_cfg;\r
709 status = asnrNew(&asnrInst[virMicNum], num_bufs_req_by_nr, bufs_alloc_for_nr, &nr_new_cfg);\r
710 if (status != asnr_NOERR) {\r
711 printf("Error returned by asnrNew() = %d\n",status);\r
712 exit(0);\r
713 }\r
714 \r
715 printf("Buffers allocated for NR:\n");\r
716 printf(" Buffer Size(twords) Alignment Volatile address\n");\r
717 for(i=0; i<num_bufs_req_by_nr; i++) {\r
718 printf(" %3d %7d %4d ",\r
719 i, (int)bufs_alloc_for_nr[i].size, (int)bufs_alloc_for_nr[i].log2align);\r
720 if(bufs_alloc_for_nr[i].volat)\r
721 printf(" yes ");\r
722 else\r
723 printf(" no ");\r
724 \r
725 printf(" 0x%x\n", bufs_alloc_for_nr[i].base);\r
726 }\r
727 \r
728 /* Open newly created NR instance */\r
729 nr_open_cfg.sampling_rate = srate;\r
730 status = asnrOpen(asnrInst[virMicNum], &nr_open_cfg);\r
731 if (status != asnr_NOERR) {\r
732 printf("Error returned by asnrOpen() = %d!\n", status);\r
733 exit(0);\r
734 }\r
735 \r
736 /* Configure NR parameters */\r
737 nr_control_cfg.valid_bitfield = asnr_CTL_VALID_ENABLE\r
738 | asnr_CTL_VALID_SAMP_RATE\r
739 | asnr_CTL_VALID_DELAY\r
740 | asnr_CTL_VALID_BAND_BIN1\r
741 | asnr_CTL_VALID_BAND_BIN2\r
742 | asnr_CTL_VALID_BAND1_MAX_ATTEN\r
743 | asnr_CTL_VALID_BAND2_MAX_ATTEN\r
744 | asnr_CTL_VALID_BAND3_MAX_ATTEN\r
745 | asnr_CTL_VALID_SIG_UPD_RATE_MIN\r
746 | asnr_CTL_VALID_SIG_UPD_RATE_MAX\r
747 | asnr_CTL_VALID_NOISE_THRESH\r
748 | asnr_CTL_VALID_NOISE_HANGOVER;\r
749 nr_control_cfg.enable = 1;\r
750 nr_control_cfg.samp_rate = vpeSim->asnrParam.samp_rate;\r
751 nr_control_cfg.delay = vpeSim->asnrParam.delay;\r
752 nr_control_cfg.band_bin1 = vpeSim->asnrParam.band_bin1;\r
753 nr_control_cfg.band_bin2 = vpeSim->asnrParam.band_bin2;\r
754 nr_control_cfg.band1_max_atten = vpeSim->asnrParam.band1_max_atten;\r
755 nr_control_cfg.band2_max_atten = vpeSim->asnrParam.band2_max_atten;\r
756 nr_control_cfg.band3_max_atten = vpeSim->asnrParam.band3_max_atten;\r
757 nr_control_cfg.sig_upd_rate_max= vpeSim->asnrParam.sig_upd_rate_max;\r
758 nr_control_cfg.sig_upd_rate_min= vpeSim->asnrParam.sig_upd_rate_min;\r
759 nr_control_cfg.noise_thresh = vpeSim->asnrParam.noise_thresh;\r
760 nr_control_cfg.noise_hangover = vpeSim->asnrParam.noise_hangover;\r
761 \r
762 status = asnrControl(asnrInst[virMicNum], &nr_control_cfg);\r
763 if (status != asnr_NOERR) {\r
764 printf("Error returned by asnrControl = %d!\n", status);\r
765 exit(0);\r
766 }\r
767 }\r
768 \r
769 void asnr_closedown(tint virMicNum)\r
770 {\r
771 ecomemBuffer_t bufs_returned_by_nr[VPE_NR_NUM_BUFS];\r
772 tint status, error;\r
773 \r
774 status = asnrClose(asnrInst[virMicNum]);\r
775 if(status != asnr_NOERR) {\r
776 printf("Error returned by asnrClose() = %d!\n", status);\r
777 exit(0);\r
778 }\r
779 \r
780 status = asnrDelete(&asnrInst[virMicNum], VPE_NR_NUM_BUFS, bufs_returned_by_nr);\r
781 if(status != asnr_NOERR) {\r
782 printf("Error returned by asnrDelete() = %d!\n", status);\r
783 exit(0);\r
784 }\r
785 \r
786 error = (bufs_returned_by_nr[0].base != nr_buff0[virMicNum])\r
787 | (bufs_returned_by_nr[1].base != nr_buff1[virMicNum])\r
788 | (bufs_returned_by_nr[2].base != nr_buff2[virMicNum])\r
789 | (bufs_returned_by_nr[3].base != nr_buff3[virMicNum])\r
790 | (bufs_returned_by_nr[4].base != nr_buff4[virMicNum])\r
791 | (bufs_returned_by_nr[5].base != nr_buff5[virMicNum]);\r
792 /// | (bufs_returned_by_nr[6].base != nr_buff6[virMicNum]);\r
793 if(error) {\r
794 printf("Buffers returned by asnrDelete() are wrong!\n");\r
795 exit(0);\r
796 }\r
797 }\r
798 \r
799 void mss_setup(void)\r
800 {\r
801 const ecomemBuffer_t *bufs_req_by_mss;\r
802 ecomemBuffer_t bufs_aloc_by_siu[SIU_NUM_MSS_BUFFS];\r
803 mssSizeConfig_t mss_size_cfg;\r
804 mssNewConfig_t mss_new_cfg;\r
805 tint err_code, num_bufs_req_by_mss;\r
806 mssControl_t mss_ctl_cfg;\r
807 mssConfig_t mss_open_cfg;\r
808 \r
809 /* Set up configurations for mssGetSizes() */\r
810 mss_size_cfg.max_sampling_rate = mss_SAMP_RATE_16K;\r
811 mss_size_cfg.max_num_mic_fixed = NUM_BF_VIRTUAL_MIC;\r
812 mss_size_cfg.max_num_mic_remote = 0;\r
813 mss_size_cfg.max_num_mic_clean = 0;\r
814 mss_size_cfg.max_num_beam = 0;\r
815 \r
816 /* Call API function mssGetSizes() to get memory requirements:\r
817 - num_bufs_req_by_mss: number of buffers required by MSS\r
818 - bufs_req_by_mss: pointer to buffer descriptors defined inside MSS */\r
819 err_code = mssGetSizes(&num_bufs_req_by_mss, &bufs_req_by_mss, &mss_size_cfg);\r
820 \r
821 printf("MSS required buffers:\n");\r
822 siu_print_buff_usage(bufs_req_by_mss, num_bufs_req_by_mss);\r
823 \r
824 /* Check if there is enough memory allocated for MSS */\r
825 if( num_bufs_req_by_mss > SIU_NUM_MSS_BUFFS\r
826 || bufs_req_by_mss[0].size > sizeof(mssbuf_t)) {\r
827 printf("Memory allocated by SIU is not enough for MSS!\n");\r
828 exit(0);\r
829 }\r
830 \r
831 /* Provide memory to MSS through mssNew() */\r
832 bufs_aloc_by_siu[0].mclass = ecomem_CLASS_INTERNAL;\r
833 bufs_aloc_by_siu[0].log2align = bufs_req_by_mss[0].log2align;\r
834 bufs_aloc_by_siu[0].volat = FALSE;\r
835 bufs_aloc_by_siu[0].size = sizeof(mssbuf_t);\r
836 bufs_aloc_by_siu[0].base = &mss_buf;\r
837 \r
838 printf("Buffers allocated by SIU for MSS:\n");\r
839 siu_print_buff_usage(bufs_aloc_by_siu, num_bufs_req_by_mss);\r
840 \r
841 /* Set up configurations for mssNew() */\r
842 mss_new_cfg.handle = (void *) siuMakeID(SIU_MID_MSS, 0);\r
843 mss_new_cfg.sizeCfg = mss_size_cfg;\r
844 \r
845 /* Call API function mssNew() to create an MSS instance:\r
846 - pass buffer descriptors that are set by SIU\r
847 - pass number of buffer descriptors */\r
848 err_code = mssNew (&mssInst, num_bufs_req_by_mss, bufs_aloc_by_siu, &mss_new_cfg);\r
849 if (err_code != mss_NOERR) {\r
850 printf("Error when calling mssNew() with error code %d!\n", err_code);\r
851 exit(1);\r
852 }\r
853 \r
854 /* Set up configuration for mssOpen() */\r
855 mss_open_cfg.sampling_rate = (vpeSim->asnrParam.samp_rate==1) ? mss_SAMP_RATE_16K : mss_SAMP_RATE_8K;\r
856 mss_open_cfg.num_mic_fixed = NUM_BF_VIRTUAL_MIC;\r
857 mss_open_cfg.num_mic_remote = 0;\r
858 mss_open_cfg.num_mic_clean = 0;\r
859 mss_open_cfg.num_mic_array = 0;\r
860 mss_open_cfg.num_beam = 0;\r
861 \r
862 err_code = mssOpen (mssInst, &mss_open_cfg);\r
863 if (err_code != mss_NOERR) {\r
864 printf("Error when calling mssOpen() with error code %d!\n", err_code);\r
865 exit(1);\r
866 }\r
867 \r
868 /* Set 1st hands-free mic as the selected source for MSS */\r
869 mss_ctl_cfg.valid_bitfield = mss_CTL_SELECT_SRC;\r
870 mss_ctl_cfg.source.group = vpeSim->mss_ctl_cfg.source.group;\r
871 mss_ctl_cfg.source.index = vpeSim->mss_ctl_cfg.source.index;\r
872 err_code = mssControl (mssInst, &mss_ctl_cfg);\r
873 \r
874 mss_ctl_cfg.valid_bitfield = vpeSim->mss_ctl_cfg.valid_bitfield;\r
875 \r
876 mss_ctl_cfg.switch_thresh = vpeSim->mss_ctl_cfg.switch_thresh;\r
877 mss_ctl_cfg.switch_duration = vpeSim->mss_ctl_cfg.switch_duration;\r
878 mss_ctl_cfg.switch_hangover = vpeSim->mss_ctl_cfg.switch_hangover;\r
879 err_code = mssControl (mssInst, &mss_ctl_cfg);\r
880 \r
881 if (err_code != mss_NOERR) {\r
882 printf("Error when calling mssControl() to configure MSS with error code %d!\n",\r
883 err_code);\r
884 exit(1);\r
885 }\r
886 }\r
887 \r
888 void mss_closedown(void)\r
889 {\r
890 ecomemBuffer_t bufs_returned_by_siu[SIU_NUM_MSS_BUFFS];\r
891 tint err_code, error;\r
892 \r
893 err_code = mssClose(mssInst);\r
894 if (err_code != mss_NOERR) {\r
895 printf("Error when calling mssClose() with error code %d!\n", err_code);\r
896 exit(1);\r
897 }\r
898 \r
899 err_code = mssDelete(&mssInst, SIU_NUM_MSS_BUFFS, bufs_returned_by_siu);\r
900 if (err_code != mss_NOERR) {\r
901 printf("Error when calling mssDelete() with error code %d!\n", err_code);\r
902 exit(1);\r
903 }\r
904 \r
905 error = (bufs_returned_by_siu[0].base != &mss_buf);\r
906 if(error) {\r
907 printf("Buffers returned by mssDelete() are wrong!\n");\r
908 exit(0);\r
909 }\r
910 }\r
911 \r
912 void vau_setup(void)\r
913 {\r
914 /* print the VAU version */\r
915 printf("Version Information of modules tested:\n");\r
916 printf("VAU %d.%d.%d.%d\n",\r
917 ti_mas_vau_Version_MAJOR, ti_mas_vau_Version_MINOR,\r
918 ti_mas_vau_Version_XVERTICAL, ti_mas_vau_Version_PATCH);\r
919 \r
920 /* print XDAIS or ECO */\r
921 if (config.xdaisFlag) {\r
922 printf("Using XDAIS APIs\n");\r
923 }\r
924 else {\r
925 printf("Using ECO APIs\n");\r
926 }\r
927 \r
928 hw_init();\r
929 \r
930 siu_open();\r
931 \r
932 /* configure VAU */\r
933 siu_new_open_config_modules(&config);\r
934 }\r
935 \r
936 void vau_closedown(void)\r
937 {\r
938 siu_close();\r
939 }\r
940 \r
941 /*-----------------------------------------------------------------\r
942 * Filename: main\r
943 * \r
944 * Description: Test the vpe API functions.\r
945 *-----------------------------------------------------------------*/\r
946 void main (void)\r
947 {\r
948 tulong sample_total;\r
949 tbool sigIn_data; \r
950 tuint second_count;\r
951 tuint sample_count, num_tuint_in, num_tuint_out;\r
952 tint i, j, retVal;\r
953 #ifdef PROFILE_CYCLES\r
954 volatile tlong cycles;\r
955 #endif\r
956 \r
957 #ifdef PROFILE_CYCLES\r
958 if ((vpeSim->outCyclesFilePtr =\r
959 fopen(nmu_SIM_LOGCYC_FNAME, "wt")) == NULL) {\r
960 printf(" Error opening cycles.txt\n");\r
961 exit(0);\r
962 }\r
963 \r
964 /* measure measurement overhead of cycles */\r
965 cycles = profile_getCPUcycleCount();\r
966 \r
967 cycles = (profile_getCPUcycleCount() - cycles);\r
968 vpeSim->cyclesOverhead = cycles;\r
969 #endif\r
970 \r
971 if (vpeSim->bf_on)\r
972 {\r
973 /* BF initialization */\r
974 bf_init();\r
975 \r
976 /* setup BF */\r
977 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
978 bf_setup(i);\r
979 }\r
980 \r
981 if (vpeSim->nr_on)\r
982 {\r
983 /* setup VPE for ASNR */\r
984 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
985 asnr_setup(i);\r
986 }\r
987 \r
988 if (vpeSim->mss_on)\r
989 {\r
990 /* setup MSS */\r
991 mss_setup();\r
992 }\r
993 \r
994 if (vpeSim->vau_on)\r
995 {\r
996 /* setup VAU */\r
997 vau_setup();\r
998 }\r
999 \r
1000 /* Simulation pass initialization */\r
1001 vpeSim->data = TRUE;\r
1002 \r
1003 /* Single test/example simulation loop */\r
1004 second_count = 0;\r
1005 sample_count = 0;\r
1006 fileInSampleIdx = 0;\r
1007 fileOutSampleIdx = 0;\r
1008 while (vpeSim->data) {\r
1009 vpe_sim_flush_cache();\r
1010 \r
1011 /* Read input frame data from file IO buffers */\r
1012 num_tuint_in = vpeSim->frame_size_in;\r
1013 sigIn_data = bf_getNextFrame((void **)inFramePtr, num_tuint_in);\r
1014 vpeSim->data = sigIn_data;\r
1015 \r
1016 if (vpeSim->bf_on)\r
1017 {\r
1018 #ifdef PROFILE_CYCLES\r
1019 cycles = profile_getCPUcycleCount();\r
1020 #endif /* BF processing the currenct frame for each virtual mic */\r
1021 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
1022 {\r
1023 retVal = bfProcess(bfInst[i], (void **)inFramePtr, buf_Inptr[i]);\r
1024 if (retVal!=bf_NOERR)\r
1025 {\r
1026 printf("Error returned by bfProcess() = %d!\n", retVal);\r
1027 exit(0);\r
1028 }\r
1029 }\r
1030 #ifdef PROFILE_CYCLES\r
1031 cycles = (profile_getCPUcycleCount() - cycles);\r
1032 siu_process_cycles(cycles, &vpeSim->cyclesBf);\r
1033 fprintf(vpeSim->outCyclesFilePtr, "BF: %ld\n", (long) cycles);\r
1034 #endif\r
1035 } else\r
1036 {\r
1037 /* copy analog mics instead */\r
1038 for (j=0; j<NUM_BF_ANALOG_MIC; j++)\r
1039 {\r
1040 for (i=0;i<num_tuint_out;i++)\r
1041 buf_Inptr[j][i] = inFramePtr[j][i];\r
1042 }\r
1043 }\r
1044 \r
1045 if(vpeSim->nr_on) {\r
1046 #ifdef PROFILE_CYCLES\r
1047 cycles = profile_getCPUcycleCount();\r
1048 #endif /* BF processing the currenct frame for each virtual mic */\r
1049 /* Run NR if enabled */\r
1050 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
1051 {\r
1052 retVal = asnrProcess(asnrInst[i], buf_Inptr[i], buf_Inptr[i]);\r
1053 if (retVal != asnr_NOERR) {\r
1054 printf("Error returned by asnrProcessn() = %d!\n", retVal);\r
1055 exit(0);\r
1056 }\r
1057 }\r
1058 #ifdef PROFILE_CYCLES\r
1059 cycles = (profile_getCPUcycleCount() - cycles);\r
1060 siu_process_cycles(cycles, &vpeSim->cyclesAsnr);\r
1061 fprintf(vpeSim->outCyclesFilePtr, "ASNR: %ld\n", (long) cycles);\r
1062 #endif\r
1063 }\r
1064 \r
1065 if (vpeSim->mss_on)\r
1066 {\r
1067 #ifdef PROFILE_CYCLES\r
1068 cycles = profile_getCPUcycleCount();\r
1069 #endif /* BF processing the currenct frame for each virtual mic */\r
1070 /* MSS processing here */\r
1071 /* prepare for MSS processing - only one soure for the case of mic-array */\r
1072 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
1073 beam_mics[i] = (void *)&buf_Inptr[i][0];\r
1074 \r
1075 /* multi-source selection module to select the optimum source (mic) */\r
1076 retVal = mssProcess(mssInst, buf_Outptr, data_rx_sync, beam_mics, NULL, NULL, NULL, NULL);\r
1077 if (retVal != mss_NOERR) {\r
1078 printf("Error returned by mssProcess() = %d!\n", retVal);\r
1079 exit(0);\r
1080 }\r
1081 #ifdef PROFILE_CYCLES\r
1082 cycles = (profile_getCPUcycleCount() - cycles);\r
1083 siu_process_cycles(cycles, &vpeSim->cyclesMss);\r
1084 fprintf(vpeSim->outCyclesFilePtr, "MSS: %ld\n", (long) cycles);\r
1085 #endif\r
1086 } else\r
1087 {\r
1088 /* copy to the virtual mic 0 to output buffer */\r
1089 for (i=0;i<num_tuint_out;i++){\r
1090 buf_Outptr[i] = buf_Inptr[0][i];\r
1091 }\r
1092 }\r
1093 \r
1094 if (vpeSim->vau_on)\r
1095 {\r
1096 #ifdef PROFILE_CYCLES\r
1097 cycles = profile_getCPUcycleCount();\r
1098 #endif /* BF processing the currenct frame for each virtual mic */\r
1099 /* VAU processing here */\r
1100 /* first half frame */\r
1101 siuInstVau.frameCount++;\r
1102 siu_process(buf_Outptr, &buf_OutptrMss);\r
1103 /* second half frame */\r
1104 siuInstVau.frameCount++;\r
1105 buf_Outptr2 = &buf_OutptrMss[vpeSim->frame_size_out/2];\r
1106 siu_process(&buf_Outptr[vpeSim->frame_size_out/2], &buf_Outptr2);\r
1107 #ifdef PROFILE_CYCLES\r
1108 cycles = (profile_getCPUcycleCount() - cycles);\r
1109 siu_process_cycles(cycles, &vpeSim->cyclesVau);\r
1110 fprintf(vpeSim->outCyclesFilePtr, "VAU: %ld\n", (long) cycles);\r
1111 #endif\r
1112 }\r
1113 \r
1114 num_tuint_out = vpeSim->frame_size_out;\r
1115 /* copy to a output buffer */\r
1116 for (i=0;i<num_tuint_out;i++){\r
1117 buf_OutptrMss[i] = buf_Outptr[i];\r
1118 }\r
1119 \r
1120 /* save the frame to the output file buffer */\r
1121 bf_putNextFrame(buf_OutptrMss, num_tuint_out);\r
1122 \r
1123 /* Update sample count and notify time progress */\r
1124 sample_count += vpeSim->frame_size_in;\r
1125 if (sample_count >= vpeSim->Fs) {\r
1126 sample_count -= vpeSim->Fs;\r
1127 second_count++;\r
1128 printf (" - Progress: %d seconds\n", second_count);\r
1129 }\r
1130 \r
1131 /* Check for simulation halt */\r
1132 sample_total = (tulong) second_count * vpeSim->Fs + sample_count;\r
1133 vpeSim->sample_cnt = sample_total;\r
1134 } /* vpeSim->data */\r
1135 \r
1136 #ifdef PROFILE_CYCLES\r
1137 siu_print_cycles();\r
1138 fclose(vpeSim->outCyclesFilePtr);\r
1139 #endif\r
1140 \r
1141 /* Progress (verbose only) */\r
1142 vpe_banner_print ("Simulation: END\n");\r
1143 /* End of current simulation test/example */\r
1144 \r
1145 if (vpeSim->vau_on)\r
1146 {\r
1147 /* VAU close down */\r
1148 vau_closedown();\r
1149 }\r
1150 \r
1151 if (vpeSim->mss_on)\r
1152 {\r
1153 /* MSS close down */\r
1154 mss_closedown();\r
1155 }\r
1156 \r
1157 if (vpeSim->nr_on)\r
1158 {\r
1159 /* ASNR close down */\r
1160 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
1161 asnr_closedown(i);\r
1162 }\r
1163 \r
1164 if (vpeSim->bf_on)\r
1165 {\r
1166 /* BF close down */\r
1167 for (i=0; i<NUM_BF_VIRTUAL_MIC; i++)\r
1168 bf_closedown(i);\r
1169 }\r
1170 \r
1171 /* End of simulation */\r
1172 printf("Simulation done.\n");\r
1173 } /* main */\r
1174 \r
1175 /* Nothing past this point */\r