comparison src/cs/services/audio/audio_tones.c @ 52:1eb391057168

Main and Audio source directories lowercased
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Jul 2018 22:49:10 +0000
parents src/cs/services/Audio/audio_tones.c@b6a5e36de839
children
comparison
equal deleted inserted replaced
51:daf96987cb39 52:1eb391057168
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_tones.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage the */
6 /* tones . */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 28 May 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 (TONE)
31 #include <math.h>
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
44 /* include the usefull L1 header */
45 #define BOOL_FLAG
46 #define CHAR_FLAG
47 #include "l1_types.h"
48 #include "l1audio_cust.h"
49 #include "l1audio_msgty.h"
50 #include "l1audio_signa.h"
51
52 /********************************************************************************/
53 /* */
54 /* Function Name: audio_tones_convert_parameter */
55 /* */
56 /* Purpose: Convert the tones paramters from the entity to the l1 */
57 /* parameters */
58 /* */
59 /* Input Parameters: */
60 /* entity tones message */
61 /* */
62 /* Output Parameters: */
63 /* layer 1 tones message */
64 /* */
65 /* Note: */
66 /* None. */
67 /* */
68 /* Revision History: */
69 /* None. */
70 /* */
71 /********************************************************************************/
72 void audio_tones_convert_parameter( T_AUDIO_TONES_START *entity_parameter,
73 T_MMI_TONE_REQ *l1_parameter)
74 {
75 double frequency_index, frequency_beep, amplitude_beep, amplitude, amplitude_index;
76
77 /* Calculation of the frequency index */
78 /* note: we /* add +0.5 to compensate the truncation */
79 frequency_beep = (double)(entity_parameter->tones_parameter.tones[0].frequency_tone);
80 frequency_index = (256 * cos(6.283185*(frequency_beep/8000)));
81 /* Calculation of the amplitude index */
82 /* note: we /* add +0.5 to compensate the truncation */
83 amplitude_beep = (double)(entity_parameter->tones_parameter.tones[0].amplitude_tone);
84 amplitude = exp((amplitude_beep*0.115129)+(5.544625));
85 amplitude_index = amplitude * sin(6.283185*(frequency_beep/8000));
86
87 l1_parameter->d_k_x1_t0 = (UINT16)((((UINT16)(frequency_index))<<8) | ((UINT16)(amplitude_index)));
88
89 /* Calculation of the frequency index */
90 /* note: we /* add +0.5 to compensate the truncation */
91 frequency_beep = (double)(entity_parameter->tones_parameter.tones[1].frequency_tone);
92 frequency_index = (256 * cos(6.283185*(frequency_beep/8000)));
93 /* Calculation of the amplitude index */
94 /* note: we /* add +0.5 to compensate the truncation */
95 amplitude_beep = (double)(entity_parameter->tones_parameter.tones[1].amplitude_tone);
96 amplitude = exp((amplitude_beep*0.115129)+(5.544625));
97 amplitude_index = amplitude * sin(6.283185*(frequency_beep/8000));
98
99 l1_parameter->d_k_x1_t1 = (UINT16)((((UINT16)(frequency_index))<<8) | ((UINT16)(amplitude_index)));
100
101 /* Calculation of the frequency index */
102 /* note: we /* add +0.5 to compensate the truncation */
103 frequency_beep = (double)(entity_parameter->tones_parameter.tones[2].frequency_tone);
104 frequency_index = (256 * cos(6.283185*(frequency_beep/8000)));
105 /* Calculation of the amplitude index */
106 /* note: we /* add +0.5 to compensate the truncation */
107 amplitude_beep = (double)(entity_parameter->tones_parameter.tones[2].amplitude_tone);
108 amplitude = exp((amplitude_beep*0.115129)+(5.544625));
109 amplitude_index = amplitude * sin(6.283185*(frequency_beep/8000));
110
111 l1_parameter->d_k_x1_t2 = (UINT16)((((UINT16)(frequency_index))<<8) | ((UINT16)(amplitude_index)));
112
113 l1_parameter->d_t0_on = (UINT16)((entity_parameter->tones_parameter.tones[0].start_tone)/20);
114 l1_parameter->d_t1_on = (UINT16)((entity_parameter->tones_parameter.tones[1].start_tone)/20);
115 l1_parameter->d_t2_on = (UINT16)((entity_parameter->tones_parameter.tones[2].start_tone)/20);
116
117 l1_parameter->d_t0_off = (UINT16)((entity_parameter->tones_parameter.tones[0].stop_tone)/20);
118 l1_parameter->d_t1_off = (UINT16)((entity_parameter->tones_parameter.tones[1].stop_tone)/20);
119 l1_parameter->d_t2_off = (UINT16)((entity_parameter->tones_parameter.tones[2].stop_tone)/20);
120
121 l1_parameter->d_bu_off = (UINT16)((entity_parameter->tones_parameter.frame_duration)/20);
122
123 l1_parameter->d_se_off = (UINT16)((entity_parameter->tones_parameter.sequence_duration)/20);
124
125 l1_parameter->d_pe_off = (UINT16)((entity_parameter->tones_parameter.period_duration)/20);
126
127 l1_parameter->d_pe_rep = entity_parameter->tones_parameter.repetition;
128 }
129
130
131
132 /********************************************************************************/
133 /* */
134 /* Function Name: audio_tones_send_status */
135 /* */
136 /* Purpose: This function sends the tones status to the entity. */
137 /* */
138 /* Input Parameters: */
139 /* status, */
140 /* return path */
141 /* */
142 /* Output Parameters: */
143 /* None. */
144 /* */
145 /* Note: */
146 /* None. */
147 /* */
148 /* Revision History: */
149 /* None. */
150 /* */
151 /********************************************************************************/
152 void audio_tones_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
153 {
154 void *p_send_message = NULL;
155 T_RVF_MB_STATUS mb_status = RVF_RED;
156
157 while (mb_status == RVF_RED)
158 {
159 /* allocate the message buffer */
160 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
161 sizeof (T_AUDIO_TONES_STATUS),
162 (T_RVF_BUFFER **) (&p_send_message));
163
164 /* If insufficient resources, then report a memory error and abort. */
165 /* and wait until more ressource is given */
166 if (mb_status == RVF_RED)
167 {
168 audio_tones_error_trace(AUDIO_ENTITY_NO_MEMORY);
169 rvf_delay(RVF_MS_TO_TICKS(1000));
170 }
171 }
172
173 /*fill the header of the message */
174 ((T_AUDIO_TONES_STATUS *)(p_send_message))->os_hdr.msg_id = AUDIO_TONES_STATUS_MSG;
175
176 /* fill the status parameters */
177 ((T_AUDIO_TONES_STATUS *)(p_send_message))->status = status;
178
179 if (return_path.callback_func == NULL)
180 {
181 /* send the message to the entity */
182 rvf_send_msg (return_path.addr_id,
183 p_send_message);
184 }
185 else
186 {
187 /* call the callback function */
188 (*return_path.callback_func)((void *)(p_send_message));
189 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
190 }
191 }
192 /********************************************************************************/
193 /* */
194 /* Function Name: audio_tones_manager */
195 /* */
196 /* Purpose: This function is called to manage a tones generation */
197 /* */
198 /* Input Parameters: */
199 /* Audio Key Beep Parameters, */
200 /* */
201 /* Output Parameters: */
202 /* None. */
203 /* */
204 /* Note: */
205 /* None. */
206 /* */
207 /* Revision History: */
208 /* None. */
209 /* */
210 /********************************************************************************/
211 void audio_tones_manager (T_RV_HDR *p_message)
212 {
213
214 /* Declare local variables. */
215 void *p_send_message;
216
217 /**************** audio_tones_manager function begins *********************/
218 switch(p_audio_gbl_var->tones.state)
219 {
220 case AUDIO_TONES_IDLE:
221 {
222 switch(p_message->msg_id)
223 {
224 case AUDIO_TONES_START_REQ:
225 {
226 /* save the addr id of the entity */
227 p_audio_gbl_var->tones.task_id = p_message->src_addr_id;
228
229 /* save the return path */
230 p_audio_gbl_var->tones.return_path.callback_func = ((T_AUDIO_TONES_START*)(p_message))->return_path.callback_func;
231 p_audio_gbl_var->tones.return_path.addr_id = ((T_AUDIO_TONES_START*)(p_message))->return_path.addr_id;
232
233 /* allocate the buffer for the message to the L1 */
234 p_send_message = audio_allocate_l1_message(sizeof(T_MMI_TONE_REQ));
235 if (p_send_message != NULL)
236 {
237 /* Convert the entity parameters to the audio L1 parameters */
238 audio_tones_convert_parameter((T_AUDIO_TONES_START *)p_message,
239 (T_MMI_TONE_REQ *)p_send_message);
240
241 /* send the start command to the audio L1 */
242 audio_send_l1_message(MMI_TONE_START_REQ, p_send_message);
243 }
244
245 /* change to the state AUDIO_TONES_WAIT_START_CONFIRMATION */
246 p_audio_gbl_var->tones.state = AUDIO_TONES_WAIT_START_CON;
247 break;
248 }
249
250 case AUDIO_TONES_STOP_REQ:
251 {
252 /* event error - send an error message*/
253 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_STOP *)(p_message))->return_path);
254
255 audio_tones_error_trace(AUDIO_ERROR_STOP_EVENT);
256 break;
257 }
258 }
259 break;
260 } /* case AUDIO_TONES_IDLE */
261
262 case AUDIO_TONES_WAIT_START_CON:
263 {
264 switch(p_message->msg_id)
265 {
266 case MMI_TONE_START_CON:
267 {
268 /* change to the state AUDIO_TONES_WAIT_STOP_COMMAND */
269 p_audio_gbl_var->tones.state = AUDIO_TONES_WAIT_STOP_COMMAND;
270 break;
271 }
272 case AUDIO_TONES_STOP_REQ:
273 /*.Before stopping this task, control that */
274 /* stop task id caller = Tones task id */
275 {
276 if ( p_audio_gbl_var->tones.task_id == p_message->src_addr_id)
277 {
278 /* change to the state AUDIO_TONES_WAIT_STOP_CONFIRMATION */
279 p_audio_gbl_var->tones.state = AUDIO_TONES_WAIT_START_CON_TO_STOP;
280 }
281 else
282 {
283 /* A stop request from an other task is sent during a start connection */
284 /* event error - send an error message */
285 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_STOP *)(p_message))->return_path);
286
287 audio_tones_error_trace(AUDIO_ERROR_STOP_EVENT);
288 }
289 break;
290 }
291 case AUDIO_TONES_START_REQ:
292 {
293 /* event error - send an error message*/
294 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_START *)(p_message))->return_path);
295
296 audio_tones_error_trace(AUDIO_ERROR_START_EVENT);
297 break;
298 }
299 }
300 break;
301 } /* case AUDIO_TONES_WAIT_START_CON */
302
303 case AUDIO_TONES_WAIT_START_CON_TO_STOP:
304 {
305 switch(p_message->msg_id)
306 {
307 case MMI_TONE_START_CON:
308 {
309 /* allocate the buffer for the message to the L1 */
310 p_send_message = audio_allocate_l1_message(0);
311 if (p_send_message != NULL)
312 {
313 /* send the start command to the audio L1 */
314 audio_send_l1_message(MMI_TONE_STOP_REQ, p_send_message);
315 }
316
317 /* change to the state AUDIO_TONES_WAIT_STOP_CON */
318 p_audio_gbl_var->tones.state = AUDIO_TONES_WAIT_STOP_CON;
319 break;
320 }
321 case AUDIO_TONES_START_REQ:
322 {
323 /* event error - send an error message*/
324 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_START *)(p_message))->return_path);
325
326 audio_tones_error_trace(AUDIO_ERROR_START_EVENT);
327 break;
328 }
329 case AUDIO_TONES_STOP_REQ:
330 {
331 /* event error - send an error message*/
332 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_STOP *)(p_message))->return_path);
333
334 audio_tones_error_trace(AUDIO_ERROR_STOP_EVENT);
335 break;
336 }
337 }
338 break;
339 }
340
341 case AUDIO_TONES_WAIT_STOP_COMMAND:
342 {
343 switch(p_message->msg_id)
344 {
345 case MMI_TONE_STOP_CON:
346 {
347 audio_tones_send_status (AUDIO_OK, p_audio_gbl_var->tones.return_path);
348
349 /* change to the state AUDIO_TONES_IDLE */
350 p_audio_gbl_var->tones.state = AUDIO_TONES_IDLE;
351 break;
352 }
353
354 case AUDIO_TONES_STOP_REQ:
355 {
356 /* A stop request is sent during a stop connection */
357 /* Save the addr id of the entity */
358 p_audio_gbl_var->tones.task_id = p_message->src_addr_id;
359
360 /*.Control that (stop task id caller = tones task id) and stop the task */
361 if ( p_audio_gbl_var->tones.task_id == p_message->src_addr_id)
362 {
363 /* allocate the buffer for the message to the L1 */
364 p_send_message = audio_allocate_l1_message(0);
365 if (p_send_message != NULL)
366 {
367 /* send the start command to the audio L1 */
368 audio_send_l1_message(MMI_TONE_STOP_REQ, p_send_message);
369 }
370
371 /* change to the state AUDIO_TONES_WAIT_STOP_CONFIRMATION */
372 p_audio_gbl_var->tones.state = AUDIO_TONES_WAIT_STOP_CON;
373 }
374 else
375 {
376 /* A stop request from an other task is sent during a stop connection */
377 /* event error - send an error message */
378 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_STOP *)(p_message))->return_path);
379
380 audio_tones_error_trace(AUDIO_ERROR_STOP_EVENT);
381 }
382 break;
383 }
384
385 case AUDIO_TONES_START_REQ:
386 {
387 /* event error - send an error message*/
388 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_START *)(p_message))->return_path);
389
390 audio_tones_error_trace(AUDIO_ERROR_START_EVENT);
391 break;
392 }
393 }
394 break;
395 } /* case AUDIO_TONES_WAIT_STOP_COMMAND */
396
397 case AUDIO_TONES_WAIT_STOP_CON:
398 {
399 switch(p_message->msg_id)
400 {
401 case MMI_TONE_STOP_CON:
402 {
403 audio_tones_send_status (AUDIO_OK, p_audio_gbl_var->tones.return_path);
404
405 /* change to the state AUDIO_TONES_IDLE */
406 p_audio_gbl_var->tones.state = AUDIO_TONES_IDLE;
407 break;
408 }
409 case AUDIO_TONES_STOP_REQ:
410 {
411 /* event error - send an error message*/
412 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_STOP *)(p_message))->return_path);
413
414 audio_tones_error_trace(AUDIO_ERROR_STOP_EVENT);
415 break;
416 }
417 case AUDIO_TONES_START_REQ:
418 {
419 /* event error - send an error message*/
420 audio_tones_send_status (AUDIO_ERROR, ((T_AUDIO_TONES_START *)(p_message))->return_path);
421
422 audio_tones_error_trace(AUDIO_ERROR_START_EVENT);
423 break;
424 }
425 }
426 break;
427 } /* case AUDIO_TONES_WAIT_STOP_CON */
428
429 } /* switch(p_audio_gbl_var->tones.state) */
430 } /*********************** End of audio_tones_manager function **********************/
431
432 #endif /* #if (TONE) */
433 #endif /* #ifdef RVM_AUDIO_MAIN_SWE */