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 * sysbf.c: BF creation routines.\r
36 *=================================================================*/\r
37 \r
38 #include <xdc/std.h>\r
39 #include <ti/sysbios/BIOS.h>\r
40 #include <xdc/runtime/System.h>\r
41 \r
42 #include <ti/mas/types/types.h>\r
43 #include <ti/mas/util/ecomem.h>\r
44 #include <ti/mas/aer/bf.h>\r
45 \r
46 #include "sysbfflt.h"\r
47 #include "sys.h"\r
48 \r
49 bfSizeConfig_t bfSizeConfig = {\r
50 bf_SAMP_RATE_16K, /* 16kHz sampling rate */\r
51 SYS_MICS_MAX, /* Maximum number of mics in the system */\r
52 32, /* Maximum beamformer filter length */\r
53 bf_TYPE_FIXED /* Fixed beamformer type */\r
54 };\r
55 \r
56 bfConfig_t bfConfig = {\r
57 bf_SAMP_RATE_16K, /* use 16kHz sampling rate */\r
58 SYS_MICS_MAX, /* use all mics */\r
59 };\r
60 \r
61 /*=================================================================\r
62 * void sysBfCreate(void) Create beamformers\r
63 *=================================================================*/\r
64 void sysBfCreate(void)\r
65 {\r
66 int k, n, err;\r
67 tint nbufs;\r
68 Fract *coeff_p;\r
69 const ecomemBuffer_t *bufs;\r
70 bfNewConfig_t bfNewConfig;\r
71 bfControl_t bfCtl;\r
72 \r
73 System_printf("...Initializing beamformers\n");\r
74 System_flush();\r
75 \r
76 /* Configure Beamformers (use same configuration for all) */\r
77 err = bfGetSizes(&nbufs, &bufs, &bfSizeConfig);\r
78 if (err != bf_NOERR) {\r
79 System_printf("*** beamformer getsizes error: %d\n", err);\r
80 BIOS_exit(0);\r
81 }\r
82 /* Allocate memory for beamformer */\r
83 if (nbufs > SYS_COMP_MAXBUFS) {\r
84 System_printf("*** not enough buffer descriptors");\r
85 BIOS_exit(0);\r
86 }\r
87 \r
88 bfNewConfig.sizeCfg = bfSizeConfig; /* Use same configuration for all */\r
89 for (k = 0; k < sysContext.nvmics; k++) {\r
90 err = sysHeapAllocAll(nbufs, sysCompBufs, (const void*)bufs);\r
91 SYS_CHECK_ERROR(err);\r
92 \r
93 /* Give memory to beamformer #k */\r
94 bfNewConfig.handle = (void*)k; /* Indicate BF instance #k */\r
95 sysContext.bfInst_p[k] = NULL;\r
96 err = bfNew(&sysContext.bfInst_p[k], nbufs, sysCompBufs, &bfNewConfig);\r
97 if (err != bf_NOERR) {\r
98 System_printf("*** beamformer #%d new error: %d\n", k, err);\r
99 BIOS_exit(0);\r
100 }\r
101 }\r
102 \r
103 /* Open BF for business */\r
104 for (k = 0; k < sysContext.nvmics; k++) {\r
105 err = bfOpen(sysContext.bfInst_p[k],&bfConfig);\r
106 if (err != bf_NOERR) {\r
107 System_printf("*** beamformer #%d open error: %d\n", k, err);\r
108 BIOS_exit(0);\r
109 }\r
110 }\r
111 /* At this point BF's are open, but DISABLED! */\r
112 /* We need to initialize filters prior to enabling them. */\r
113 \r
114 for (k = 0; k < sysContext.nvmics; k++) {\r
115 coeff_p = sysBfFilters[sysContext.vmicangles[k]];\r
116 for (n = 0; n < sysContext.nmics; n++) {\r
117 err = bfPutFilter (sysContext.bfInst_p[k], coeff_p, bf_FG_BF, n, SYS_BF_FILTER_LENGTH);\r
118 if (err != bf_NOERR) {\r
119 System_printf("*** beamformer #%d put-filter error: %d\n", k, err);\r
120 BIOS_exit(0);\r
121 }\r
122 coeff_p += SYS_BF_FILTER_LENGTH; /* point to the filter for next mic */\r
123 }\r
124 }\r
125 \r
126 /* Now we can enable beamformers */\r
127 bfCtl.valid_bitfield = bf_CTL_CONFIG;\r
128 bfCtl.config.mask = bf_CTL_CFG_ENABLE;\r
129 bfCtl.config.value = bf_ENABLE;\r
130 for (k = 0; k < sysContext.nvmics; k++) {\r
131 err = bfControl (sysContext.bfInst_p[k], &bfCtl);\r
132 if (err != bf_NOERR) {\r
133 System_printf("*** beamformer #%d control error: %d\n", k, err);\r
134 BIOS_exit(0);\r
135 }\r
136 }\r
137 \r
138 System_printf("Done with beamformers\n");\r
139 System_flush();\r
140 \r
141 } /* sysBfCreate */\r
142 \r
143 /* nothing past this point */\r
144 \r