]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/audio-preprocessing.git/blob - common/components/sysmss.c
Merge pull request #1 in PROCESSOR-SDK/audio-preprocessing-fw from k2g_cmb_rt to...
[processor-sdk/audio-preprocessing.git] / common / components / sysmss.c
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  *  sysmss.c: MSS 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/mss.h>\r
45 \r
46 #include "mss/mss.h"\r
47 #include "sys.h"\r
48 \r
49 /* Configuration for getSizes */\r
50 mssSizeConfig_t mssSizeConfig = {\r
51   mss_SAMP_RATE_16K,    /* 16kHz sampling rate */\r
52   SYS_VMICS_MAX,        /* Maximum # of fixed mics (will be providing virtual here! */\r
53   0,                    /* No remote mics */\r
54   0,                    /* No "clean" mics */\r
55   0                     /* Beams not supported so we have to used fixed! */\r
56 };\r
57 \r
58 /* Configuration for Open */\r
59 mssConfig_t mssConfig = {\r
60   mss_SAMP_RATE_16K,    /* use 16kHz sampling rate */\r
61   SYS_VMICS_MAX,        /* use one virtual mic only by default */\r
62   0,                    /* No remote mics */\r
63   0,                    /* No "clean" mics */\r
64   SYS_MICS_MAX,         /* Microphone array has 8 mics */\r
65   0                     /* Beams not supported so we used the fixed! */\r
66 };\r
67 \r
68 mssControl_t mssCtl = {\r
69   (mss_CTL_SWITCH_THRESH | mss_CTL_SWITCH_DURATION | mss_CTL_SWITCH_HNAGOVER),\r
70   {0, 0},   /* do not use modes */\r
71   {0, 0},   /* do not use source */\r
72   250,      /* sw-thresh in ms */\r
73   500,      /* sw-duration in ms */\r
74   500       /* sw-hangover in ms */\r
75 };\r
76 \r
77 /*=================================================================\r
78  *  void sysMssCreate(void)     Create beamformers\r
79  *=================================================================*/\r
80 void sysMssCreate(void)\r
81 {\r
82   int err;\r
83   tint nbufs;\r
84   const ecomemBuffer_t  *bufs;\r
85   mssNewConfig_t mssNewConfig;\r
86 //  bfControl_t   bfCtl;\r
87 \r
88   System_printf("...Initializing MSS\n");\r
89   System_flush();\r
90 \r
91   /* Configure MSS */\r
92   err = mssGetSizes(&nbufs, &bufs, &mssSizeConfig);\r
93   if (err != mss_NOERR) {\r
94     System_printf("*** MSS getSizes error: %d\n", err);\r
95     BIOS_exit(0);\r
96   }\r
97   if (nbufs > SYS_COMP_MAXBUFS) {\r
98     System_printf("*** not enough buffer descriptors");\r
99     BIOS_exit(0);\r
100   }\r
101 \r
102   /* Allocate memory for MSS */\r
103   mssNewConfig.sizeCfg = mssSizeConfig;   /* Use same configuration */\r
104   err = sysHeapAllocAll(nbufs, sysCompBufs, (const void*)bufs);\r
105   SYS_CHECK_ERROR(err);\r
106   \r
107   /* Give memory to MSS */\r
108   mssNewConfig.handle = (void*)0;     /* Indicate instance 0 */\r
109   sysContext.mssInst_p = NULL;\r
110   err = mssNew(&sysContext.mssInst_p, nbufs, sysCompBufs, &mssNewConfig);\r
111   if (err != mss_NOERR) {\r
112     System_printf("*** MSS New error: %d\n", err);\r
113     BIOS_exit(0);\r
114   }\r
115 \r
116   /* Open MSS for business */\r
117   err = mssOpen(sysContext.mssInst_p,&mssConfig);\r
118   if (err != mss_NOERR) {\r
119     System_printf("*** MSS open error: %d\n", err);\r
120     BIOS_exit(0);\r
121   }\r
122   /* At this point MSS is open */\r
123 \r
124   /* Reconfigure hangovers, etc. */\r
125   err = mssControl(sysContext.mssInst_p, &mssCtl);\r
126   if (err != mss_NOERR) {\r
127     System_printf("*** MSS control error: %d\n", err);\r
128     BIOS_exit(0);\r
129   }\r
130 \r
131   System_printf("Done with MSS\n");\r
132   System_flush();\r
133 \r
134 } /* sysMssCreate */\r
135 \r
136 /* nothing past this point */\r
137 \r