comparison src/cs/services/audio/audio_midi.c @ 0:92470e5d0b9e

src: partial import from FC Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 May 2020 01:28:16 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92470e5d0b9e
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_midi.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage MIDI */
6 /* */
7 /* Version 0.1 */
8 /* */
9 /* Date Modification */
10 /* ------------------------------------ */
11 /* 11 June 2003 Create */
12 /* */
13 /* Author */
14 /* Fabrice Goucem */
15 /* */
16 /* (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved*/
17 /****************************************************************************/
18
19 #include "rv/rv_defined_swe.h"
20 #ifdef RVM_AUDIO_MAIN_SWE
21 #ifndef _WINDOWS
22 #include "config/swconfig.cfg"
23 #include "config/sys.cfg"
24 #include "config/chipset.cfg"
25 #endif
26
27 // include the usefull L1 header
28 #include "l1_confg.h"
29
30 #include "rv/rv_general.h"
31 #include "rvm/rvm_gen.h"
32 #include "audio/audio_features_i.h"
33 #include "audio/audio_ffs_i.h"
34 #include "audio/audio_api.h"
35 #include "audio/audio_structs_i.h"
36 #include "audio/audio_var_i.h"
37 #include "audio/audio_messages_i.h"
38 #include "rvf/rvf_target.h"
39 #include "audio/audio_const_i.h"
40 #include "audio/audio_error_hdlr_i.h"
41 #include "audio/audio_macro_i.h"
42
43 // include the useful L1 header
44 #define BOOL_FLAG
45 #define CHAR_FLAG
46 #include "l1_types.h"
47 #include "l1audio_cust.h"
48 #include "l1audio_msgty.h"
49 #include "l1audio_signa.h"
50
51
52 /********************************************************************************/
53 /* */
54 /* Function Name: audio_midi_start */
55 /* */
56 /* Purpose: This function is called to initiate a MIDI file playback */
57 /* */
58 /* Input Parameters: */
59 /* Midi file parameters, */
60 /* Return path. */
61 /* */
62 /* Output Parameters: */
63 /* Validation of the MIDI parameters. */
64 /* */
65 /* Note: */
66 /* None. */
67 /* */
68 /* Revision History: */
69 /* None. */
70 /* */
71 /********************************************************************************/
72 T_AUDIO_RET audio_midi_start(T_AUDIO_MIDI_PARAMETER *parameter, T_RV_RETURN *p_return_path)
73 {
74 #if (L1_MIDI==1)
75 // Declare local variables
76 T_RVF_MB_STATUS mb_status=RVF_GREEN;
77 T_AUDIO_MIDI_START *p_msg_start=NULL;
78 T_FFS_FD ffs_fd;
79
80 /************************ audio_midi_start function begins ******************/
81
82 if(p_audio_gbl_var==NULL)
83 {
84 audio_midi_error_trace(AUDIO_ENTITY_NOT_START);
85 return(AUDIO_ERROR);
86 }
87
88 // check if the midi file exists
89 #ifndef _WINDOWS
90 ffs_fd=ffs_open(parameter->midi_name,FFS_O_RDONLY);
91 if(ffs_fd<=0)
92 {
93 audio_midi_error_trace(AUDIO_ENTITY_FILE_ERROR);
94 return(AUDIO_ERROR);
95 }
96 #else
97 ffs_fd=0xdeadbeef;
98 #endif // _WINDOWS
99
100 // allocate the memory for the message to send
101 mb_status=rvf_get_buf(p_audio_gbl_var->mb_external,
102 sizeof(T_AUDIO_MIDI_START),
103 (T_RVF_BUFFER **)(&p_msg_start));
104
105 // If insufficient resources, then report a memory error and abort
106 if(mb_status==RVF_YELLOW)
107 {
108 // deallocate the memory
109 rvf_free_buf((T_RVF_BUFFER *)p_msg_start);
110 audio_midi_error_trace(AUDIO_ENTITY_NO_MEMORY);
111 #ifndef _WINDOWS
112 ffs_close(ffs_fd);
113 #endif
114 return(AUDIO_ERROR);
115 }
116 else
117 {
118 if(mb_status==RVF_RED)
119 {
120 audio_midi_error_trace(AUDIO_ENTITY_NO_MEMORY);
121 #ifndef _WINDOWS
122 ffs_close(ffs_fd);
123 #endif
124 return (AUDIO_ERROR);
125 }
126 }
127
128 // fill the message id
129 p_msg_start->os_hdr.msg_id=AUDIO_MIDI_START_REQ;
130
131 // fill the address source id
132 p_msg_start->os_hdr.src_addr_id =rvf_get_taskid();
133 p_msg_start->os_hdr.dest_addr_id=p_audio_gbl_var->addrId;
134
135 // fill the message parameters
136 p_msg_start->audio_ffs_fd=ffs_fd;
137
138 if(p_return_path->callback_func==NULL)
139 {
140 p_msg_start->return_path.addr_id=p_return_path->addr_id;
141 p_msg_start->return_path.callback_func=NULL;
142 }
143 else
144 p_msg_start->return_path.callback_func=p_return_path->callback_func;
145
146 // send the messsage to the audio entity
147 rvf_send_msg(p_audio_gbl_var->addrId,p_msg_start);
148
149 return(AUDIO_OK);
150 #else // L1_MIDI==1
151 AUDIO_SEND_TRACE("MIDI not compiled",RV_TRACE_LEVEL_DEBUG_LOW);
152 return(AUDIO_ERROR);
153 #endif // L1_MIDI==1
154 } /*********************** End of audio_midi_start function ******************/
155
156
157 /********************************************************************************/
158 /* */
159 /* Function Name: audio_midi_stop */
160 /* */
161 /* Purpose: This function is called to stop MIDI file playback */
162 /* */
163 /* Input Parameters: */
164 /* Return path. */
165 /* */
166 /* Output Parameters: */
167 /* None. */
168 /* */
169 /* Note: */
170 /* None. */
171 /* */
172 /* Revision History: */
173 /* None. */
174 /* */
175 /********************************************************************************/
176 T_AUDIO_RET audio_midi_stop(void)
177 {
178 #if (L1_MIDI==1)
179 // Declare local variables
180 T_RVF_MB_STATUS mb_status =RVF_GREEN;
181 T_AUDIO_MIDI_STOP *p_msg_stop=NULL;
182
183 /************************ audio_midi_stop function begins ****************/
184
185 if(p_audio_gbl_var==NULL)
186 {
187 audio_midi_error_trace(AUDIO_ENTITY_NOT_START);
188 return(AUDIO_ERROR);
189 }
190
191 // allocate the memory for the message to send
192 mb_status=rvf_get_buf(p_audio_gbl_var->mb_external,
193 sizeof(T_AUDIO_MIDI_STOP),
194 (T_RVF_BUFFER **)(&p_msg_stop));
195
196 // If insufficient resources, then report a memory error and abort
197 if(mb_status==RVF_YELLOW)
198 {
199 // deallocate the memory
200 rvf_free_buf((T_RVF_BUFFER *)p_msg_stop);
201 audio_midi_error_trace(AUDIO_ENTITY_NO_MEMORY);
202 return(AUDIO_ERROR);
203 }
204 else
205 {
206 if(mb_status==RVF_RED)
207 {
208 audio_midi_error_trace(AUDIO_ENTITY_NO_MEMORY);
209 return(AUDIO_ERROR);
210 }
211 }
212
213 // fill the message id
214 p_msg_stop->os_hdr.msg_id=AUDIO_MIDI_STOP_REQ;
215
216 // fill the address source id
217 p_msg_stop->os_hdr.src_addr_id =rvf_get_taskid();
218 p_msg_stop->os_hdr.dest_addr_id=p_audio_gbl_var->addrId;
219
220 // send the messsage to the audio entity
221 rvf_send_msg(p_audio_gbl_var->addrId,p_msg_stop);
222
223 return(AUDIO_OK);
224 #else // L1_MIDI==1
225 AUDIO_SEND_TRACE("MIDI not compiled",RV_TRACE_LEVEL_DEBUG_LOW);
226 return(AUDIO_ERROR);
227 #endif // L1_MIDI==1
228 } /*********************** End of audio_midi_stop function *******************/
229
230 #if (L1_MIDI == 1)
231
232 /********************************************************************************/
233 /* */
234 /* Function Name: audio_midi_message_switch */
235 /* */
236 /* Purpose: Manage the message supply */
237 /* */
238 /* Input Parameters: */
239 /* start or stop message from midi features */
240 /* */
241 /* Output Parameters: */
242 /* index of the manager */
243 /* */
244 /* Note: */
245 /* None. */
246 /* */
247 /* Revision History: */
248 /* None. */
249 /* */
250 /********************************************************************************/
251 UINT8 audio_midi_message_switch(T_RV_HDR *p_message)
252 {
253 switch(p_message->msg_id)
254 {
255 case AUDIO_MIDI_START_REQ:
256 case AUDIO_MIDI_STOP_REQ:
257 return(AUDIO_MIDI);
258 break;
259
260 // driver init => check session_id is MIDI
261 case AUDIO_DRIVER_INIT_STATUS_MSG:
262 {
263 UINT8 session_id=((T_AUDIO_DRIVER_INIT_STATUS *)p_message)->session_id;
264
265 // session_id is MIDI
266 if((session_id==AUDIO_MIDI_SESSION_ID) && (p_audio_gbl_var->midi.state!=AUDIO_IDLE))
267 return(AUDIO_MIDI);
268 else
269 return(AUDIO_MIDI_NONE);
270 }
271 break;
272
273 case AUDIO_DRIVER_NOTIFICATION_MSG:
274 {
275 UWORD8 channel_id;
276 channel_id=((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id;
277 if((channel_id==p_audio_gbl_var->midi.channel_id) && (p_audio_gbl_var->midi.state>AUDIO_WAIT_CHANNEL_ID))
278 return(AUDIO_MIDI);
279 else
280 return(AUDIO_MIDI_NONE);
281 }
282 break;
283
284 case AUDIO_DRIVER_STATUS_MSG:
285 {
286 UWORD8 channel_id;
287 channel_id=((T_AUDIO_DRIVER_STATUS *)p_message)->channel_id;
288 if((channel_id==p_audio_gbl_var->midi.channel_id) && (p_audio_gbl_var->midi.state>AUDIO_WAIT_CHANNEL_ID))
289 return(AUDIO_MIDI);
290 else
291 return(AUDIO_MIDI_NONE);
292 }
293 break;
294
295 default:
296 return(AUDIO_MIDI_NONE);
297 break;
298 } // switch
299 }
300
301
302 /********************************************************************************/
303 /* */
304 /* Function Name: audio_midi_send_status */
305 /* */
306 /* Purpose: This function sends the MIDI play status to the entity */
307 /* */
308 /* Input Parameters: */
309 /* status, */
310 /* return path */
311 /* */
312 /* Output Parameters: */
313 /* None. */
314 /* */
315 /* Note: */
316 /* None. */
317 /* */
318 /* Revision History: */
319 /* None. */
320 /* */
321 /********************************************************************************/
322 void audio_midi_send_status(T_AUDIO_RET status, T_RV_RETURN *return_path)
323 {
324 T_AUDIO_MIDI_STATUS *p_send_message;
325 T_RVF_MB_STATUS mb_status=RVF_RED;
326
327 // allocate the message buffer
328 while(mb_status==RVF_RED)
329 {
330 mb_status=rvf_get_buf(p_audio_gbl_var->mb_external,
331 sizeof(T_AUDIO_MIDI_STATUS),
332 (T_RVF_BUFFER **)(&p_send_message));
333
334 // If insufficient resources, then report a memory error and abort
335 // and wait until more ressource is given
336 if(mb_status==RVF_RED)
337 {
338 audio_midi_error_trace(AUDIO_ENTITY_NO_MEMORY);
339 rvf_delay(RVF_MS_TO_TICKS(1000));
340 }
341 }
342
343 // fill the header of the message
344 p_send_message->os_hdr.msg_id=AUDIO_MIDI_STATUS_MSG;
345
346 // fill the status parameters
347 p_send_message->status=status;
348
349 // send message or call callback
350 if(return_path->callback_func==NULL)
351 {
352 rvf_send_msg(return_path->addr_id,p_send_message);
353 }
354 else
355 {
356 (*(return_path->callback_func))((void *)p_send_message);
357 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
358 }
359 }
360
361
362
363 /********************************************************************************/
364 /* */
365 /* Function Name: audio_midi_manager */
366 /* */
367 /* Purpose: This function is called to manage a MIDI play manager */
368 /* */
369 /* Input Parameters: */
370 /* Message to the audio entity */
371 /* */
372 /* Output Parameters: */
373 /* None. */
374 /* */
375 /* Note: */
376 /* None. */
377 /* */
378 /* Revision History: */
379 /* None. */
380 /* */
381 /********************************************************************************/
382 void audio_midi_manager(T_RV_HDR *p_message)
383 {
384 // Declare local variables
385 T_RV_HDR *p_send_message;
386 T_RVF_MB_STATUS mb_status;
387 T_RV_RETURN return_path;
388
389 // initialize the return path
390 return_path.callback_func=NULL;
391 return_path.addr_id=p_audio_gbl_var->addrId;
392
393 /**************** audio_midi_manager function begins ***********************/
394 switch(p_audio_gbl_var->midi.state)
395 {
396 case AUDIO_IDLE:
397 {
398 switch(p_message->msg_id)
399 {
400 case AUDIO_MIDI_START_REQ:
401 {
402 T_AUDIO_DRIVER_PARAMETER driver_parameter;
403 p_audio_gbl_var->midi.stop_req_allowed=TRUE;
404
405 // save the return path + ffs_fd
406 p_audio_gbl_var->midi.return_path.callback_func=((T_AUDIO_MIDI_START *)p_message)->return_path.callback_func;
407 p_audio_gbl_var->midi.return_path.addr_id=((T_AUDIO_MIDI_START *)p_message)->return_path.addr_id;
408 p_audio_gbl_var->midi.ffs_fd=((T_AUDIO_MIDI_START *)p_message)->audio_ffs_fd;
409
410 // driver parameters
411 driver_parameter.nb_buffer = AUDIO_MIDI_NB_BUFFER;
412 driver_parameter.buffer_size = AUDIO_MIDI_SIZE; // 16 bit words
413
414 // return_path for driver
415 return_path.callback_func = NULL;
416 return_path.addr_id = p_audio_gbl_var->addrId;
417
418 // init driver
419 audio_driver_init_midi_session(&driver_parameter,&return_path);
420
421 p_audio_gbl_var->midi.state=AUDIO_WAIT_CHANNEL_ID;
422 }
423 break;
424 case AUDIO_MIDI_STOP_REQ:
425 {
426 audio_midi_error_trace(AUDIO_ERROR_STOP_EVENT);
427 // do not send a status message because of pre-emption issues
428 // An automatic stop can pre-empt a stop request. A status is sent + back in state idle
429 // then the stop request is received and another status is sent, which can be misinterpreted
430 }
431 break;
432 }
433 }
434 break; // AUDIO_IDLE
435
436 case AUDIO_WAIT_CHANNEL_ID:
437 {
438 switch(p_message->msg_id)
439 {
440 case AUDIO_DRIVER_INIT_STATUS_MSG:
441 {
442 UINT8 *play_buffer;
443 INT16 size_read;
444
445 // check init is successfull otherwise, send status AUDIO_ERROR
446 if(((T_AUDIO_DRIVER_INIT_STATUS *)p_message)->status==AUDIO_OK)
447 {
448 // get channel id
449 p_audio_gbl_var->midi.channel_id=((T_AUDIO_DRIVER_INIT_STATUS *)p_message)->channel_id;
450
451 // initializations
452 p_audio_gbl_var->midi.size = AUDIO_MIDI_SIZE << 1;
453 p_audio_gbl_var->midi.stop_req_allowed=TRUE;
454
455 // fill all buffers in advance
456 while(audio_driver_get_play_buffer(p_audio_gbl_var->midi.channel_id,&play_buffer)==AUDIO_OK)
457 {
458 // write from FLASH to RAM buffer
459 if(p_audio_gbl_var->midi.ffs_fd!=NULL)
460 {
461 #ifndef _WINDOWS
462 size_read=ffs_read(p_audio_gbl_var->midi.ffs_fd,play_buffer,p_audio_gbl_var->midi.size);
463 #else
464 size_read=p_audio_gbl_var->midi.size;
465 #endif
466 if(size_read<EFFS_OK)
467 {
468 #ifndef _WINDOWS
469 if(ffs_close(p_audio_gbl_var->midi.ffs_fd)!=EFFS_OK)
470 audio_mem_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
471 #endif
472 AUDIO_SEND_TRACE("AUDIO MIDI: FFS PLAY READ failed",RV_TRACE_LEVEL_DEBUG_LOW);
473 audio_mem_send_status(AUDIO_ERROR,p_audio_gbl_var->midi.channel_id,AUDIO_START_STATUS,return_path);
474 return;
475 }
476 }
477
478 AUDIO_SEND_TRACE_PARAM("AUDIO MIDI: size read",size_read,RV_TRACE_LEVEL_DEBUG_LOW);
479
480 audio_driver_play_buffer(p_audio_gbl_var->midi.channel_id,play_buffer);
481 }
482
483 // send message
484 audio_driver_start_session(p_audio_gbl_var->midi.channel_id,return_path);
485
486 // change state
487 p_audio_gbl_var->midi.state=AUDIO_WAIT_STOP;
488 }
489 else
490 {
491 audio_midi_error_trace(AUDIO_ERROR_START_EVENT);
492 audio_midi_send_status(AUDIO_ERROR, &p_audio_gbl_var->midi.return_path);
493 // change state
494 p_audio_gbl_var->midi.state=AUDIO_IDLE;
495 }
496 }
497 break;
498 case AUDIO_MIDI_STOP_REQ:
499 // change state
500 p_audio_gbl_var->midi.state=AUDIO_WAIT_CHANNEL_ID_TO_STOP;
501 break;
502 }
503 } // case AUDIO_WAIT_CHANNEL_ID:
504 break;
505
506 case AUDIO_WAIT_STOP:
507 {
508 switch(p_message->msg_id)
509 {
510 case AUDIO_DRIVER_NOTIFICATION_MSG:
511 {
512 UINT8 *play_buffer;
513 INT16 size_read;
514
515 // try to get a buffer
516 if(audio_driver_get_play_buffer(p_audio_gbl_var->midi.channel_id,&play_buffer)==AUDIO_OK)
517 {
518 #ifndef _WINDOWS
519 size_read=ffs_read(p_audio_gbl_var->midi.ffs_fd,play_buffer,p_audio_gbl_var->midi.size);
520 #else
521 size_read=p_audio_gbl_var->midi.size;
522 #endif
523 if(size_read<EFFS_OK)
524 {
525 AUDIO_SEND_TRACE("AUDIO MIDI: FFS PLAY READ FILED",RV_TRACE_LEVEL_DEBUG_LOW);
526 size_read=0; // will put END_MASK in whole buffer so stops play
527 }
528 audio_driver_play_buffer(p_audio_gbl_var->midi.channel_id,play_buffer);
529
530 if(size_read>0)
531 AUDIO_SEND_TRACE_PARAM("AUDIO MIDI: size read",size_read,RV_TRACE_LEVEL_DEBUG_LOW);
532 else
533 AUDIO_SEND_TRACE("AUDIO MIDI: buffer not used",RV_TRACE_LEVEL_DEBUG_LOW);
534 } // if(audio_driver_get_play_buffer(channel_id,&p_buffer)==AUDIO_OK)
535 else
536 AUDIO_SEND_TRACE("AUDIO MIDI: no buffer available",RV_TRACE_LEVEL_DEBUG_LOW);
537 }
538 break; // case AUDIO_DRIVER_NOTIFICATION_MSG
539
540 case AUDIO_MIDI_STOP_REQ:
541 if(p_audio_gbl_var->midi.stop_req_allowed==TRUE)
542 {
543 p_audio_gbl_var->midi.stop_req_allowed=FALSE;
544 audio_driver_stop_session(p_audio_gbl_var->midi.channel_id);
545 }
546 else
547 AUDIO_SEND_TRACE("AUDIO MIDI: second stop request received",RV_TRACE_LEVEL_WARNING);
548 break;
549
550 case AUDIO_DRIVER_STATUS_MSG:
551 if(p_audio_gbl_var->midi.ffs_fd!=NULL)
552 {
553 #ifndef _WINDOWS
554 if(ffs_close(p_audio_gbl_var->midi.ffs_fd)!=EFFS_OK) audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
555 #endif
556 AUDIO_SEND_TRACE("AUDIO MIDI: close FFS file", RV_TRACE_LEVEL_DEBUG_LOW);
557 }
558 audio_midi_send_status(AUDIO_OK,&p_audio_gbl_var->midi.return_path);
559 p_audio_gbl_var->midi.state=AUDIO_IDLE;
560 break;
561 }
562 }
563 break; // WAIT_STOP
564
565 case AUDIO_WAIT_CHANNEL_ID_TO_STOP:
566 {
567 switch(p_message->msg_id)
568 {
569 case AUDIO_DRIVER_INIT_STATUS_MSG:
570 {
571 if(((T_AUDIO_DRIVER_INIT_STATUS *)p_message)->status==AUDIO_OK)
572 {
573 // get channel_id
574 p_audio_gbl_var->midi.channel_id=((T_AUDIO_DRIVER_INIT_STATUS *)p_message)->channel_id;
575
576 audio_driver_stop_session(p_audio_gbl_var->midi.channel_id);
577
578 // change state
579 p_audio_gbl_var->midi.state=AUDIO_WAIT_DRIVER_STOP_CON;
580 }
581 else
582 {
583 // close file
584 if(p_audio_gbl_var->midi.ffs_fd!=NULL)
585 {
586 #ifndef _WINDOWS
587 if(ffs_close(p_audio_gbl_var->midi.ffs_fd)!=EFFS_OK) audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
588 #endif
589 AUDIO_SEND_TRACE("AUDIO MIDI: close FFS file:",RV_TRACE_LEVEL_DEBUG_LOW);
590 }
591
592 audio_midi_send_status(AUDIO_OK,&p_audio_gbl_var->midi.return_path);
593
594 // change state
595 p_audio_gbl_var->midi.state=AUDIO_IDLE;
596 }
597 }
598 break;
599 case AUDIO_MIDI_STOP_REQ:
600 audio_midi_error_trace(AUDIO_ERROR_STOP_EVENT);
601 break;
602 }
603 } // case AUDIO_WAIT_CHANNEL_ID_TO_STOP:
604 break;
605 case AUDIO_WAIT_DRIVER_STOP_CON:
606 {
607 switch(p_message->msg_id)
608 {
609 case AUDIO_DRIVER_STATUS_MSG:
610 {
611 if(((T_AUDIO_DRIVER_STATUS *)p_message)->status_type==AUDIO_STOP_STATUS)
612 {
613 // close file
614 if(p_audio_gbl_var->midi.ffs_fd!=NULL)
615 {
616 #ifndef _WINDOWS
617 if(ffs_close(p_audio_gbl_var->midi.ffs_fd)!=EFFS_OK) audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
618 #endif
619 AUDIO_SEND_TRACE("AUDIO MIDI: close FFS file",RV_TRACE_LEVEL_DEBUG_LOW);
620 }
621
622 audio_midi_send_status(((T_AUDIO_DRIVER_STATUS *)p_message)->status,
623 &p_audio_gbl_var->midi.return_path);
624 p_audio_gbl_var->midi.state=AUDIO_IDLE;
625 }
626 }
627 break;
628 case AUDIO_MIDI_STOP_REQ:
629 audio_midi_error_trace(AUDIO_ERROR_STOP_EVENT);
630 break;
631 }
632 } //case AUDIO_WAIT_DRIVER_STOP_CON:
633 break;
634 }
635 } /*********************** End of audio_midi_manager function **********************/
636
637 /********************************************************************************/
638 /* */
639 /* Function Name: audio_driver_midi_manager */
640 /* */
641 /* Purpose: This function is called to manage a MIDI manager */
642 /* */
643 /* Input Parameters: */
644 /* Message to the audio entity */
645 /* */
646 /* Output Parameters: */
647 /* None. */
648 /* */
649 /* Note: */
650 /* None. */
651 /* */
652 /* Revision History: */
653 /* None. */
654 /* */
655 /********************************************************************************/
656 T_AUDIO_RET audio_driver_midi_manager(T_RV_HDR *p_message, T_AUDIO_DRIVER_SESSION *p_session)
657 {
658 /**************** audio_driver_midi_manager function begins ***********************/
659 switch(p_session->session_info.state)
660 {
661 case AUDIO_DRIVER_CHANNEL_WAIT_INIT:
662 // init buffer index, layer1 not valid until 1st buffer is filled
663 // index_l1 will be set to 0 when get_play_buffer() is called in WAIT_START state
664 p_session->session_info.index_l1 = 0xFF;
665 p_session->session_info.index_appli = 0;
666 p_session->session_info.play_api_state = AUDIO_PLAY_API_STATE_GET_BUF;
667
668 // allocate the buffer for the message to the L1
669 p_session->session_req.p_l1_send_message=audio_allocate_l1_message(sizeof(T_MMI_MIDI_REQ));
670 ((T_MMI_MIDI_REQ *)(p_session->session_req.p_l1_send_message))->session_id=AUDIO_MIDI_SESSION_ID;
671
672 if(p_session->session_req.p_l1_send_message!=NULL)
673 return(AUDIO_OK);
674 else
675 return(AUDIO_ERROR);
676 break;
677
678 case AUDIO_DRIVER_CHANNEL_WAIT_START:
679 // send the start midi message to the L1
680 audio_send_l1_message(MMI_MIDI_START_REQ,p_session->session_req.p_l1_send_message);
681 return(AUDIO_OK);
682 break;
683
684 case AUDIO_DRIVER_CHANNEL_WAIT_STOP:
685 {
686 // send the stop command to the audio L1
687 void *p_send_message=audio_allocate_l1_message(0);
688 if(p_send_message!=NULL)
689 {
690 // send the stop command to the audio L1
691 audio_send_l1_message(MMI_MIDI_STOP_REQ,p_send_message);
692 return(AUDIO_OK);
693 }
694 return(AUDIO_ERROR);
695 }
696 break;
697 case AUDIO_DRIVER_CHANNEL_WAIT_START_CON_TO_STOP:
698 {
699 // send the stop command to the audio L1
700 void *p_send_message=audio_allocate_l1_message(0);
701 if(p_send_message!=NULL)
702 {
703 // send the stop command to the audio L1
704 audio_send_l1_message(MMI_MIDI_STOP_REQ,p_send_message);
705 return(AUDIO_OK);
706 }
707 return(AUDIO_ERROR);
708 }
709 break;
710 }
711 } /*********************** End of audio_driver_midi_manager function **********************/
712
713
714 /********************************************************************************/
715 /* */
716 /* Function Name: audio_driver_init_midi_session */
717 /* */
718 /* Purpose: This function is called in order to initialize MIDI */
719 /* */
720 /* Input Parameters: */
721 /* Specific MIDI parameters */
722 /* Driver parameters */
723 /* Return path */
724 /* */
725 /* Output Parameters: */
726 /* Validation of the parameters */
727 /* */
728 /* Note: */
729 /* None. */
730 /* */
731 /* Revision History: */
732 /* None. */
733 /* */
734 /********************************************************************************/
735 T_AUDIO_RET audio_driver_init_midi_session(T_AUDIO_DRIVER_PARAMETER *p_driver_parameter, T_RV_RETURN *p_return_path)
736 {
737 #if (L1_MIDI==1)
738 /* Declare local variables. */
739 T_RVF_MB_STATUS mb_status = RVF_GREEN;
740 T_AUDIO_DRIVER_INIT_MIDI_SESSION *p_msg = NULL;
741
742 /************************ audio_keybeep_stop function begins ****************/
743
744 if (p_audio_gbl_var == NULL )
745 {
746 audio_driver_error_trace(AUDIO_ENTITY_NOT_START);
747 return(AUDIO_ERROR);
748 }
749
750 /* If bad parameters report an error and abort.*/
751 if(p_driver_parameter->nb_buffer<2)
752 {
753 audio_driver_error_trace(AUDIO_ENTITY_BAD_PARAMETER);
754 return (AUDIO_ERROR);
755 }
756
757 /* allocate the memory for the message to send */
758 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
759 sizeof (T_AUDIO_DRIVER_INIT_MIDI_SESSION),
760 (T_RVF_BUFFER **) (&p_msg));
761
762 /* If insufficient resources, then report a memory error and abort. */
763 if (mb_status == RVF_YELLOW)
764 {
765 /* deallocate the memory */
766 rvf_free_buf((T_RVF_BUFFER *)p_msg);
767 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY);
768 return (AUDIO_ERROR);
769 }
770 else
771 if (mb_status == RVF_RED)
772 {
773 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY);
774 return (AUDIO_ERROR);
775 }
776
777 /* fill the message id */
778 p_msg->os_hdr.msg_id = AUDIO_DRIVER_INIT_MIDI_SESSION;
779 p_msg->os_hdr.dest_addr_id = p_audio_gbl_var->addrId;
780
781 /* fill parameters */
782 p_msg->driver_parameter.buffer_size = p_driver_parameter->buffer_size;
783 p_msg->driver_parameter.nb_buffer = p_driver_parameter->nb_buffer;
784
785 if (p_return_path->callback_func == NULL)
786 {
787 p_msg->return_path.addr_id = p_return_path->addr_id;
788 p_msg->return_path.callback_func = NULL;
789 }
790 else
791 p_msg->return_path.callback_func = p_return_path->callback_func;
792
793 /* send the messsage to the audio entity */
794 rvf_send_msg (p_audio_gbl_var->addrId, p_msg);
795
796 return (AUDIO_OK);
797 #else // L1_MIDI==1
798 AUDIO_SEND_TRACE("MIDI not compiled", RV_TRACE_LEVEL_DEBUG_LOW);
799 return (AUDIO_ERROR);
800 #endif // L1_MIDI==1
801 }
802
803
804 /********************************************************************************/
805 /* */
806 /* Function Name: audio_midi_l1_simulator */
807 /* */
808 /* Purpose: This function simulates the L1 for MIDI */
809 /* */
810 /* Input Parameters: */
811 /* event: Event that triggered the function */
812 /* p_msg: Message (if any) associated with the event */
813 /* */
814 /* Note: */
815 /* None. */
816 /* */
817 /* Revision History: */
818 /* None. */
819 /* */
820 /********************************************************************************/
821 void audio_midi_l1_simulator(UINT16 event, T_RV_HDR *p_message)
822 {
823 #ifdef _WINDOWS
824 enum { WAIT_START_REQ, WAIT_STOP };
825
826 T_RVF_MB_STATUS mb_status;
827 T_RV_RETURN *return_path=&(p_audio_gbl_var->audio_driver_session[p_audio_gbl_var->midi.channel_id].session_req.return_path);
828
829 switch(p_audio_gbl_var->midi.l1_state)
830 {
831 case WAIT_START_REQ:
832 if(p_message->msg_id==MMI_MIDI_START_REQ)
833 {
834 rvf_start_timer(AUDIO_MIDI_L1_SIMUL_TIMER,
835 RVF_MS_TO_TICKS(1000),
836 AUDIO_MIDI_L1_SIMUL_ONE_SHOT_TIMER);
837 p_audio_gbl_var->midi.counter=10;
838
839 // send MMI_MIDI_START_CON message to the Riviera audio entity
840 mb_status=rvf_get_buf(p_audio_gbl_var->mb_internal,
841 sizeof(T_AUDIO_DRIVER_NOTIFICATION),
842 (T_RVF_BUFFER **)(&p_message));
843 if(mb_status==RVF_RED)
844 {
845 AUDIO_SEND_TRACE("AUDIO entity has no memory for driver notification",RV_TRACE_LEVEL_ERROR);
846 return;
847 }
848 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->header.msg_id=MMI_MIDI_START_CON;
849 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id=p_audio_gbl_var->midi.channel_id;
850 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer=NULL;
851 if(return_path->callback_func==NULL)
852 rvf_send_msg(return_path->addr_id, p_message);
853 else
854 {
855 (*return_path->callback_func)((void *)(p_message));
856 rvf_free_buf((T_RVF_BUFFER *)p_message);
857 }
858
859 p_audio_gbl_var->midi.l1_state=WAIT_STOP;
860 return;
861 }
862 break;
863
864 case WAIT_STOP:
865 if(event & AUDIO_MIDI_L1_SIMUL_TIMER_EVT_MASK)
866 {
867 p_audio_gbl_var->midi.counter--;
868
869 // switch buffer
870 {
871 T_AUDIO_DRIVER_SESSION *p=&p_audio_gbl_var->audio_driver_session[p_audio_gbl_var->midi.channel_id];
872 p->session_info.index_l1++;
873 if(p->session_info.index_l1==p->session_req.nb_buffer) p->session_info.index_l1=0;
874 }
875
876 // send notification message to the Riviera audio entity
877 mb_status=rvf_get_buf(p_audio_gbl_var->mb_internal,
878 sizeof(T_AUDIO_DRIVER_NOTIFICATION),
879 (T_RVF_BUFFER **)(&p_message));
880 if(mb_status==RVF_RED)
881 {
882 AUDIO_SEND_TRACE("AUDIO entity has no memory for driver notification",RV_TRACE_LEVEL_ERROR);
883 return;
884 }
885 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->header.msg_id=AUDIO_DRIVER_NOTIFICATION_MSG;
886 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id=p_audio_gbl_var->midi.channel_id;
887 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer=NULL;
888 if(return_path->callback_func==NULL)
889 rvf_send_msg(return_path->addr_id, p_message);
890 else
891 {
892 (*return_path->callback_func)((void *)(p_message));
893 rvf_free_buf((T_RVF_BUFFER *)p_message);
894 }
895
896 // check if we're done with the simulation
897 if(p_audio_gbl_var->midi.counter==0)
898 {
899 rvf_stop_timer(AUDIO_MIDI_L1_SIMUL_TIMER);
900
901 // send MMI_MIDI_STOP_CON message to the Riviera audio entity
902 mb_status=rvf_get_buf(p_audio_gbl_var->mb_internal,
903 sizeof(T_AUDIO_DRIVER_NOTIFICATION),
904 (T_RVF_BUFFER **)(&p_message));
905 if(mb_status==RVF_RED)
906 {
907 AUDIO_SEND_TRACE("AUDIO entity has no memory for driver notification",RV_TRACE_LEVEL_ERROR);
908 return;
909 }
910 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->header.msg_id=MMI_MIDI_STOP_CON;
911 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id=p_audio_gbl_var->midi.channel_id;
912 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer=NULL;
913 if(return_path->callback_func==NULL)
914 rvf_send_msg(return_path->addr_id, p_message);
915 else
916 {
917 (*return_path->callback_func)((void *)(p_message));
918 rvf_free_buf((T_RVF_BUFFER *)p_message);
919 }
920
921 p_audio_gbl_var->midi.l1_state=WAIT_START_REQ;
922 return;
923 }
924 rvf_start_timer(AUDIO_MIDI_L1_SIMUL_TIMER,
925 RVF_MS_TO_TICKS(1000),
926 AUDIO_MIDI_L1_SIMUL_ONE_SHOT_TIMER);
927 }
928 if(p_message->msg_id==MMI_MIDI_STOP_REQ)
929 {
930 rvf_stop_timer(AUDIO_MIDI_L1_SIMUL_TIMER);
931
932 // send MMI_MIDI_STOP_CON message to the Riviera audio entity
933 mb_status=rvf_get_buf(p_audio_gbl_var->mb_internal,
934 sizeof(T_AUDIO_DRIVER_NOTIFICATION),
935 (T_RVF_BUFFER **)(&p_message));
936 if(mb_status==RVF_RED)
937 {
938 AUDIO_SEND_TRACE("AUDIO entity has no memory for driver notification",RV_TRACE_LEVEL_ERROR);
939 return;
940 }
941 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->header.msg_id=MMI_MIDI_STOP_CON;
942 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id=p_audio_gbl_var->midi.channel_id;
943 ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer=NULL;
944 if(return_path->callback_func==NULL)
945 rvf_send_msg(return_path->addr_id, p_message);
946 else
947 {
948 (*return_path->callback_func)((void *)(p_message));
949 rvf_free_buf((T_RVF_BUFFER *)p_message);
950 }
951
952 p_audio_gbl_var->midi.l1_state=WAIT_START_REQ;
953 return;
954 }
955 break;
956 }
957 #endif // _WINDOWS
958 }
959
960 #endif // #if (L1_MIDI == 1)
961 #endif // #ifdef RVM_AUDIO_MAIN_SWE