blob: 8d3b7987f80d5e52ffa4ecdc16cd2973dc01a057 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2012
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 *
38 * Filename:
39 * ---------
40 * media.c
41 *
42 * Project:
43 * --------
44 * MAUI
45 *
46 * Description:
47 * ------------
48 * Audio Playback/Record general interface
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *==============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 * removed!
71 *
72 * removed!
73 * removed!
74 * removed!
75 *
76 * removed!
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 *
89 * removed!
90 * removed!
91 * removed!
92 *
93 * removed!
94 * removed!
95 * removed!
96 *
97 * removed!
98 * removed!
99 * removed!
100 *
101 * removed!
102 * removed!
103 * removed!
104 *
105 * removed!
106 * removed!
107 * removed!
108 *
109 *------------------------------------------------------------------------------
110 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
111 *==============================================================================
112 *******************************************************************************/
113#include "kal_public_api.h"
114#include "kal_general_types.h"
115#include "kal_public_defs.h"
116#include "reg_base.h"
117#include "fs_type.h"
118#include "kal_trace.h"
119#include "string.h"
120#include "fsal.h"
121#include "audcoeff_default.h"
122
123#include "ddload.h"
124#include "l1audio.h"
125// #include "audio_def.h"
126#include "speech_def.h"
127#include "am.h"
128#include "media.h"
129#include "afe.h"
130#include "audio_enum.h"
131#include "l1sp_trc.h"
132#include "fs_errcode.h"
133
134#if defined(__AUDIO_COMPONENT_SUPPORT__)
135#include "AudComUtil.h"
136#endif
137
138#if VERIFY_DATA_TO_DSP
139extern void VERIFY_DATA_TO_DSP_START( void );
140extern void VERIFY_DATA_TO_DSP_RESUME( void );
141extern void VERIFY_DATA_TO_DSP_STOP( void );
142#endif
143
144
145
146
147/* Functions for Ring Buffer Access */
148#if 0
149/* under construction !*/
150/* under construction !*/
151/* under construction !*/
152/* under construction !*/
153/* under construction !*/
154/* under construction !*/
155/* under construction !*/
156/* under construction !*/
157/* under construction !*/
158/* under construction !*/
159/* under construction !*/
160/* under construction !*/
161/* under construction !*/
162/* under construction !*/
163/* under construction !*/
164/* under construction !*/
165/* under construction !*/
166/* under construction !*/
167/* under construction !*/
168/* under construction !*/
169/* under construction !*/
170/* under construction !*/
171/* under construction !*/
172/* under construction !*/
173/* under construction !*/
174/* under construction !*/
175/* under construction !*/
176/* under construction !*/
177/* under construction !*/
178/* under construction !*/
179/* under construction !*/
180/* under construction !*/
181/* under construction !*/
182/* under construction !*/
183/* under construction !*/
184/* under construction !*/
185/* under construction !*/
186/* under construction !*/
187/* under construction !*/
188/* under construction !*/
189/* under construction !*/
190/* under construction !*/
191/* under construction !*/
192/* under construction !*/
193/* under construction !*/
194/* under construction !*/
195/* under construction !*/
196/* under construction !*/
197/* under construction !*/
198/* under construction !*/
199/* under construction !*/
200/* under construction !*/
201/* under construction !*/
202/* under construction !*/
203/* under construction !*/
204/* under construction !*/
205/* under construction !*/
206/* under construction !*/
207/* under construction !*/
208/* under construction !*/
209/* under construction !*/
210/* under construction !*/
211/* under construction !*/
212/* under construction !*/
213/* under construction !*/
214/* under construction !*/
215/* under construction !*/
216/* under construction !*/
217/* under construction !*/
218/* under construction !*/
219/* under construction !*/
220/* under construction !*/
221/* under construction !*/
222/* under construction !*/
223/* under construction !*/
224/* under construction !*/
225/* under construction !*/
226/* under construction !*/
227/* under construction !*/
228/* under construction !*/
229/* under construction !*/
230/* under construction !*/
231/* under construction !*/
232/* under construction !*/
233/* under construction !*/
234/* under construction !*/
235/* under construction !*/
236/* under construction !*/
237/* under construction !*/
238/* under construction !*/
239/* under construction !*/
240/* under construction !*/
241/* under construction !*/
242/* under construction !*/
243/* under construction !*/
244/* under construction !*/
245/* under construction !*/
246/* under construction !*/
247/* under construction !*/
248/* under construction !*/
249/* under construction !*/
250/* under construction !*/
251/* under construction !*/
252/* under construction !*/
253/* under construction !*/
254/* under construction !*/
255/* under construction !*/
256/* under construction !*/
257/* under construction !*/
258/* under construction !*/
259/* under construction !*/
260/* under construction !*/
261/* under construction !*/
262/* under construction !*/
263/* under construction !*/
264/* under construction !*/
265/* under construction !*/
266/* under construction !*/
267/* under construction !*/
268/* under construction !*/
269/* under construction !*/
270/* under construction !*/
271/* under construction !*/
272/* under construction !*/
273/* under construction !*/
274/* under construction !*/
275/* under construction !*/
276/* under construction !*/
277/* under construction !*/
278/* under construction !*/
279/* under construction !*/
280/* under construction !*/
281/* under construction !*/
282/* under construction !*/
283/* under construction !*/
284/* under construction !*/
285/* under construction !*/
286/* under construction !*/
287/* under construction !*/
288/* under construction !*/
289/* under construction !*/
290/* under construction !*/
291/* under construction !*/
292/* under construction !*/
293/* under construction !*/
294/* under construction !*/
295/* under construction !*/
296/* under construction !*/
297/* under construction !*/
298/* under construction !*/
299/* under construction !*/
300/* under construction !*/
301/* under construction !*/
302/* under construction !*/
303/* under construction !*/
304/* under construction !*/
305/* under construction !*/
306/* under construction !*/
307/* under construction !*/
308/* under construction !*/
309/* under construction !*/
310/* under construction !*/
311/* under construction !*/
312/* under construction !*/
313/* under construction !*/
314/* under construction !*/
315/* under construction !*/
316/* under construction !*/
317/* under construction !*/
318/* under construction !*/
319/* under construction !*/
320/* under construction !*/
321/* under construction !*/
322/* under construction !*/
323/* under construction !*/
324/* under construction !*/
325/* under construction !*/
326/* under construction !*/
327/* under construction !*/
328/* under construction !*/
329/* under construction !*/
330/* under construction !*/
331/* under construction !*/
332/* under construction !*/
333/* under construction !*/
334/* under construction !*/
335/* under construction !*/
336/* under construction !*/
337/* under construction !*/
338/* under construction !*/
339/* under construction !*/
340/* under construction !*/
341/* under construction !*/
342/* under construction !*/
343/* under construction !*/
344/* under construction !*/
345/* under construction !*/
346/* under construction !*/
347/* under construction !*/
348/* under construction !*/
349/* under construction !*/
350/* under construction !*/
351/* under construction !*/
352/* under construction !*/
353/* under construction !*/
354/* under construction !*/
355/* under construction !*/
356/* under construction !*/
357/* under construction !*/
358/* under construction !*/
359/* under construction !*/
360/* under construction !*/
361/* under construction !*/
362/* under construction !*/
363/* under construction !*/
364/* under construction !*/
365/* under construction !*/
366/* under construction !*/
367/* under construction !*/
368/* under construction !*/
369/* under construction !*/
370/* under construction !*/
371/* under construction !*/
372/* under construction !*/
373/* under construction !*/
374/* under construction !*/
375/* under construction !*/
376/* under construction !*/
377/* under construction !*/
378/* under construction !*/
379/* under construction !*/
380/* under construction !*/
381/* under construction !*/
382/* under construction !*/
383/* under construction !*/
384/* under construction !*/
385/* under construction !*/
386/* under construction !*/
387/* under construction !*/
388/* under construction !*/
389/* under construction !*/
390/* under construction !*/
391/* under construction !*/
392/* under construction !*/
393/* under construction !*/
394/* under construction !*/
395/* under construction !*/
396/* under construction !*/
397/* under construction !*/
398/* under construction !*/
399/* under construction !*/
400/* under construction !*/
401/* under construction !*/
402/* under construction !*/
403/* under construction !*/
404/* under construction !*/
405/* under construction !*/
406/* under construction !*/
407/* under construction !*/
408/* under construction !*/
409/* under construction !*/
410/* under construction !*/
411/* under construction !*/
412/* under construction !*/
413/* under construction !*/
414/* under construction !*/
415/* under construction !*/
416/* under construction !*/
417/* under construction !*/
418/* under construction !*/
419/* under construction !*/
420/* under construction !*/
421/* under construction !*/
422/* under construction !*/
423/* under construction !*/
424/* under construction !*/
425/* under construction !*/
426/* under construction !*/
427/* under construction !*/
428/* under construction !*/
429/* under construction !*/
430/* under construction !*/
431/* under construction !*/
432/* under construction !*/
433/* under construction !*/
434/* under construction !*/
435/* under construction !*/
436/* under construction !*/
437/* under construction !*/
438/* under construction !*/
439/* under construction !*/
440/* under construction !*/
441/* under construction !*/
442/* under construction !*/
443/* under construction !*/
444/* under construction !*/
445/* under construction !*/
446/* under construction !*/
447/* under construction !*/
448/* under construction !*/
449/* under construction !*/
450/* under construction !*/
451/* under construction !*/
452/* under construction !*/
453/* under construction !*/
454/* under construction !*/
455/* under construction !*/
456/* under construction !*/
457/* under construction !*/
458/* under construction !*/
459/* under construction !*/
460/* under construction !*/
461/* under construction !*/
462/* under construction !*/
463/* under construction !*/
464/* under construction !*/
465/* under construction !*/
466/* under construction !*/
467/* under construction !*/
468/* under construction !*/
469/* under construction !*/
470/* under construction !*/
471/* under construction !*/
472/* under construction !*/
473/* under construction !*/
474/* under construction !*/
475/* under construction !*/
476/* under construction !*/
477/* under construction !*/
478/* under construction !*/
479/* under construction !*/
480/* under construction !*/
481/* under construction !*/
482/* under construction !*/
483/* under construction !*/
484/* under construction !*/
485/* under construction !*/
486/* under construction !*/
487/* under construction !*/
488/* under construction !*/
489/* under construction !*/
490/* under construction !*/
491/* under construction !*/
492/* under construction !*/
493/* under construction !*/
494/* under construction !*/
495/* under construction !*/
496/* under construction !*/
497/* under construction !*/
498/* under construction !*/
499/* under construction !*/
500/* under construction !*/
501/* under construction !*/
502/* under construction !*/
503/* under construction !*/
504/* under construction !*/
505/* under construction !*/
506/* under construction !*/
507/* under construction !*/
508/* under construction !*/
509/* under construction !*/
510/* under construction !*/
511/* under construction !*/
512/* under construction !*/
513/* under construction !*/
514/* under construction !*/
515/* under construction !*/
516/* under construction !*/
517/* under construction !*/
518/* under construction !*/
519/* under construction !*/
520/* under construction !*/
521/* under construction !*/
522/* under construction !*/
523/* under construction !*/
524/* under construction !*/
525/* under construction !*/
526/* under construction !*/
527/* under construction !*/
528/* under construction !*/
529/* under construction !*/
530/* under construction !*/
531/* under construction !*/
532/* under construction !*/
533/* under construction !*/
534/* under construction !*/
535/* under construction !*/
536/* under construction !*/
537/* under construction !*/
538/* under construction !*/
539/* under construction !*/
540/* under construction !*/
541/* under construction !*/
542/* under construction !*/
543/* under construction !*/
544/* under construction !*/
545/* under construction !*/
546/* under construction !*/
547/* under construction !*/
548/* under construction !*/
549/* under construction !*/
550/* under construction !*/
551/* under construction !*/
552/* under construction !*/
553/* under construction !*/
554/* under construction !*/
555/* under construction !*/
556/* under construction !*/
557/* under construction !*/
558/* under construction !*/
559/* under construction !*/
560/* under construction !*/
561/* under construction !*/
562/* under construction !*/
563/* under construction !*/
564/* under construction !*/
565/* under construction !*/
566/* under construction !*/
567/* under construction !*/
568/* under construction !*/
569/* under construction !*/
570/* under construction !*/
571/* under construction !*/
572/* under construction !*/
573/* under construction !*/
574/* under construction !*/
575/* under construction !*/
576/* under construction !*/
577/* under construction !*/
578/* under construction !*/
579/* under construction !*/
580/* under construction !*/
581/* under construction !*/
582/* under construction !*/
583/* under construction !*/
584/* under construction !*/
585/* under construction !*/
586/* under construction !*/
587/* under construction !*/
588/* under construction !*/
589/* under construction !*/
590/* under construction !*/
591/* under construction !*/
592/* under construction !*/
593/* under construction !*/
594/* under construction !*/
595/* under construction !*/
596/* under construction !*/
597/* under construction !*/
598/* under construction !*/
599/* under construction !*/
600/* under construction !*/
601/* under construction !*/
602/* under construction !*/
603/* under construction !*/
604/* under construction !*/
605/* under construction !*/
606/* under construction !*/
607/* under construction !*/
608/* under construction !*/
609/* under construction !*/
610/* under construction !*/
611/* under construction !*/
612/* under construction !*/
613/* under construction !*/
614/* under construction !*/
615/* under construction !*/
616/* under construction !*/
617/* under construction !*/
618/* under construction !*/
619/* under construction !*/
620/* under construction !*/
621/* under construction !*/
622/* under construction !*/
623/* under construction !*/
624/* under construction !*/
625/* under construction !*/
626/* under construction !*/
627/* under construction !*/
628/* under construction !*/
629/* under construction !*/
630/* under construction !*/
631/* under construction !*/
632/* under construction !*/
633/* under construction !*/
634/* under construction !*/
635/* under construction !*/
636/* under construction !*/
637/* under construction !*/
638/* under construction !*/
639/* under construction !*/
640/* under construction !*/
641/* under construction !*/
642/* under construction !*/
643/* under construction !*/
644/* under construction !*/
645/* under construction !*/
646/* under construction !*/
647/* under construction !*/
648/* under construction !*/
649/* under construction !*/
650/* under construction !*/
651#endif
652
653/* ------------------------------------------------------------------------------ */
654/* Media File Playback/Recording Interface */
655/* ------------------------------------------------------------------------------ */
656// extern void AudioPP_Loudness_Registry( void );
657
658
659/* ------------------------------------------------------------------------------ */
660
661#ifdef PCM_EX_UNIT_TEST
662#include "pcm4way.h"
663static uint32 pcm_ex_test_on = 0;
664static uint16 PCM_BUF[160];
665static uint16 PCM_UL_BUF[8][160];
666static uint16 PCM_DL_BUF[8][160];
667static uint32 pcm_buf_rw;
668
669void pcm4way_hisrHdl()
670{
671 uint32 I;
672 int16 *buf1, *buf2;
673
674 buf1 = (int16*)PCM_UL_BUF[pcm_buf_rw];
675 buf2 = (int16*)PCM_BUF;
676 for(I = 160; I > 0 ; I--)
677 *buf2++ = (*buf1++) >> 2;
678 PCM4WAY_GetFromMic((uint16*)PCM_UL_BUF[pcm_buf_rw]);
679 buf1 = (int16*)PCM_UL_BUF[pcm_buf_rw];
680 buf2 = (int16*)PCM_BUF;
681 for(I = 160; I > 0 ; I--)
682 (*buf2++) += (*buf1++) >> 2 * 3;
683 PCM4WAY_PutToSE((const uint16*)PCM_BUF);
684
685 buf1 = (int16*)PCM_DL_BUF[pcm_buf_rw];
686 buf2 = (int16*)PCM_BUF;
687 for(I = 160; I > 0 ; I--)
688 *buf2++ = (*buf1++) >> 2;
689 PCM4WAY_GetFromSD((uint16*)PCM_DL_BUF[pcm_buf_rw]);
690 buf1 = (int16*)PCM_DL_BUF[pcm_buf_rw];
691 buf2 = (int16*)PCM_BUF;
692 for(I = 160; I > 0 ; I--)
693 (*buf2++) += (*buf1++) >> 2 * 3;
694 PCM4WAY_PutToSpk((const uint16*)PCM_BUF);
695
696 pcm_buf_rw ++;
697 pcm_buf_rw &= 0x7;
698}
699
700void pcm2way_hisrHdl()
701{
702 uint32 I;
703 int16 *buf1, *buf2;
704
705 buf1 = (int16*)PCM_UL_BUF[pcm_buf_rw];
706 buf2 = (int16*)PCM_BUF;
707 for(I = 160; I > 0 ; I--)
708 *buf2++ = (*buf1++) >> 2;
709 PCM2WAY_GetFromMic((uint16*)PCM_UL_BUF[pcm_buf_rw]);
710 buf1 = (int16*)PCM_UL_BUF[pcm_buf_rw];
711 buf2 = (int16*)PCM_BUF;
712 for(I = 160; I > 0 ; I--)
713 (*buf2++) += (*buf1++) >> 2 * 3;
714 PCM2WAY_PutToSpk((const uint16*)PCM_BUF);
715
716 pcm_buf_rw ++;
717 pcm_buf_rw &= 0x7;
718}
719
720#endif
721
722/*
723void Media_MuteSpeaker( bool mute )
724{
725// AFE_MuteSpeaker( L1SP_AUDIO, mute );
726// AFE_MuteSpeaker( L1SP_VOICE, mute );
727}
728*/
729
730/* ------------------------------------------------------------------------------ */
731
732#ifndef __L1_STANDALONE__ // avoid link error
733
734//interface for audiohdl
735void rbGetWriteBuffer( AUD_RB_INFO *rb, kal_uint8 **buffer, kal_uint32 *buf_len )// in bytes
736{
737 int32 count;
738 int32 temp_read = rb->read;
739 int32 temp_write = rb->write;
740 if( temp_read > temp_write )
741 count = temp_read - temp_write - 1;
742 else if( temp_read == 0 )
743 count = rb->rb_size - temp_write - 1;
744 else
745 count = rb->rb_size - temp_write;
746
747 ASSERT( count>=0 );
748 *buffer = (uint8 *)&rb->rb_base[temp_write];
749 *buf_len = count;
750}
751
752void rbGetReadBuffer( AUD_RB_INFO *rb, kal_uint8 **buffer, kal_uint32 *buf_len )// in bytes
753{
754 int32 count;
755 int32 temp_write = rb->write;
756 int32 temp_read = rb->read;
757 if( temp_write >= temp_read )
758 count = temp_write - temp_read;
759 else
760 count = rb->rb_size - temp_read;
761
762 ASSERT( count>=0 );
763 *buffer = (uint8 *)&rb->rb_base[temp_read];
764 *buf_len = count;
765}
766
767void rbReadDataDone( AUD_RB_INFO *rb, kal_uint32 len ) // in bytes
768{
769 int32 temp_read = rb->read;
770 temp_read+= len;
771
772 ASSERT(temp_read <= rb->rb_size);
773 if( temp_read == rb->rb_size )
774 {
775 temp_read = 0;
776 }
777 rb->read = temp_read;
778
779 MD_TRC_L1AUDIO_READ_BYTE(len);
780}
781
782
783void rbWriteDataDone( AUD_RB_INFO *rb, kal_uint32 len ) // in bytes
784{
785 int32 temp_write = rb->write;
786 temp_write += len;
787
788 ASSERT(temp_write <= rb->rb_size);
789 if( temp_write == rb->rb_size )
790 {
791 temp_write = 0;
792 }
793 rb->write = temp_write;
794}
795
796int32 rbGetFreeSpace( AUD_RB_INFO *rb )
797{
798 int32 count;
799
800 count = rb->read - rb->write - 1;
801 if( count < 0 )
802 count += rb->rb_size;
803 return count; // free size in byte
804}
805
806int32 rbGetDataCount( AUD_RB_INFO *rb )
807{
808 return rb->rb_size - rbGetFreeSpace(rb) - 1;
809}
810//interface for audiohdl end
811
812
813#endif // #ifndef __L1_STANDALONE__
814