comparison src/cs/services/audio/audio_sr.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_sr.c */
4 /* */
5 /* Purpose: This file contains all the functions used in the different */
6 /* speech reco task */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 21 Nov. 2001 Create */
13 /* */
14 /* Author */
15 /* Francois Mazard - Stephanie Gerthoux */
16 /* */
17 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
18 /****************************************************************************/
19
20 #include "rv/rv_defined_swe.h"
21
22 #ifdef RVM_AUDIO_MAIN_SWE
23 #ifndef _WINDOWS
24 #include "config/swconfig.cfg"
25 #include "config/sys.cfg"
26 #include "config/chipset.cfg"
27 #endif
28
29 #include "l1_confg.h"
30 #if (SPEECH_RECO)
31 #include "rv/rv_general.h"
32 #include "rvm/rvm_gen.h"
33 #include "audio/audio_features_i.h"
34 #include "audio/audio_ffs_i.h"
35 #include "audio/audio_api.h"
36 #include "audio/audio_structs_i.h"
37 #include "audio/audio_error_hdlr_i.h"
38 #include "audio/audio_var_i.h"
39 #include "audio/audio_messages_i.h"
40 #include "rvf/rvf_target.h"
41 #include "audio/audio_const_i.h"
42
43 #include "ffs/ffs_api.h"
44
45 #ifndef _WINDOWS
46 #include "l1_types.h"
47 #include "l1audio_cust.h"
48 #include "l1audio_msgty.h"
49 #include "l1audio_signa.h"
50 #include "audio/audio_macro_i.h"
51 #else
52 #include "tests/rv/rv_test_filter.h"
53 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
54 /* include the usefull L1 header */
55 #define BOOL_FLAG
56 #define CHAR_FLAG
57 #include "l1_types.h"
58 #include "l1audio_const.h"
59 #include "l1audio_cust.h"
60 #include "l1audio_defty.h"
61 #include "l1audio_msgty.h"
62 #include "l1audio_signa.h"
63 #include "l1_const.h"
64 #include "l1_defty.h"
65 #include "l1_msgty.h"
66 #include "l1_signa.h"
67 #include "l1_varex.h"
68 #include "audio/tests/audio_test.h"
69 #endif
70 #endif
71
72 #include <string.h>
73
74 #ifndef _WINDOWS
75 /**************************************/
76 /* External prototypes */
77 /**************************************/
78 extern void srback_CTO_algorithm (volatile UWORD16 *RAM_address);
79 extern void srback_save_model_temp (volatile UWORD16 *RAM_address_input, UWORD16 *RAM_address_output);
80 extern void Cust_srback_save_model (UWORD8 database, UWORD8 index, volatile UWORD16 *RAM_address);
81 extern void Cust_srback_save_speech (UWORD8 database, UWORD8 index, UWORD16 *start_buffer, UWORD16 *stop_buffer, UWORD16 *start_speech, UWORD16 *stop_speech);
82 extern void Cust_srback_load_model (UWORD8 database, UWORD8 index, volatile UWORD16 *RAM_address);
83
84 #endif
85
86 /********************************************************************************/
87 /* */
88 /* Function Name: audio_sr_create_vocabulary_database */
89 /* */
90 /* Purpose: Create the l1st of the model included in the specified database */
91 /* */
92 /* Input Parameters: */
93 /* directory of the vocabulary database */
94 /* */
95 /* Output Parameters: */
96 /* pointer to the list of the model name */
97 /* number of the model in the database */
98 /* */
99 /* Note: */
100 /* None. */
101 /* */
102 /* Revision History: */
103 /* None. */
104 /* */
105 /********************************************************************************/
106 INT8 audio_sr_create_vocabulary_database(char* directory, void** pp_database)
107 {
108 #ifndef _WINDOWS
109 T_FFS_DIR ffs_dir;
110 T_FFS_SIZE size, number_of_object;
111 T_FFS_STAT stat;
112 INT8 number_of_model=0, i, j, name_size;
113 char name[AUDIO_PATH_NAME_MAX_SIZE], full_name[AUDIO_PATH_NAME_MAX_SIZE],*p_model_name, *ptr;
114 T_RVF_MB_STATUS mb_status;
115
116 /* open the path */
117 number_of_object = ffs_opendir(directory, &ffs_dir);
118 if (number_of_object <= 0)
119 {
120 return(AUDIO_ERROR);
121 }
122
123 /* allocate the buffer for the vocabulary database */
124 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs,
125 (AUDIO_SR_MAX_VOCABULARY_NAME * AUDIO_PATH_NAME_MAX_SIZE),
126 (T_RVF_BUFFER **) (pp_database));
127
128 /* If insufficient resources, then report a memory error and abort. */
129 if (mb_status == RVF_RED)
130 {
131 audio_sr_error_trace(AUDIO_ENTITY_NO_MEMORY);
132 return (AUDIO_ERROR);
133 }
134 /* set the pointer used to write the table of model name */
135 p_model_name = *pp_database;
136
137 /* scan the directory and save the name of the model if it exists */
138 size = 1;
139 while (size > 0)
140 {
141 size = ffs_readdir(&ffs_dir, name,
142 AUDIO_PATH_NAME_MAX_SIZE);
143 if (size > 0)
144 {
145 /* look for the type of the object */
146 /* Note the ffs_stat function needs the full path naem */
147 /* therefor the directory needs to be added to the name from the ffs_readdir function */
148 strcpy(full_name, directory);
149 strcat(full_name,"/");
150 strcat(full_name, name);
151 if (ffs_stat(full_name, &stat) != EFFS_OK)
152 {
153 /* deallocate the memory */
154 rvf_free_buf((T_RVF_BUFFER *)(*pp_database));
155
156 return(AUDIO_ERROR);
157 }
158 else
159 {
160 if ((stat.type == OT_FILE) &&
161 (stat.size != 0) )
162 /* the object is a file with data */
163 {
164 /* check if the name contains _sr at the end */
165 name_size = strlen(name);
166 ptr = name;
167 ptr += (name_size - 3);
168
169 if ( strcmp(ptr, "_sr") == 0 )
170 {
171 /* increase the number of model */
172 number_of_model++;
173 /* Check if the number of vocabulary isn't too high */
174 if (number_of_model > AUDIO_SR_MAX_VOCABULARY_NAME)
175 {
176 /* deallocate the memory */
177 rvf_free_buf((T_RVF_BUFFER *)(*pp_database));
178 return(AUDIO_ERROR);
179 }
180 /* save the model name */
181 strcpy(p_model_name, full_name);
182 /* Increase the model name pointer */
183 p_model_name += AUDIO_PATH_NAME_MAX_SIZE;
184 } /* strcmp(ptr, "_sr") == 0 */
185 } /* stat.type == OT_FILE */
186 } /* fs_stat(full_name, &stat) == EFFS_OK */
187 } /* if (size>0) */
188 } /* while (size>0) */
189
190 return (number_of_model);
191 #else
192 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
193 T_RVF_MB_STATUS mb_status;
194
195 /* allocate the buffer for the vocabulary database */
196 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs,
197 (AUDIO_SR_MAX_VOCABULARY_NAME * AUDIO_PATH_NAME_MAX_SIZE),
198 (T_RVF_BUFFER **) (pp_database));
199 /* If insufficient resources, then report a memory error and abort. */
200 if (mb_status == RVF_RED)
201 {
202 audio_sr_error_trace(AUDIO_ENTITY_NO_MEMORY);
203 return (AUDIO_ERROR);
204 }
205
206 if (p_audio_test->vocabuary_size <= 0)
207 {
208 /* deallocate the memory */
209 rvf_free_buf((T_RVF_BUFFER *)(*pp_database));
210 return (AUDIO_ERROR);
211 }
212 else
213 {
214 return (p_audio_test->vocabuary_size);
215 }
216 #endif
217 #endif
218 }
219
220 #ifndef _WINDOWS
221 /********************************************************************************/
222 /* */
223 /* Function Name: audio_sr_background_manager */
224 /* */
225 /* Purpose: Execute the background task requested by the L1 */
226 /* */
227 /* Input Parameters: */
228 /* message fomr the L1 */
229 /* */
230 /* Output Parameters: */
231 /* */
232 /* Note: */
233 /* None. */
234 /* */
235 /* Revision History: */
236 /* None. */
237 /* */
238 /********************************************************************************/
239 void audio_sr_background_manager(T_RV_HDR *p_message)
240 {
241 UINT16 confirm_message_id;
242 void *p_confirm_message;
243 UINT8 index;
244
245 switch (p_message->msg_id)
246 {
247 case L1_SRBACK_SAVE_DATA_REQ:
248 {
249 AUDIO_SEND_TRACE("AUDIO SR BACKGROUND: Save model", RV_TRACE_LEVEL_DEBUG_LOW);
250
251 // Call the customer function to save the model
252 Cust_srback_save_model( ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->database_id,
253 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->model_index,
254 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->model_RAM_address );
255
256 if ( ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->speech)
257 {
258 AUDIO_SEND_TRACE("AUDIO SR BACKGROUND: Save speech", RV_TRACE_LEVEL_DEBUG_LOW);
259
260 // Call the customer function to save the speech from a circular buffer to the database
261 Cust_srback_save_speech( ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->database_id,
262 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->model_index,
263 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->start_buffer,
264 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->stop_buffer,
265 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->start_address,
266 ((T_L1_SRBACK_SAVE_DATA_REQ *)(p_message))->stop_address);
267 }
268
269 /* set the confirm message identifier */
270 confirm_message_id = L1_SRBACK_SAVE_DATA_CON;
271
272 break;
273 } // L1_SRBACK_SAVE_DATA_REQ
274
275 case L1_SRBACK_LOAD_MODEL_REQ:
276 {
277 if ( ( ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->CTO_enable ) == FALSE )
278 {
279 AUDIO_SEND_TRACE_PARAM("AUDIO SR BACKGROUND: load model without CTO",
280 ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_index,
281 RV_TRACE_LEVEL_DEBUG_LOW);
282
283 // Call the function to load a model
284 Cust_srback_load_model( ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->database_id,
285 ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_index,
286 ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_RAM_address );
287 }
288 else
289 {
290 // Calculate the good index
291 index = ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_index>>1;
292
293 AUDIO_SEND_TRACE_PARAM("AUDIO SR BACKGROUND: load model with CTO",
294 index,
295 RV_TRACE_LEVEL_DEBUG_LOW);
296
297 // Call the function to load a model with the good index
298 Cust_srback_load_model( ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->database_id,
299 index,
300 ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_RAM_address );
301
302 // The CTO algorithm is used and the model index is odd
303 if ( ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_index & 0x01 )
304 {
305 // Call the function to apply the CTO algorithm to the loaded model
306 srback_CTO_algorithm( ((T_L1_SRBACK_LOAD_MODEL_REQ *)(p_message))->model_RAM_address );
307 }
308 }
309
310 /* set the confirm message identifier */
311 confirm_message_id = L1_SRBACK_LOAD_MODEL_CON;
312
313 break;
314 } // L1_SRBACK_LOAD_MODEL_REQ
315
316 case L1_SRBACK_TEMP_SAVE_DATA_REQ:
317 {
318 AUDIO_SEND_TRACE("AUDIO SR BACKGROUND: save model in temporary buffer",
319 RV_TRACE_LEVEL_DEBUG_LOW);
320
321 // Call the function to save the model in a temporary buffer
322 srback_save_model_temp( ((T_L1_SRBACK_TEMP_SAVE_DATA_REQ *)(p_message))->model_RAM_address_input,
323 ((T_L1_SRBACK_TEMP_SAVE_DATA_REQ *)(p_message))->model_RAM_address_output );
324
325 /* set the confirm message identifier */
326 confirm_message_id = L1_SRBACK_TEMP_SAVE_DATA_CON;
327
328 break;
329 }
330 } /* switch */
331
332 /* send the confirmation message */
333 /* allocate the buffer for the message to the L1 */
334 p_confirm_message = audio_allocate_l1_message(0);
335 if (p_confirm_message != NULL)
336 {
337 /* send the start command to the audio L1 */
338 audio_send_l1_message(confirm_message_id, p_confirm_message);
339 }
340 } /* audio_sr_background_manager */
341 #endif /* _WINDOWS */
342 #endif /* SPEECH_RECO */
343 #endif /* RVM_AUDIO_MAIN_SWE */