comparison src/cs/services/Audio/audio_sr_enroll.c @ 0:945cf7f506b2

src/cs: chipsetsw import from tcs211-fcmodem binary blobs and LCD demo files have been excluded, all line endings are LF only
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 22:50:11 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:945cf7f506b2
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_sr_enroll.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage the */
6 /* enrollment 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 /********************************************************************************/
55 /* */
56 /* Function Name: audio_sr_enroll_convert_parameter */
57 /* */
58 /* Purpose: Convert the speech reco enroll parameters from the entity to */
59 /* the l1 parameters */
60 /* */
61 /* Input Parameters: */
62 /* entity speech reco enroll message */
63 /* */
64 /* Output Parameters: */
65 /* layer 1 speech reco enroll message */
66 /* */
67 /* Note: */
68 /* None. */
69 /* */
70 /* Revision History: */
71 /* None. */
72 /* */
73 /********************************************************************************/
74 void audio_sr_enroll_convert_parameter( T_AUDIO_SR_ENROLL_START *entity_parameter,
75 T_MMI_SR_ENROLL_REQ *l1_parameter)
76 {
77 T_RVF_MB_STATUS mb_status;
78
79 l1_parameter->database_id = 0;
80 l1_parameter->word_index = 0;
81
82 /* Check if the speech sample must be saved */
83 if (entity_parameter->voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
84 {
85 l1_parameter->speech = TRUE;
86 /* Allocate the RAM buffer for the speech samples */
87 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs,
88 (SC_SR_MMI_2_L1_SPEECH_SIZE * sizeof(UINT16)),
89 (T_RVF_BUFFER **) (&(p_audio_gbl_var->speech_reco.sr_enroll.p_speech_address)));
90
91 l1_parameter->speech_address = (UWORD16 *)p_audio_gbl_var->speech_reco.sr_enroll.p_speech_address;
92
93 AUDIO_SEND_TRACE_PARAM(" AUDIO SR ENROLL: speech buffer allocate ",
94 l1_parameter->speech_address,
95 RV_TRACE_LEVEL_DEBUG_LOW);
96
97 /* If insufficient resource, then report a memory error and abort. */
98 if (mb_status == RVF_RED)
99 {
100 audio_sr_error_trace(AUDIO_ENTITY_NO_MEMORY);
101 }
102 }
103 else
104 {
105 l1_parameter->speech = FALSE;
106 }
107 }
108
109 /********************************************************************************/
110 /* */
111 /* Function Name: audio_sr_enroll_send_status */
112 /* */
113 /* Purpose: This function sends the speech reco enroll status to the */
114 /* entity. */
115 /* */
116 /* Input Parameters: */
117 /* status, */
118 /* return path */
119 /* */
120 /* Output Parameters: */
121 /* None. */
122 /* */
123 /* Note: */
124 /* None. */
125 /* */
126 /* Revision History: */
127 /* None. */
128 /* */
129 /********************************************************************************/
130 void audio_sr_enroll_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
131 {
132 void *p_send_message = NULL;
133 T_RVF_MB_STATUS mb_status = RVF_RED;
134
135 while (mb_status == RVF_RED)
136 {
137 /* allocate the message buffer */
138 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
139 sizeof (T_AUDIO_SR_ENROLL_STATUS),
140 (T_RVF_BUFFER **) (&p_send_message));
141
142 /* If insufficient resources, then report a memory error and abort. */
143 /* and wait until more ressource is given */
144 if (mb_status == RVF_RED)
145 {
146 audio_sr_error_trace(AUDIO_ENTITY_NO_MEMORY);
147 rvf_delay(RVF_MS_TO_TICKS(1000));
148 }
149 }
150
151 /*fill the header of the message */
152 ((T_AUDIO_SR_ENROLL_STATUS *)(p_send_message))->os_hdr.msg_id = AUDIO_SR_ENROLL_STATUS_MSG;
153
154 if (status > 0)
155 {
156 status = (INT8)((-2) - status);
157 }
158
159 /* fill the status parameters */
160 ((T_AUDIO_SR_ENROLL_STATUS *)(p_send_message))->status = status;
161
162 if (return_path.callback_func == NULL)
163 {
164 /* send the message to the entity */
165 rvf_send_msg (return_path.addr_id,
166 p_send_message);
167 }
168 else
169 {
170 /* call the callback function */
171 (*return_path.callback_func)((void *)(p_send_message));
172 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
173 }
174 }
175
176 /********************************************************************************/
177 /* */
178 /* Function Name: audio_sr_enroll_manager */
179 /* */
180 /* Purpose: This function is called to manage a speech reco enrollment */
181 /* process. */
182 /* */
183 /* Input Parameters: */
184 /* Audio Speech reco enroll Parameters, */
185 /* */
186 /* Output Parameters: */
187 /* None. */
188 /* */
189 /* Note: */
190 /* None. */
191 /* */
192 /* Revision History: */
193 /* None. */
194 /* */
195 /********************************************************************************/
196 void audio_sr_enroll_manager (T_RV_HDR *p_message)
197 {
198 /* Declare local variables. */
199 void *p_send_message;
200 T_RV_RET status;
201
202 /**************** audio_sr_enroll_manager function begins *********************/
203 switch(p_audio_gbl_var->speech_reco.sr_enroll.state)
204 {
205 case AUDIO_SR_ENROLL_IDLE:
206 {
207 switch(p_message->msg_id)
208 {
209 case AUDIO_SR_ENROLL_START_REQ:
210 {
211 /* save the task id of the entity */
212 p_audio_gbl_var->speech_reco.sr_enroll.task_id =
213 ((T_AUDIO_SR_ENROLL_START*)(p_message))->os_hdr.src_addr_id;
214
215 /* save the return path */
216 p_audio_gbl_var->speech_reco.sr_enroll.return_path.callback_func =
217 ((T_AUDIO_SR_ENROLL_START*)(p_message))->return_path.callback_func;
218 p_audio_gbl_var->speech_reco.sr_enroll.return_path.addr_id =
219 ((T_AUDIO_SR_ENROLL_START*)(p_message))->return_path.addr_id;
220
221 /* save the message parameters */
222 p_audio_gbl_var->speech_reco.sr_enroll.sr_ffs_fd =
223 ((T_AUDIO_SR_ENROLL_START*)(p_message))->sr_ffs_fd;
224 p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd =
225 ((T_AUDIO_SR_ENROLL_START*)(p_message))->voice_ffs_fd;
226
227 /* allocate the buffer for the message to the L1 */
228 p_send_message = audio_allocate_l1_message(sizeof(T_MMI_SR_ENROLL_REQ));
229 if ( p_send_message != NULL)
230 {
231 /* Convert the entity parameters to the audio L1 parameters */
232 audio_sr_enroll_convert_parameter((T_AUDIO_SR_ENROLL_START *)p_message,
233 (T_MMI_SR_ENROLL_REQ *)p_send_message);
234
235 /* send the start command to the audio L1 */
236 audio_send_l1_message(MMI_SR_ENROLL_START_REQ, p_send_message);
237 }
238
239 /* change to the state AUDIO_SR_ENROLL_WAIT_START_CONFIRMATION */
240 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_WAIT_START_CON;
241 break;
242 }
243
244 case AUDIO_SR_ENROLL_STOP_REQ:
245 {
246 /* event error - send an error message*/
247 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_STOP *)(p_message))->return_path);
248
249 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
250 break;
251 }
252 }
253 break;
254 } /* case AUDIO_SR_ENROLL_IDLE */
255
256 case AUDIO_SR_ENROLL_WAIT_START_CON:
257 {
258 switch(p_message->msg_id)
259 {
260 case MMI_SR_ENROLL_START_CON:
261 {
262 /* change to the state AUDIO_SR_ENROLL_WAIT_STOP_COMMAND */
263 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_WAIT_STOP_COMMAND;
264 break;
265 }
266 case AUDIO_SR_ENROLL_STOP_REQ:
267 /*.Before stopping this task, control that */
268 /* stop task id caller = SR enroll task id */
269 {
270 if ( p_audio_gbl_var->speech_reco.sr_enroll.task_id ==
271 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->os_hdr.src_addr_id)
272 {
273 /* save the return path */
274 p_audio_gbl_var->speech_reco.sr_enroll.return_path.callback_func =
275 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->return_path.callback_func;
276 p_audio_gbl_var->speech_reco.sr_enroll.return_path.addr_id =
277 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->return_path.addr_id;
278
279 /* change to the state AUDIO_SR_ENROLL_WAIT_STOP_CONFIRMATION */
280 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_WAIT_START_CON_TO_STOP;
281 }
282 else
283 {
284 /* A stop request from an other task is sent during a start connection */
285 /* event error - send an error message */
286 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_STOP *)(p_message))->return_path);
287
288 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
289 }
290 break;
291 }
292 case AUDIO_SR_ENROLL_START_REQ:
293 {
294 /* close the model file */
295 /* close the voice sample file if it exists*/
296 #ifndef _WINDOWS
297 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->sr_ffs_fd);
298 if ( ((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
299 {
300 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd);
301 }
302 #endif
303 /* event error - send an error message*/
304 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_START *)(p_message))->return_path);
305
306 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
307 break;
308 }
309 }
310 break;
311 } /* case AUDIO_SR_ENROLL_WAIT_START_CON */
312
313 case AUDIO_SR_ENROLL_WAIT_START_CON_TO_STOP:
314 {
315 switch(p_message->msg_id)
316 {
317 case MMI_SR_ENROLL_START_CON:
318 {
319 /* send the stop command to the audio L1 */
320 /* allocate the buffer for the message to the L1 */
321 p_send_message = audio_allocate_l1_message(0);
322 if ( p_send_message != NULL)
323 {
324 /* send the start command to the audio L1 */
325 audio_send_l1_message(MMI_SR_ENROLL_STOP_REQ, p_send_message);
326 }
327
328 /* change to the state AUDIO_SR_ENROLL_WAIT_STOP_CON */
329 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_WAIT_STOP_CON;
330 break;
331 }
332 case AUDIO_SR_ENROLL_START_REQ:
333 {
334 /* close the model file */
335 /* close the voice sample file if it exists*/
336 #ifndef _WINDOWS
337 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->sr_ffs_fd);
338 if ( ((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
339 {
340 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd);
341 }
342 #endif
343 /* event error - send an error message*/
344 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_START *)(p_message))->return_path);
345
346 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
347 break;
348 }
349 case AUDIO_SR_ENROLL_STOP_REQ:
350 {
351 /* event error - send an error message*/
352 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_STOP *)(p_message))->return_path);
353
354 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
355 break;
356 }
357 }
358 break;
359 }
360
361 case AUDIO_SR_ENROLL_WAIT_STOP_COMMAND:
362 {
363 switch(p_message->msg_id)
364 {
365 case MMI_SR_ENROLL_STOP_CON:
366 {
367 /* close the model file */
368 /* close the voice sample file if it exists*/
369 #ifndef _WINDOWS
370 ffs_close(p_audio_gbl_var->speech_reco.sr_enroll.sr_ffs_fd);
371 if (p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
372 {
373 ffs_close(p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd);
374 }
375 #endif
376
377 /* Deallocate the speech buffer if it was used */
378 if (p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
379 {
380 status = rvf_free_buf(p_audio_gbl_var->speech_reco.sr_enroll.p_speech_address);
381 if (status != RVF_GREEN)
382 {
383 AUDIO_SEND_TRACE("AUDIO SR ENROLL: A wrong speech buffer is deallocated",
384 RV_TRACE_LEVEL_ERROR);
385 }
386 }
387
388 audio_sr_enroll_send_status (((T_MMI_SR_ENROLL_STOP_CON *)p_message)->error_id,
389 p_audio_gbl_var->speech_reco.sr_enroll.return_path);
390
391 /* change to the state AUDIO_SR_ENROLL_IDLE */
392 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_IDLE;
393 break;
394 }
395
396 case AUDIO_SR_ENROLL_STOP_REQ:
397 {
398 /*.Before stopping this task, control that */
399 /* stop task id caller = SR enroll task id */
400 if ( p_audio_gbl_var->speech_reco.sr_enroll.task_id ==
401 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->os_hdr.src_addr_id)
402 {
403 /* save the return path */
404 p_audio_gbl_var->speech_reco.sr_enroll.return_path.callback_func =
405 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->return_path.callback_func;
406 p_audio_gbl_var->speech_reco.sr_enroll.return_path.addr_id =
407 ((T_AUDIO_SR_ENROLL_STOP*)(p_message))->return_path.addr_id;
408
409 /* send the stop command to the audio L1 */
410 /* allocate the buffer for the message to the L1 */
411 p_send_message = audio_allocate_l1_message(0);
412 if ( p_send_message != NULL)
413 {
414 /* send the start command to the audio L1 */
415 audio_send_l1_message(MMI_SR_ENROLL_STOP_REQ, p_send_message);
416 }
417
418 /* change to the state AUDIO_SR_ENROLL_WAIT_STOP_CONFIRMATION */
419 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_WAIT_STOP_CON;
420 }
421 else
422 {
423 /* A stop request from an other task is sent during a start connection */
424 /* event error - send an error message */
425 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_STOP *)(p_message))->return_path);
426
427 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
428 }
429 break;
430 }
431
432 case AUDIO_SR_ENROLL_START_REQ:
433 {
434 /* close the model file */
435 /* close the voice sample file if it exists*/
436 #ifndef _WINDOWS
437 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->sr_ffs_fd);
438 if ( ((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
439 {
440 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd);
441 }
442 #endif
443 /* event error - send an error message*/
444 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_START *)(p_message))->return_path);
445
446 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
447 break;
448 }
449 }
450 break;
451 } /* case AUDIO_SR_ENROLL_WAIT_STOP_COMMAND */
452
453 case AUDIO_SR_ENROLL_WAIT_STOP_CON:
454 {
455 switch(p_message->msg_id)
456 {
457 case MMI_SR_ENROLL_STOP_CON:
458 {
459 /* close the model file */
460 /* close the voice sample file if it exists*/
461 #ifndef _WINDOWS
462 ffs_close(p_audio_gbl_var->speech_reco.sr_enroll.sr_ffs_fd);
463 if (p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
464 {
465 ffs_close(p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd);
466 }
467 #endif
468
469 /* Deallocate the speech buffer if it was used */
470 if (p_audio_gbl_var->speech_reco.sr_enroll.voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
471 {
472 status = rvf_free_buf(p_audio_gbl_var->speech_reco.sr_enroll.p_speech_address);
473 if (status != RVF_GREEN)
474 {
475 AUDIO_SEND_TRACE("AUDIO SR ENROLL: A wrong speech buffer is deallocated ",
476 RV_TRACE_LEVEL_ERROR);
477 }
478 }
479
480 audio_sr_enroll_send_status (((T_MMI_SR_ENROLL_STOP_CON *)p_message)->error_id,
481 p_audio_gbl_var->speech_reco.sr_enroll.return_path);
482
483 /* change to the state AUDIO_SR_ENROLL_IDLE */
484 p_audio_gbl_var->speech_reco.sr_enroll.state = AUDIO_SR_ENROLL_IDLE;
485 break;
486 }
487 case AUDIO_SR_ENROLL_STOP_REQ:
488 {
489 /* event error - send an error message*/
490 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_STOP *)(p_message))->return_path);
491
492 audio_sr_error_trace(AUDIO_ERROR_STOP_EVENT);
493 break;
494 }
495 case AUDIO_SR_ENROLL_START_REQ:
496 {
497 /* close the model file */
498 /* close the voice sample file if it exists*/
499 #ifndef _WINDOWS
500 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->sr_ffs_fd);
501 if ( ((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd != AUDIO_SR_NO_RECORD_SPEECH)
502 {
503 ffs_close(((T_AUDIO_SR_ENROLL_START *)(p_message))->voice_ffs_fd);
504 }
505 #endif
506 /* event error - send an error message*/
507 audio_sr_enroll_send_status (AUDIO_ERROR, ((T_AUDIO_SR_ENROLL_START *)(p_message))->return_path);
508
509 audio_sr_error_trace(AUDIO_ERROR_START_EVENT);
510 break;
511 }
512 }
513 break;
514 } /* case AUDIO_SR_ENROLL_WAIT_STOP_CON */
515 } /* switch(p_audio_gbl_var->speech_reco.state) */
516 } /*********************** End of audio_sr_enroll_manager function **********************/
517 #endif /* #if (SPEECH_RECO) */
518 #endif /* #ifdef RVM_AUDIO_MAIN_SWE */