comparison chipsetsw/services/Audio/audio_sr_reco.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_sr_reco.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage the */
6 /* recognition of a word for the speech recognition module. */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 09 Oct. 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 #ifdef RVM_AUDIO_MAIN_SWE
22 #ifndef _WINDOWS
23 #include "config/swconfig.cfg"
24 #include "config/sys.cfg"
25 #include "config/chipset.cfg"
26 #endif
27
28 /* include the usefull L1 header */
29 #include "l1_confg.h"
30
31 #if (SPEECH_RECO)
32 #include "rv/rv_general.h"
33 #include "rvm/rvm_gen.h"
34 #include "audio/audio_features_i.h"
35 #include "audio/audio_ffs_i.h"
36 #include "audio/audio_api.h"
37 #include "audio/audio_structs_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 #include "audio/audio_error_hdlr_i.h"
43 #include "audio/audio_macro_i.h"
44
45 /* include the usefull L1 header */
46 #define BOOL_FLAG
47 #define CHAR_FLAG
48 #include "l1_types.h"
49 #include "l1audio_cust.h"
50 #include "l1audio_msgty.h"
51 #include "l1audio_signa.h"
52 #include "l1audio_cust.h"
53
54 #include <string.h>
55
56 /********************************************************************************/
57 /* */
58 /* Function Name: audio_sr_reco_convert_parameter */
59 /* */
60 /* Purpose: Convert the speech reco parameters from the entity to */
61 /* the l1 parameters */
62 /* */
63 /* Input Parameters: */
64 /* entity speech reco message */
65 /* */
66 /* Output Parameters: */
67 /* layer 1 speech reco message */
68 /* */
69 /* Note: */
70 /* None. */
71 /* */
72 /* Revision History: */
73 /* None. */
74 /* */
75 /********************************************************************************/
76 void audio_sr_reco_convert_parameter( T_AUDIO_SR_RECO_START *entity_parameter,
77 T_MMI_SR_RECO_REQ *l1_parameter)
78 {
79 l1_parameter->database_id = 0;
80 l1_parameter->vocabulary_size = entity_parameter->vocabulary_size;
81 }
82
83 /********************************************************************************/
84 /* */
85 /* Function Name: audio_sr_reco_send_status */
86 /* */
87 /* Purpose: This function sends the speech reco status to the */
88 /* entity. */
89 /* */
90 /* Input Parameters: */
91 /* status, */
92 /* return path */
93 /* */
94 /* Output Parameters: */
95 /* None. */
96 /* */
97 /* Note: */
98 /* None. */
99 /* */
100 /* Revision History: */
101 /* None. */
102 /* */
103 /********************************************************************************/
104 void audio_sr_reco_send_status (T_AUDIO_RET status, UINT8 word_index, T_RV_RETURN return_path)
105 {
106 void *p_send_message = NULL;
107 T_RVF_MB_STATUS mb_status = RVF_RED;
108 #ifndef _WINDOWS
109 UINT8 i;
110 char *p_database;
111 char *p_word_name;
112 UINT8 model_name_lengh;
113 #endif
114
115 while (mb_status == RVF_RED)
116 {
117 /* allocate the message buffer */
118 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
119 sizeof (T_AUDIO_SR_RECO_STATUS),
120 (T_RVF_BUFFER **) (&p_send_message));
121
122 /* If insufficient resources, then report a memory error and abort. */
123 /* and wait until more ressource is given */
124 if (mb_status == RVF_RED)
125 {
126 audio_sr_error_trace(AUDIO_ENTITY_NO_MEMORY);
127 rvf_delay(RVF_MS_TO_TICKS(1000));
128 }
129 }
130
131 /*fill the header of the message */
132 ((T_AUDIO_SR_RECO_STATUS *)(p_send_message))->os_hdr.msg_id = AUDIO_SR_RECO_STATUS_MSG;
133
134 if (status > 0)
135 {
136 status = (INT8)((-2) - status);
137 }
138
139 if (status == SC_NO_ERROR)
140 /* no error occured dring the recognition */
141 {
142 #ifndef _WINDOWS
143 /* search the name of the recognized word */
144 p_database = p_audio_gbl_var->speech_reco.sr_reco.p_database;
145 for(i=0; i< word_index; i++)
146 {
147 p_database += AUDIO_PATH_NAME_MAX_SIZE;
148 }
149
150 /* the _sr need to be suppress */
151 model_name_lengh = (strlen(p_database) - 3);
152
153 /* copy this path in the message */
154 strncpy(((T_AUDIO_SR_RECO_STATUS *)(p_send_message))->word_recognized,
155 p_database,
156 model_name_lengh);
157 p_word_name = (char *)(((T_AUDIO_SR_RECO_STATUS *)(p_send_message))->word_recognized);
158 p_word_name += model_name_lengh;
159 *p_word_name = 0;
160 #endif
161 }
162
163 /* fill the status parameters */
164 ((T_AUDIO_SR_RECO_STATUS *)(p_send_message))->status = status;
165
166 if (return_path.callback_func == NULL)
167 {
168 /* send the message to the entity */
169 rvf_send_msg (return_path.addr_id,
170 p_send_message);
171 }
172 else
173 {
174 /* call the callback function */
175 (*return_path.callback_func)((void *)(p_send_message));
176 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
177 }
178 }
179
180 /********************************************************************************/
181 /* */
182 /* Function Name: audio_sr_reco_manager */
183 /* */
184 /* Purpose: This function is called to manage a speech reco */
185 /* process. */
186 /* */
187 /* Input Parameters: */
188 /* Audio Speech reco reco Parameters, */
189 /* */
190 /* Output Parameters: */
191 /* None. */
192 /* */
193 /* Note: */
194 /* None. */
195 /* */
196 /* Revision History: */
197 /* None. */
198 /* */
199 /********************************************************************************/
200 void audio_sr_reco_manager (T_RV_HDR *p_message)
201 {
202 /* Declare local variables. */
203 void *p_send_message;
204
205 /**************** audio_sr_reco_manager function begins *********************/
206 switch(p_audio_gbl_var->speech_reco.sr_reco.state)
207 {
208 case AUDIO_SR_RECO_IDLE:
209 {
210 switch(p_message->msg_id)
211 {
212 case AUDIO_SR_RECO_START_REQ:
213 {
214 /* save the task id of the entity */
215 p_audio_gbl_var->speech_reco.sr_reco.task_id =
216 ((T_AUDIO_SR_RECO_START*)(p_message))->os_hdr.src_addr_id;
217
218 /* save the return path */
219 p_audio_gbl_var->speech_reco.sr_reco.return_path.callback_func =
220 ((T_AUDIO_SR_RECO_START*)(p_message))->return_path.callback_func;
221 p_audio_gbl_var->speech_reco.sr_reco.return_path.addr_id =
222 ((T_AUDIO_SR_RECO_START*)(p_message))->return_path.addr_id;
223
224 /* save the message parameters */
225 p_audio_gbl_var->speech_reco.sr_reco.vocabulary_size =
226 ((T_AUDIO_SR_RECO_START*)(p_message))->vocabulary_size;
227 p_audio_gbl_var->speech_reco.sr_reco.p_database =
228 ((T_AUDIO_SR_RECO_START*)(p_message))->p_database;
229
230 /* allocate the buffer for the message to the L1 */
231 p_send_message = audio_allocate_l1_message(sizeof(T_MMI_SR_RECO_REQ));
232 if ( p_send_message != NULL)
233 {
234 /* Convert the entity parameters to the audio L1 parameters */
235 audio_sr_reco_convert_parameter((T_AUDIO_SR_RECO_START *)p_message,
236 (T_MMI_SR_RECO_REQ *)p_send_message);
237
238 /* send the start command to the audio L1 */
239 audio_send_l1_message(MMI_SR_RECO_START_REQ, p_send_message);
240 }
241
242 /* change to the state AUDIO_SR_RECO_WAIT_START_CONFIRMATION */
243 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_WAIT_START_CON;
244 break;
245 }
246
247 case AUDIO_SR_RECO_STOP_REQ:
248 {
249 /* event error - send an error message*/
250 audio_sr_reco_send_status (AUDIO_ERROR, 0,
251 ((T_AUDIO_SR_RECO_STOP *)(p_message))->return_path);
252
253 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
254 break;
255 }
256 }
257 break;
258 } /* case AUDIO_SR_RECO_IDLE */
259
260 case AUDIO_SR_RECO_WAIT_START_CON:
261 {
262 switch(p_message->msg_id)
263 {
264 case MMI_SR_RECO_START_CON:
265 {
266 /* change to the state AUDIO_SR_RECO_WAIT_STOP_COMMAND */
267 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_WAIT_STOP_COMMAND;
268 break;
269 }
270 case AUDIO_SR_RECO_STOP_REQ:
271 /*.Before stopping this task, control that */
272 /* stop task id caller = SR reco task id */
273 {
274 if ( p_audio_gbl_var->speech_reco.sr_reco.task_id ==
275 ((T_AUDIO_SR_RECO_STOP*)(p_message))->os_hdr.src_addr_id)
276 {
277 /* save the return path */
278 p_audio_gbl_var->speech_reco.sr_reco.return_path.callback_func =
279 ((T_AUDIO_SR_RECO_STOP*)(p_message))->return_path.callback_func;
280 p_audio_gbl_var->speech_reco.sr_reco.return_path.addr_id =
281 ((T_AUDIO_SR_RECO_STOP*)(p_message))->return_path.addr_id;
282
283 /* change to the state AUDIO_SR_RECO_WAIT_STOP_CONFIRMATION */
284 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_WAIT_START_CON_TO_STOP;
285 }
286 else
287 {
288 /* A stop request from an other task is sent during a start connection */
289 /* event error - send an error message */
290 audio_sr_reco_send_status (AUDIO_ERROR, 0,
291 ((T_AUDIO_SR_RECO_STOP *)(p_message))->return_path);
292
293 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
294 }
295 break;
296 }
297 case AUDIO_SR_RECO_START_REQ:
298 {
299 /* deallocate the vocabulary data buffer */
300 rvf_free_buf(
301 (T_RVF_BUFFER *)(((T_AUDIO_SR_RECO_START *)(p_message))->p_database));
302
303 /* event error - send an error message*/
304 audio_sr_reco_send_status (AUDIO_ERROR, 0,
305 ((T_AUDIO_SR_RECO_START *)(p_message))->return_path);
306
307 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
308 break;
309 }
310 }
311 break;
312 } /* case AUDIO_SR_RECO_WAIT_START_CON */
313
314 case AUDIO_SR_RECO_WAIT_START_CON_TO_STOP:
315 {
316 switch(p_message->msg_id)
317 {
318 case MMI_SR_RECO_START_CON:
319 {
320 /* send the stop command to the audio L1 */
321 /* allocate the buffer for the message to the L1 */
322 p_send_message = audio_allocate_l1_message(0);
323 if ( p_send_message != NULL)
324 {
325 /* send the start command to the audio L1 */
326 audio_send_l1_message(MMI_SR_RECO_STOP_REQ, p_send_message);
327 }
328
329 /* change to the state AUDIO_SR_RECO_WAIT_STOP_CON */
330 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_WAIT_STOP_CON;
331 break;
332 }
333 case AUDIO_SR_RECO_START_REQ:
334 {
335 /* deallocate the vocabulary data buffer */
336 rvf_free_buf(
337 (T_RVF_BUFFER *)(((T_AUDIO_SR_RECO_START *)(p_message))->p_database));
338
339 /* event error - send an error message*/
340 audio_sr_reco_send_status (AUDIO_ERROR, 0,
341 ((T_AUDIO_SR_RECO_START *)(p_message))->return_path);
342
343 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
344 break;
345 }
346 case AUDIO_SR_RECO_STOP_REQ:
347 {
348 /* event error - send an error message*/
349 audio_sr_reco_send_status (AUDIO_ERROR, 0,
350 ((T_AUDIO_SR_RECO_STOP *)(p_message))->return_path);
351
352 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
353 break;
354 }
355 }
356 break;
357 }
358
359 case AUDIO_SR_RECO_WAIT_STOP_COMMAND:
360 {
361 switch(p_message->msg_id)
362 {
363 case MMI_SR_RECO_STOP_CON:
364 {
365 /* deallocate the vocabulary data buffer */
366 rvf_free_buf(
367 (T_RVF_BUFFER *)(p_audio_gbl_var->speech_reco.sr_reco.p_database));
368
369 audio_sr_reco_send_status (((T_MMI_SR_RECO_STOP_CON *)p_message)->error_id,
370 (UINT8)((T_MMI_SR_RECO_STOP_CON *)p_message)->best_word_index,
371 p_audio_gbl_var->speech_reco.sr_reco.return_path);
372
373 /* change to the state AUDIO_SR_RECO_IDLE */
374 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_IDLE;
375 break;
376 }
377
378 case AUDIO_SR_RECO_STOP_REQ:
379 {
380 /*.Before stopping this task, control that */
381 /* stop task id caller = SR reco task id */
382 if ( p_audio_gbl_var->speech_reco.sr_reco.task_id ==
383 ((T_AUDIO_SR_RECO_STOP*)(p_message))->os_hdr.src_addr_id)
384 {
385 /* save the return path */
386 p_audio_gbl_var->speech_reco.sr_reco.return_path.callback_func =
387 ((T_AUDIO_SR_RECO_STOP*)(p_message))->return_path.callback_func;
388 p_audio_gbl_var->speech_reco.sr_reco.return_path.addr_id =
389 ((T_AUDIO_SR_RECO_STOP*)(p_message))->return_path.addr_id;
390
391 /* send the stop command to the audio L1 */
392 /* allocate the buffer for the message to the L1 */
393 p_send_message = audio_allocate_l1_message(0);
394 if ( p_send_message != NULL)
395 {
396 /* send the start command to the audio L1 */
397 audio_send_l1_message(MMI_SR_RECO_STOP_REQ, p_send_message);
398 }
399
400 /* change to the state AUDIO_SR_RECO_WAIT_STOP_CONFIRMATION */
401 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_WAIT_STOP_CON;
402 }
403 else
404 {
405 /* A stop request from an other task is sent during a start connection */
406 /* event error - send an error message */
407 audio_sr_reco_send_status (AUDIO_ERROR, 0,
408 ((T_AUDIO_SR_RECO_STOP *)(p_message))->return_path);
409
410 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
411 }
412 break;
413 }
414
415 case AUDIO_SR_RECO_START_REQ:
416 {
417 /* deallocate the vocabulary data buffer */
418 rvf_free_buf(
419 (T_RVF_BUFFER *)(((T_AUDIO_SR_RECO_START *)(p_message))->p_database));
420
421 /* event error - send an error message*/
422 audio_sr_reco_send_status (AUDIO_ERROR, 0,
423 ((T_AUDIO_SR_RECO_START *)(p_message))->return_path);
424
425 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
426 break;
427 }
428 }
429 break;
430 } /* case AUDIO_SR_RECO_WAIT_STOP_COMMAND */
431
432 case AUDIO_SR_RECO_WAIT_STOP_CON:
433 {
434 switch(p_message->msg_id)
435 {
436 case MMI_SR_RECO_STOP_CON:
437 {
438 /* deallocate the vocabulary data buffer */
439 rvf_free_buf(
440 (T_RVF_BUFFER *)(p_audio_gbl_var->speech_reco.sr_reco.p_database));
441
442 audio_sr_reco_send_status (((T_MMI_SR_RECO_STOP_CON *)p_message)->error_id,
443 (UINT8)((T_MMI_SR_RECO_STOP_CON *)p_message)->best_word_index,
444 p_audio_gbl_var->speech_reco.sr_reco.return_path);
445
446 /* change to the state AUDIO_SR_RECO_IDLE */
447 p_audio_gbl_var->speech_reco.sr_reco.state = AUDIO_SR_RECO_IDLE;
448 break;
449 }
450 case AUDIO_SR_RECO_STOP_REQ:
451 {
452 /* event error - send an error message*/
453 audio_sr_reco_send_status (AUDIO_ERROR, 0,
454 ((T_AUDIO_SR_RECO_STOP *)(p_message))->return_path);
455
456 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
457 break;
458 }
459 case AUDIO_SR_RECO_START_REQ:
460 {
461 /* deallocate the vocabulary data buffer */
462 rvf_free_buf(
463 (T_RVF_BUFFER *)(((T_AUDIO_SR_RECO_START *)(p_message))->p_database));
464
465 /* event error - send an error message*/
466 audio_sr_reco_send_status (AUDIO_ERROR, 0,
467 ((T_AUDIO_SR_RECO_START *)(p_message))->return_path);
468
469 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
470 break;
471 }
472 }
473 break;
474 } /* case AUDIO_SR_RECO_WAIT_STOP_CON */
475 } /* switch(p_audio_gbl_var->speech_reco.state) */
476 } /*********************** End of audio_sr_reco_manager function **********************/
477 #endif /* #if (SPEECH_RECO) */
478 #endif /* #ifdef RVM_AUDIO_MAIN_SWE */