blob: 7f138224698a0b2c22eb70677560c4f31bbba7a9 [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 * am.c
41 *
42 * Project:
43 * --------
44 * Maui
45 *
46 * Description:
47 * ------------
48 * Audio Manager(AM) for Audio Mode Changes
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *------------------------------------------------------------------------------
55 * removed!
56 * removed!
57 * removed!
58 *
59 * removed!
60 * removed!
61 * removed!
62 *
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 *
71 * removed!
72 * removed!
73 * removed!
74 *
75 * removed!
76 * removed!
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 * removed!
89 *
90>>>> ORIGINAL //VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c#10
91==== THEIRS //VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c#11
92 * removed!
93 * removed!
94 * removed!
95 *
96==== YOURS //ws_thomas.chen_work1/VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c
97>>>> ORIGINAL //VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c#9
98==== THEIRS //VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c#10
99<<<<
100 * removed!
101 * removed!
102 * removed!
103 * removed!
104 *
105 * removed!
106 * removed!
107 * removed!
108 *
109==== YOURS //ws_thomas.chen_work1/VMOLY/TRUNK/VMOLY/mcu/driver/audio/src/v1/am.c
110 * removed!
111 * removed!
112 * removed!
113 * removed!
114 *
115 * removed!
116 * removed!
117 * removed!
118 * removed!
119 *
120 * removed!
121 * removed!
122 * removed!
123 * removed!
124 *
125<<<<
126 * removed!
127 * removed!
128 * removed!
129 * removed!
130 *
131 * removed!
132 * removed!
133 * removed!
134 *
135 * removed!
136 * removed!
137 * removed!
138 *
139 * removed!
140 * removed!
141 * removed!
142 *
143 * removed!
144 * removed!
145 * removed!
146 *
147 * removed!
148 * removed!
149 * removed!
150 *
151 * removed!
152 * removed!
153 * removed!
154 *
155 * removed!
156 * removed!
157 * removed!
158 *
159 * removed!
160 * removed!
161 * removed!
162 *
163 *
164 * removed!
165 * removed!
166 * removed!
167 *
168 * removed!
169 * removed!
170 * removed!
171 *
172 * removed!
173 * removed!
174 * removed!
175 *
176 * removed!
177 * removed!
178 * removed!
179 * removed!
180 *
181 * removed!
182 * removed!
183 * removed!
184 * removed!
185 *
186 * removed!
187 * removed!
188 * removed!
189 *
190 * removed!
191 * removed!
192 * removed!
193 *
194 * removed!
195 * removed!
196 * removed!
197 *
198 * removed!
199 * removed!
200 * removed!
201 *
202 * removed!
203 * removed!
204 * removed!
205 *
206 * removed!
207 * removed!
208 * removed!
209 *
210 * removed!
211 * removed!
212 * removed!
213 *
214 * removed!
215 * removed!
216 * removed!
217 *
218 * removed!
219 * removed!
220 * removed!
221 *
222 * removed!
223 * removed!
224 * removed!
225 *
226 * removed!
227 * removed!
228 * removed!
229 *
230 * removed!
231 * removed!
232 * removed!
233 *
234 * removed!
235 * removed!
236 * removed!
237 *
238 * removed!
239 * removed!
240 * removed!
241 *
242 * removed!
243 * removed!
244 * removed!
245 *
246 * removed!
247 * removed!
248 * removed!
249 *
250 * removed!
251 * removed!
252 * removed!
253 *
254 * removed!
255 * removed!
256 * removed!
257 *
258 * removed!
259 * removed!
260 * removed!
261 * removed!
262 *
263 * removed!
264 * removed!
265 * removed!
266 *
267 * removed!
268 * removed!
269 * removed!
270 *
271 * removed!
272 * removed!
273 * removed!
274 * removed!
275 *
276 * removed!
277 * removed!
278 * removed!
279 *
280 * removed!
281 * removed!
282 * removed!
283 *
284 * removed!
285 * removed!
286 * removed!
287 *
288 * removed!
289 * removed!
290 * removed!
291 * removed!
292 *
293 * removed!
294 * removed!
295 * removed!
296 *
297 * removed!
298 * removed!
299 *
300 * removed!
301 * removed!
302 * removed!
303 *
304 * removed!
305 * removed!
306 * removed!
307 *
308 * removed!
309 * removed!
310 * removed!
311 *
312 * removed!
313 * removed!
314 * removed!
315 *
316 * removed!
317 * removed!
318 * removed!
319 *
320 * removed!
321 * removed!
322 * removed!
323 *
324 * removed!
325 * removed!
326 * removed!
327 *
328 * removed!
329 * removed!
330 * removed!
331 * removed!
332 * removed!
333 * removed!
334 *
335 * removed!
336 * removed!
337 * removed!
338 *
339 * removed!
340 * removed!
341 * removed!
342 *
343 * removed!
344 * removed!
345 * removed!
346 * removed!
347 *
348 * removed!
349 * removed!
350 * removed!
351 *
352 * removed!
353 * removed!
354 * removed!
355 *
356 * removed!
357 * removed!
358 * removed!
359 *
360 * removed!
361 * removed!
362 * removed!
363 * removed!
364 * removed!
365 * removed!
366 * removed!
367 *
368 * removed!
369 * removed!
370 * removed!
371 * removed!
372 * removed!
373 * removed!
374 *
375 * removed!
376 * removed!
377 * removed!
378 *
379 * removed!
380 * removed!
381 * removed!
382 *
383 * removed!
384 * removed!
385 * removed!
386 *
387 * removed!
388 * removed!
389 * removed!
390 *
391 *
392 *******************************************************************************/
393#include "kal_public_api.h"
394#include "kal_general_types.h"
395#include "reg_base.h"
396#include "md2g_drv.h"
397#include "string.h"
398#include "sync_data.h"
399
400#include "media.h"
401#include "l1audio_trace_utmd.h"
402#include "audio_ringbuf.h" // "audio_def.h"
403#include "l1audio.h"
404#include "afe.h"
405#include "ddload.h"
406#include "am.h"
407#include "l1aud_common_def.h"
408#include "speech_def.h"
409#include "afe_def.h"
410
411#include "sp_daca.h"
412#include "pcm4way.h"
413#include "sp_enhance.h"
414
415#include "sal_def.h"
416#include "sal_exp.h"
417#include "sp_cc.h"
418#include "extcodec.h"
419
420#include "us_timer.h"
421#include "DVFS_drv_md_public.h"
422
423#include "sp_drv.h"
424#include "spc_drv.h"
425#include "sp_dsptone_drv.h"
426#include "sp_ps.h"
427
428//#define TK6291_FAKE_COMPILE
429
430
431#define AM_2G_RESYNC_THRESHOLD 1083
432/* ========================================================================= */
433
434/* ========================================================================= */
435#define AM_STATE_KEYTONE (1<<L1SP_KEYTONE )
436#define AM_STATE_TONE (1<<L1SP_TONE )
437#define AM_STATE_SPEECH (1<<L1SP_SPEECH )
438#define AM_STATE_VOIP (1<<(L1SP_MAX_AUDIO+0) )
439#define AM_STATE_VOICE (1<<L1SP_VOICE )
440// #define AM_STATE_DAI (1<<L1SP_DAI )
441// #define AM_STATE_AUDIO (1<<L1SP_AUDIO )
442#define AM_STATE_SND_EFFECT (1<<L1SP_SND_EFFECT)
443// #define AM_STATE_AvBT (1 << (L1SP_MAX_AUDIO + 1))
444// #define AM_STATE_AVSYNC (1 << (L1SP_MAX_AUDIO + 2))
445#define AM_STATE_DACA (1 << (L1SP_MAX_AUDIO + 3))
446
447#define AM_CONFLICT_STATE (AM_STATE_SPEECH + AM_STATE_VOIP + AM_STATE_VOICE ) // + AM_STATE_AUDIO) // no audio state exist
448
449/*======== Speech State : record features in dedicated-mode speech ========= */
450#define SP_STATE_VMR (1 << 0)
451#define SP_STATE_PCM8K_REC (1 << 1)
452#define SP_STATE_PCMNWAY (1 << 2)
453#define SP_STATE_DACA (1 << 3)
454#define SP_STATE_VMR_EPL (1 << 4) // VM record with EPL
455
456/*======== VoIP State ======================================= */
457#define VOIP_STATE_VMR (1 << 0)
458
459#define VOIP_STATE_REC_ONLY_CAL (1 << 1)
460#define VOIP_STATE_REC_PLAY_CAL (1 << 2)
461
462
463/*============= DSP&AFE IO types ============================ */
464#define NORMAL_MODE 0
465// #define DAI_MODE 1
466// #define BT_CORDLESS_MODE 2
467#define BT_EARPHONE_MODE 3
468// #define PCM_MODE 4
469
470/*============= low byte flags of *DP_AUDIO_PAR ============================ */
471// #define VOICE_INPUT_FILTER_FLAG 0x1
472// #define VOICE_OUTPUT_FILTER_FLAG 0x2
473// #define VOICE_WB_AMR_FLAG 0x8
474// #define VOICE_16K_SWITCH_FLAG 0x10
475// #define VOICE_MIC_MUTE_FLAG 0x20
476// #define VOICE_SIDETONE_FILTER_FLAG 0
477
478
479/* ========================================================================= */
480
481/* To work around the bug of DSP when handover in short time,
482 Do not set handover flag to DSP, but VBI_Reset and other setting remain */
483#define NOT_HANDOVER_IN_SHORT_TIME
484
485#define VBI_Reset() { ASSERT(0); }
486#define VBI_End() { ASSERT(0); }
487#if defined(__C2K_SPEECH_SUPPORT__)
488void AM_DSP_TurnOffC2KSDSP(uint32 data , uint32 extraInfo);
489#endif
490/* =========== Block Filter Switch Between old/New Usage===================== */
491volatile kal_uint16 *g_Compen_Blk_Flt;
492extern ps_conf_test_mode_enum query_ps_conf_test_mode(void);
493typedef struct {
494 void (*code)(uint32, uint32);
495 uint32 data;
496 uint32 data2;
497} AM_QFunction;
498#define RAMP_QUEUE_SIZE 8
499typedef struct {
500 uint16 RampPoint;
501 bool MuteState;
502} RampStatus;
503
504static struct {
505#if defined( NOT_HANDOVER_IN_SHORT_TIME )
506 uint32 l1FN_HO;
507#endif
508 uint16 state;
509 uint16 pre_speech_mode;
510 uint8 is_reset_enh;
511 uint16 speech_mode;
512 uint16 ul_speech_mode; //behavior is the same as 3/4G
513 // int16 speech_off_delay;
514 int8 sub_channel;
515 int8 ul_sub_channel; //behavior is the same as 3/4G
516
517 // uint16 audioDigitalGain;
518 uint16 speechDigitalGain;
519 uint16 speechUplinkSwAgcGain;
520 uint16 speechDlEnhRefDigtalGain;
521
522 // uint16 bt_digital_gain; // temporary value for keeping origial dl volume in other mode
523 // uint16 bt_mic_gain; // temporary value for keeping origial up volume in other mode
524 // uint16 bt_dlEnhRef_digital_gain; // temporary value for keeping origial dl enhancement reference volum in the other mode
525
526
527 RINGBUFFER_T(AM_QFunction,8) qfunc;
528#if __SP3G_PLATFORM__
529 RINGBUFFER_T(AM_QFunction,8) qfunc2; // modem-unrelated
530#endif
531
532 uint8 speech_state;
533 // uint8 voip_state;
534 uint8 io_type;
535
536 // bool fLoopBack;
537 // kal_bool pre_isWBLink;
538
539#if defined(_SPE_ENH_MD_PARSE_)
540 bool isFirCoeffSet;
541 bool isIirCoeffSet;
542 int16 in_coeff_tmp[90];
543 int16 out_coeff_tmp[90];
544 int16 IIR_in_coeff_tmp[42];
545 int16 IIR_out_coeff_tmp[42];
546 int16 MIC1_IIR_coeff_tmp[20];
547 int16 MIC2_IIR_coeff_tmp[20];
548 int16 wb_in_coeff_tmp[90];
549 int16 wb_out_coeff_tmp[90];
550 int16 wb_IIR_in_coeff_tmp[42];
551 int16 wb_IIR_out_coeff_tmp[42];
552 int16 wb_MIC1_IIR_coeff_tmp[20];
553 int16 wb_MIC2_IIR_coeff_tmp[20];
554 int16 swb_in_coeff_tmp[90];
555 int16 swb_out_coeff_tmp[90];
556 int16 swb_IIR_in_coeff_tmp[42];
557 int16 swb_IIR_out_coeff_tmp[42];
558 int16 swb_MIC1_IIR_coeff_tmp[20];
559 int16 swb_MIC2_IIR_coeff_tmp[20];
560#endif
561 // bool toneLoopbackRec;
562 bool sp3g_flag;
563
564
565 RINGBUFFER_T(RampStatus, RAMP_QUEUE_SIZE) ramp_point_queue;
566#if defined(__C2K_SPEECH_SUPPORT__)
567 bool spc2k_flag;
568 bool c2k_flag;
569#endif
570#if defined(__VOLTE_SUPPORT__)
571 bool sp4g_flag;
572 int codec_4g;
573#endif
574
575 AM_RECORD_FORMAT record_format;
576 bool dsp_2g_reset;
577} am;
578
579#if defined(__C2K_SPEECH_SUPPORT__)
580#if defined(__VOLTE_SUPPORT__)
581#define IsWBLink(speech_codec) ((SP4G_CODEC_G722 == speech_codec ) || ((speech_codec >= 0x20) && (speech_codec <= 0x28)) || (SPH_CODEC_C2K_SO73WB == speech_codec))
582#else
583#define IsWBLink(speech_codec) (((speech_codec) >= 0x20) || (SPH_CODEC_C2K_SO73WB == (speech_codec)))
584#endif
585#else
586#if defined(__VOLTE_SUPPORT__)
587#define IsWBLink(speech_codec) ((SP4G_CODEC_G722 == speech_codec ) || ((speech_codec >= 0x20) && (speech_codec <= 0x28)))
588#else
589#define IsWBLink(speech_codec) ((speech_codec) >= 0x20)
590#endif
591#endif
592
593
594
595
596/* --------------------------------------------------------------------------*/
597void SP4G_Call_Close(void);
598void SP4G_Call_Open(uint16 codec, PS_RESET_TYPE_t resetType);
599kal_uint32 SP4G_GetCodecMode(void);
600bool is_EVS_codec(uint8 codec);
601bool is_g_codec(uint8 codec);
602int get_sp4g_fake_EVS_IO(void);
603
604static void AM_ReloadDSPCoefficient( void );
605
606
607static void AM_Enqueue( void (*code)(uint32, uint32), uint32 data, uint32 data2, bool isCritical )
608{
609 /* For 65nm process, MCU has to reload DSP coefficient at each wake-up */
610 if (am.state == 0){
611 AM_ReloadDSPCoefficient();
612 }
613
614 code( data , data2 );
615}
616
617
618
619const signed short Sph_Mic1_IIR_In[20] =
620{
621-7815, 16002, 7900, -15800, 7900, -8033, 16219, 8192,-16384, 8192, /* UL SWB HP-IIR-137Hz (20ms task)*/
622 0, 0, 8192, 0, 0, 0, 0, 8192, 0, 0 /* not used */
623};
624const signed short Sph_Mic2_IIR_In[20] =
625{
626-7972, 16162, 8000, -16000, 8000, -8095, 16285, 8192,-16384, 8192, /* UL SWB HP-IIR-75Hz (20ms task)*/
627 0, 0, 8192, 0, 0, 0, 0, 8192, 0, 0 /*not used*/
628};
629const signed short Speech_All_Pass_IIR_Coeff[42] =
630{ /* All pass filter */
631 0x14, 0x400, 0, 0, 0,
632 0, 0, 0, 0, 0,
633 0, 0, 0, 0, 0,
634 0, 0, 0, 0, 0,
635 0, 0, 0, 0, 0,
636 0, 0, 0, 0, 0,
637 0, 0, 0, 0, 0,
638 0, 0, 0, 0, 0,
639 0, 0
640};
641const int16 Speech_All_Pass_FIR_Coeff[45] =
642 { /* All pass filter */
643 32767, 0, 0, 0, 0,
644 0, 0, 0, 0, 0,
645 0, 0, 0, 0, 0,
646 0, 0, 0, 0, 0,
647 0, 0, 0, 0, 0,
648 0, 0, 0, 0, 0,
649 0, 0, 0, 0, 0,
650 0, 0, 0, 0, 0,
651 0, 0, 0, 0, 0
652 };
653
654
655
656
657
658
659const uint16 DSP_PCM_IDLE_DELAY_M_VOLTE = (6*8)+(16<<10)+(2<<8);
660
661
662/* Note: The speech pattern length for amr-wb can be calculated from
663lenSpeechBitsAMR_WB in amr_table.h; therefore, remove them out.
664Those for amr might be removed if vm.c does not handle amr any more. */
665static const uint8 SpeechPatternLength[] = {
666 (uint8)((260 + 15) / 16), /* FR */
667 (uint8)((112 + 15) / 16), /* HR */
668 (uint8)((244 + 15) / 16), /* EFR */
669 (uint8)((244 + 15) / 16), /* AMR 12.2K */
670 (uint8)((204 + 15) / 16), /* AMR 10.2K */
671 (uint8)((159 + 15) / 16), /* AMR 7.95K */
672 (uint8)((148 + 15) / 16), /* AMR 7.4K */
673 (uint8)((134 + 15) / 16), /* AMR 6.7K */
674 (uint8)((118 + 15) / 16), /* AMR 5.9K */
675 (uint8)((103 + 15) / 16), /* AMR 5.15K */
676 (uint8)(( 95 + 15) / 16), /* AMR 4.75K */
677
678 (uint8)((132 + 15) / 16), /* AMR-WB 6.60 */
679 (uint8)((177 + 15) / 16), /* AMR-WB 8.85 */
680 (uint8)((253 + 15) / 16), /* AMR-WB 12.65 */
681 (uint8)((285 + 15) / 16), /* AMR-WB 14.25 */
682 (uint8)((317 + 15) / 16), /* AMR-WB 15.85 */
683 (uint8)((365 + 15) / 16), /* AMR-WB 18.25 */
684 (uint8)((397 + 15) / 16), /* AMR-WB 19.85 */
685 (uint8)((461 + 15) / 16), /* AMR-WB 23.05 */
686 (uint8)((477 + 15) / 16), /* AMR-WB 23.85 */
687
688 (uint8)(1), /* QCELP8K (Not supported)*/ //return 1 to prevent vm codec length check
689 (uint8)(17), /* QCELP13K */
690 (uint8)(11), /* EVRCA */
691 (uint8)(11), /* EVRCB */
692
693 (uint8)(9+2), /* EVS_AWB660 */
694 (uint8)(12+2), /* EVS_AWB885 */
695 (uint8)(16+2), /* EVS_AWB1265 */
696 (uint8)(18+2), /* EVS_AWB1425 */
697 (uint8)(20+2), /* EVS_AWB1585 */
698 (uint8)(23+2), /* EVS_AWB1825 */
699 (uint8)(25+2), /* EVS_AWB1985 */
700 (uint8)(29+2), /* EVS_AWB2305 */
701 (uint8)(30+2), /* EVS_AWB2385 */
702 (uint8)(10+2), /* EVS_PRI590 */
703 (uint8)(9+2), /* EVS_PRI720 */
704 (uint8)(10+2), /* EVS_PRI800 */
705 (uint8)(12+2), /* EVS_PRI960 */
706 (uint8)(17+2), /* EVS_PRI1320 */
707 (uint8)(21+2), /* EVS_PRI1640 */
708 (uint8)(31+2), /* EVS_PRI2440 */
709 (uint8)(40+2), /* EVS_PRI3200 */
710 (uint8)(60+2), /* EVS_PRI4800 */
711 (uint8)(80+2), /* EVS_PRI6400 */
712 (uint8)(120+2), /* EVS_PRI9600 */
713 (uint8)(160+2) /* EVS_PRI12800 */
714};
715
716#if 0
717/* under construction !*/
718/* under construction !*/
719/* under construction !*/
720/* under construction !*/
721/* under construction !*/
722/* under construction !*/
723/* under construction !*/
724/* under construction !*/
725/* under construction !*/
726/* under construction !*/
727/* under construction !*/
728/* under construction !*/
729/* under construction !*/
730#endif
731
732uint16 AM_GetSpeechPatternLength( uint8 speech_mode )
733{
734 if((speech_mode >= 11) && (speech_mode <= 31)) //EVS
735 {
736 speech_mode = speech_mode - 11 + 24;
737 }
738 else if( speech_mode >= 0x30) // c2k related
739 speech_mode = speech_mode - 0x30 + 0x14;
740 else if( speech_mode >= 0x20 )
741 speech_mode = speech_mode - 0x20 + 0x0B;
742 if( speech_mode<(sizeof(SpeechPatternLength)/sizeof(SpeechPatternLength[0])))
743 return (uint16)SpeechPatternLength[speech_mode];
744 else
745 return 1; //return 1 to prevent vm codec length check
746}
747//Need to add new pattern for MT6280
748
749static const uint16 SpeechSilencePattern[][31] = {
750 { 0x4820,0xD617,0x0284,0x2480,0x9249,0x8924,0x8002,0x4924, /* FR */
751 0x2492,0x0289,0x2480,0x9249,0x8924,0x8002,0x4924,0x2492,
752 0x0009 },
753 { 0x4E20,0x875E,0x5473,0x8482,0x00E9,0x0000,0x0000 }, /* HR */
754 { 0x7A10,0x092D,0xB55F,0x7C06,0x185C,0xDE06,0x4230,0x0103, /* EFR */
755 0xA012,0x001A,0x0000,0x0000,0x0D6C,0x0000,0x0000,0x0000 },
756 { 0x00e2,0x5dfc,0xf095,0xcd4e,0x24da,0x0e04,0xf0fb,0x4f2e, /* AMR12.2 */
757 0x4430,0x9fa8,0x0319,0x56c0,0xc144,0x0278,0x70ea,0x0004 },
758 { 0xe00a,0xf2e7,0x516b,0x19a1,0xc10d,0x145a,0x4c96,0x25e0, /* AMR10.2 */
759 0x5ce6,0x17b9,0x0982,0x225d,0x00c4 },
760 { 0x033c,0xe5cd,0xd9fb,0x387f,0x420c,0x8c99,0x58d7,0x1156, /* AMR7.95 */
761 0x397f,0x1074 },
762 { 0xe00a,0xf2e7,0x9ac5,0x4433,0x185b,0x3e05,0xdc64,0xc886, /* AMR7.4 */
763 0xcd2e,0x0000 },
764 { 0xe00a,0xf2e7,0x7761,0x0486,0x0dd5,0xf47c,0x21b0,0xf547, /* AMR6.7 */
765 0x0002 },
766 { 0xe00a,0xf2e7,0xb196,0xa8ae,0xbcb7,0x6fb9,0x0193,0x002e }, /* AMR5.9 */
767 { 0x3c0a,0x7e51,0x652c,0x5e91,0xd023,0xea5a,0x005b }, /* AMR5.15 */
768 { 0x3c0a,0x3e51,0x6529,0x3a49,0x977f,0x3565 }, /* AMR4.75 */
769 { 0x1480,0x02ee,0xd706,0x09f4,0x4e01,0x2ada,0x59ef,0x2a20,0x0001 }, /* AMR-WB 6.60 */
770 { 0x1290,0x0460,0x78f1,0xae42,0x2330,0x98c8,0x0120,0x57f8,0xa4b5,0xa681,0x25a0,0x0000 }, /* AMR-WB 8.85 */
771 { 0x1290,0x0460,0x78f1,0x4142,0xc702,0x3f49,0xd446,0x7295,0x55c0,0x1028,0x7159,0xe315,0x96cf,0x8328,0x06a7,0x1f2c }, /* AMR-WB 12.65 */
772 { 0x1290,0x0460,0x78f1,0x1542,0x8839,0x8c07,0x462d,0x59f4,0x3069,0x55c3,0x6028,0xa539,0x1724,0x2ebb,0xa182,0x92da,0xd156,0x1e06 }, /* AMR-WB 14.25 */
773 { 0x1290,0x0460,0x78f1,0x1542,0x00b8,0xc095,0x381e,0xf446,0x6959,0x6870,0x5f5c,0xe028,0xb886,0x2724,0xcbb3,0x820b,0xcaa0,0x5692,0x6053,0x1c05 }, /* AMR-WB 15.85 */
774 { 0x1290,0x0460,0x78f1,0xff42,0x0604,0xd0c8,0x8460,0x63e0,0x7b44,0xce75,0x3c14,0xea27,0x285d,0xf790,0x13eb,0xec97,0x5f93,0x28bb,0x2648,0x3b81,0x2de6,0x1529,0x1529 }, /* AMR-WB 18.25 */
775 { 0x1290,0x0460,0x78f1,0x3942,0xf104,0x2b51,0x40cb,0xd864,0xc463,0x75ce,0x5d7d,0x3c8f,0xfa23,0x285d,0xd690,0xfa27,0xc515,0x93ea,0xbb5f,0x1e28,0xc5ea,0xfa2f,0x2c8c,0x45d8,0x1529 }, /* AMR-WB 19.85 */
776 { 0x1290,0x0460,0x78f1,0x1742,0x2098,0xaa41,0x4330,0xb286,0xd023,0xc463,0x5ce6,0x6e55,0xe3d7,0x14ef,0xb10f,0x2017,0xf1e0,0xf68f,0x8735,0x1c66,0x5b22,0x3765,0xc86c,0xdb41,0x84d3,0x522a,0x8696,0xc4b6,0x1c2a }, /* AMR-WB 23.05 */
777 { 0x1290,0x0460,0x78f1,0x1742,0x2098,0xaa41,0x4330,0xb286,0xd023,0x4f63,0xce6c,0x0555,0x5926,0x4c7e,0x1af1,0xc5df,0xe01e,0x2daf,0xdc74,0x56be,0xe4c0,0xf38a,0xa07a,0x5585,0x41fb,0x784d,0x932d,0x4798,0x914b,0x0f52 } /* AMR-WB 27.85 */
778};
779
780void AM_Reset_Enh(uint32 codec)
781{
782 kal_bool preIsSWB;
783 kal_bool afterIsSWB;
784
785 //Set_Reset_Enh_Status(false);
786 if( (SP4G_CODEC_EVS_32K_005_9 <= codec) && (SP4G_CODEC_EVS_32K_128_0 >= codec) ){
787 afterIsSWB = true;
788 }else{
789 afterIsSWB = false;
790 }
791
792 if( (SP4G_CODEC_EVS_32K_005_9 <= am.pre_speech_mode) && (SP4G_CODEC_EVS_32K_128_0 >= am.pre_speech_mode) ){
793 preIsSWB = true;
794 }else{
795 preIsSWB = false;
796 }
797 kal_prompt_trace(MOD_L1SP, "AM_Reset_Enh,preIsSWB=%x,afterIsSWB=%x,codec=%x,am.pre_speech_mode=%x", preIsSWB,afterIsSWB,codec,am.pre_speech_mode);
798 if(preIsSWB != afterIsSWB ){
799 //SetSpeechEnhancement(false);
800 //SetSpeechEnhancement(true);
801 Set_Reset_Enh_Status(true);
802 }
803 am.pre_speech_mode = codec;
804}
805
806void Set_Reset_Enh_Status(uint8 status)
807{
808 am.is_reset_enh = status;
809}
810
811
812uint8 Get_Reset_Enh_Status(void)
813{
814 return am.is_reset_enh;
815}
816
817void AM_FillSilencePattern( volatile uint16 *addr, uint16 info, uint16 speech_mode )
818{
819#ifndef L1D_TEST
820 const uint16 *pat_info;
821 uint32 I, len;
822 if( speech_mode >= 0x20 )
823 speech_mode = speech_mode - 0x20 + 0x0B;
824
825 if( speech_mode >= (sizeof(SpeechPatternLength)/sizeof(SpeechPatternLength[0])) )
826 return;
827
828 pat_info = SpeechSilencePattern[speech_mode];
829 len = (uint16)SpeechPatternLength[speech_mode];
830
831 *addr++ = info;
832 for( I = 0; I < len; I++ )
833 *addr++ = *pat_info++;
834
835 Data_Sync_Barrier();
836#endif
837}
838
839void AM_FillSilencePatternInBuffer( uint16 *buffer, uint16 speech_mode )
840{
841#ifndef L1D_TEST
842 const uint16 *pat_info;
843 uint32 I, len;
844 if( speech_mode >= 0x20 )
845 speech_mode = speech_mode - 0x20 + 0x0B;
846
847 if( speech_mode >= (sizeof(SpeechPatternLength)/sizeof(SpeechPatternLength[0])) )
848 return;
849
850 pat_info = SpeechSilencePattern[speech_mode];
851 len = (uint16)SpeechPatternLength[speech_mode];
852
853 for( I = 0; I < len; I++ )
854 *buffer++ = *pat_info++;
855#endif
856}
857
858/* -------------------------------------------------------------------------- */
859extern uint32 L1I_GetTimeStamp( void );
860
861void AM_SetDSP2GReset(bool v)
862{
863 am.dsp_2g_reset = v;
864}
865
866void AM_Set2GCodecInfo(uint16 speech_mode, int8 sub_channel)//
867{
868 am.ul_speech_mode = speech_mode;
869 am.ul_sub_channel = sub_channel;
870}
871
872void AM_Get2GCodecInfo(uint16 *speech_mode, int8 *sub_channel)//
873{
874 *speech_mode = am.ul_speech_mode;
875 *sub_channel = am.ul_sub_channel;
876}
877
878void AM_FlushQFunction( void )
879{
880#ifndef L1D_TEST
881 while( !RB_EMPTY(am.qfunc) )
882 kal_sleep_task( AUD_1TICK(1) );
883#endif
884}
885
886/* ========================================================================= */
887/* Interface Functions */
888/* ========================================================================= */
889
890#if 0
891/* under construction !*/
892/* under construction !*/
893/* under construction !*/
894/* under construction !*/
895/* under construction !*/
896/* under construction !*/
897/* under construction !*/
898/* under construction !*/
899/* under construction !*/
900/* under construction !*/
901/* under construction !*/
902/* under construction !*/
903/* under construction !*/
904/* under construction !*/
905/* under construction !*/
906/* under construction !*/
907/* under construction !*/
908/* under construction !*/
909/* under construction !*/
910/* under construction !*/
911/* under construction !*/
912/* under construction !*/
913/* under construction !*/
914/* under construction !*/
915/* under construction !*/
916/* under construction !*/
917/* under construction !*/
918/* under construction !*/
919/* under construction !*/
920#endif
921
922
923#if defined(_SPE_ENH_MD_PARSE_)
924static void AM_WriteSpeechCompensationFilter( const int16 in_coeff[90], const int16 out_coeff[90] )
925{
926 int i;
927 volatile uint16* dsp_ptr;
928
929 MD_TRC_SPE_DSP_CHECK_NB_FIR_PAR(in_coeff[0],in_coeff[1],out_coeff[0],out_coeff[1]);
930 /* Write audio FIR filter coeficients */
931 dsp_ptr = SAL_BKF_GetFltCoefAddr_NB_UL();
932
933 for( i=0; i<SAL_FLTCOEFLEN_BKF_NB; i++ )
934#if 1 // ndef __HQA_AUDIO__
935 *dsp_ptr ++ = *in_coeff++;
936#else
937/* under construction !*/
938#endif
939
940 dsp_ptr = SAL_BKF_GetFltCoefAddr_NB_DL();
941
942 for( i=0; i<SAL_FLTCOEFLEN_BKF_NB; i++ )
943#if 1 // ndef __HQA_AUDIO__
944 *dsp_ptr ++ = *out_coeff++;
945#else
946/* under construction !*/
947#endif
948
949
950 Data_Sync_Barrier();
951}
952static void AM_WriteSpeechIIRCompensationFilter( const int16 in_coeff[42], const int16 out_coeff[42],const int16 Mic1_coeff[20],const int16 Mic2_coeff[20] )
953{
954 int i;
955 volatile uint16* dsp_ptr;
956 /* Write audio IIR filter coeficients */
957 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_UL_NB);
958
959 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
960 {
961 *dsp_ptr ++ = *in_coeff++;
962 }
963
964
965 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_DL_NB);
966 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
967 {
968 *dsp_ptr ++ = *out_coeff++;
969 }
970
971 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC1_IIR_COEF_UL_NB);
972 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
973 {
974 *dsp_ptr ++ = *Mic1_coeff++;
975 }
976
977 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC2_IIR_COEF_UL_NB);
978 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
979 {
980 *dsp_ptr ++ = *Mic2_coeff++;
981 }
982 Data_Sync_Barrier();
983
984
985}
986void AM_WriteFirCoeffs( const int16 in_coeff[90], const int16 out_coeff[90] )
987{
988
989
990 memcpy(am.in_coeff_tmp, in_coeff, 90*sizeof(int16));
991 memcpy(am.out_coeff_tmp, out_coeff, 90*sizeof(int16));
992
993
994 am.isFirCoeffSet= true;
995
996 /* Write audio FIR filter coeficients */
997 AM_WriteSpeechCompensationFilter(in_coeff, out_coeff);
998
999
1000
1001}
1002
1003void AM_WriteIirCoeffs( const int16 in_coeff[42], const int16 out_coeff[42],const int16 Mic1_coeff[20],const int16 Mic2_coeff[20] )
1004{
1005 memcpy(am.IIR_in_coeff_tmp, in_coeff, 42*sizeof(int16));
1006 memcpy(am.IIR_out_coeff_tmp, out_coeff, 42*sizeof(int16));
1007 memcpy(am.MIC1_IIR_coeff_tmp, Mic1_coeff, 20*sizeof(int16));
1008 memcpy(am.MIC2_IIR_coeff_tmp, Mic2_coeff, 20*sizeof(int16));
1009 am.isIirCoeffSet= true;
1010 /* Write audio IIR filter coeficients */
1011 AM_WriteSpeechIIRCompensationFilter(in_coeff, out_coeff,Mic1_coeff,Mic2_coeff);
1012
1013
1014
1015}
1016static void AM_WriteWbSpeechCompensationFilter( const int16 wb_in_coeff[90], const int16 wb_out_coeff[90] )
1017{
1018 int i;
1019 volatile uint16* dsp_ptr;
1020 MD_TRC_SPE_DSP_CHECK_WB_FIR_PAR(wb_in_coeff[0],wb_in_coeff[1],wb_out_coeff[0],wb_out_coeff[1]);
1021 /* Write audio FIR filter coeficients */
1022 dsp_ptr = SAL_BKF_GetFltCoefAddr_WB_UL();
1023
1024 for( i=0; i<SAL_FLTCOEFLEN_BKF_WB; i++ ){
1025#if 1 // ndef __HQA_AUDIO__
1026 *dsp_ptr ++ = *wb_in_coeff++;
1027#else
1028/* under construction !*/
1029/* under construction !*/
1030/* under construction !*/
1031/* under construction !*/
1032/* under construction !*/
1033#endif
1034 }
1035 dsp_ptr = SAL_BKF_GetFltCoefAddr_WB_DL();
1036
1037 for( i=0; i<SAL_FLTCOEFLEN_BKF_WB; i++ ){
1038#if 1 // ndef __HQA_AUDIO__
1039 *dsp_ptr ++ = *wb_out_coeff++;
1040#else
1041/* under construction !*/
1042/* under construction !*/
1043/* under construction !*/
1044/* under construction !*/
1045/* under construction !*/
1046#endif
1047 }
1048
1049 Data_Sync_Barrier();
1050}
1051static void AM_WriteWbSpeechIIRCompensationFilter( const int16 wb_in_coeff[42], const int16 wb_out_coeff[42],const int16 wb_Mic1_coeff[20],const int16 wb_Mic2_coeff[20] )
1052{
1053 int i;
1054 volatile uint16* dsp_ptr;
1055 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_UL_WB);
1056 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
1057 {
1058 *dsp_ptr ++ = *wb_in_coeff++;
1059 }
1060 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_DL_WB);
1061 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
1062 {
1063 *dsp_ptr ++ = *wb_out_coeff++;
1064 }
1065 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC1_IIR_COEF_UL_WB);
1066 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
1067 {
1068 *dsp_ptr ++ = *wb_Mic1_coeff++;
1069 }
1070
1071 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC2_IIR_COEF_UL_WB);
1072 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
1073 {
1074 *dsp_ptr ++ = *wb_Mic2_coeff++;
1075 }
1076 Data_Sync_Barrier();
1077
1078
1079
1080
1081}
1082static void AM_WriteSWbSpeechCompensationFilter( const int16 swb_in_coeff[90], const int16 swb_out_coeff[90] )
1083{
1084 int i;
1085 volatile uint16* dsp_ptr;
1086 MD_TRC_SPE_DSP_CHECK_SWB_FIR_PAR(swb_in_coeff[0],swb_in_coeff[1],swb_out_coeff[0],swb_out_coeff[1]);
1087 /* Write audio FIR filter coeficients */
1088 dsp_ptr = SAL_BKF_GetFltCoefAddr_SWB_UL();
1089
1090 for( i=0; i<SAL_FLTCOEFLEN_BKF_SWB; i++ ){
1091#if 1 // ndef __HQA_AUDIO__
1092 *dsp_ptr ++ = *swb_in_coeff++;
1093#else
1094/* under construction !*/
1095/* under construction !*/
1096/* under construction !*/
1097/* under construction !*/
1098/* under construction !*/
1099#endif
1100 }
1101 dsp_ptr = SAL_BKF_GetFltCoefAddr_SWB_DL();
1102
1103 for( i=0; i<SAL_FLTCOEFLEN_BKF_SWB; i++ ){
1104#if 1 // ndef __HQA_AUDIO__
1105 *dsp_ptr ++ = *swb_out_coeff++;
1106#else
1107/* under construction !*/
1108/* under construction !*/
1109/* under construction !*/
1110/* under construction !*/
1111/* under construction !*/
1112#endif
1113}
1114 Data_Sync_Barrier();
1115}
1116static void AM_WriteSWbSpeechIIRCompensationFilter( const int16 swb_in_coeff[42], const int16 swb_out_coeff[42],const int16 swb_Mic1_coeff[20],const int16 swb_Mic2_coeff[20] )
1117{
1118 volatile uint16* dsp_ptr;
1119 int i;
1120 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_UL_SWB);
1121 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
1122 {
1123 *dsp_ptr ++ = *swb_in_coeff++;
1124 }
1125
1126 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_ENH_IIR_COEF_DL_SWB);
1127 for( i=0; i<SAL_FLTCOEFLEN_ENH_IIR; i++ )
1128 {
1129 *dsp_ptr ++ = *swb_out_coeff++;
1130 }
1131
1132 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC1_IIR_COEF_UL_SWB);
1133 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
1134 {
1135 *dsp_ptr ++ = *swb_Mic1_coeff++;
1136 }
1137
1138 dsp_ptr = SAL_IIR_Coef_GetBuf(SAL_MIC2_IIR_COEF_UL_SWB);
1139 for( i=0; i<SAL_FLTCOEFLEN_MIC_IIR; i++ )
1140 {
1141 *dsp_ptr ++ = *swb_Mic2_coeff++;
1142 }
1143 MO_Sync();//Data_Sync_Barrier();
1144
1145}
1146void AM_WriteWbFirCoeffs( const int16 wb_in_coeff[90], const int16 wb_out_coeff[90] )
1147{
1148
1149
1150 memcpy(am.wb_in_coeff_tmp, wb_in_coeff, 90*sizeof(int16));
1151 memcpy(am.wb_out_coeff_tmp, wb_out_coeff, 90*sizeof(int16));
1152
1153
1154 //write FIR coefiicient when some application is running.
1155 // Otherwise, the coefficient will be reloaed under AM_Enqueue()
1156 if(am.state !=0) {
1157 AM_WriteWbSpeechCompensationFilter(am.wb_in_coeff_tmp, am.wb_out_coeff_tmp);
1158 }
1159}
1160void AM_WriteWbIirCoeffs( const int16 wb_in_coeff[42], const int16 wb_out_coeff[42],const int16 wb_Mic1_coeff[20],const int16 wb_Mic2_coeff[20] )
1161{
1162// #if __RELOAD_DSP_COEFF__
1163 memcpy(am.wb_IIR_in_coeff_tmp, wb_in_coeff, 42*sizeof(int16));
1164 memcpy(am.wb_IIR_out_coeff_tmp, wb_out_coeff, 42*sizeof(int16));
1165 memcpy(am.wb_MIC1_IIR_coeff_tmp, wb_Mic1_coeff, 20*sizeof(int16));
1166 memcpy(am.wb_MIC2_IIR_coeff_tmp, wb_Mic2_coeff, 20*sizeof(int16));
1167// #endif
1168 if(am.state !=0) {
1169 AM_WriteWbSpeechIIRCompensationFilter(am.wb_IIR_in_coeff_tmp, am.wb_IIR_out_coeff_tmp,am.wb_MIC1_IIR_coeff_tmp,am.wb_MIC2_IIR_coeff_tmp);
1170 }
1171}
1172void AM_WriteSWbFirCoeffs( const int16 swb_in_coeff[90], const int16 swb_out_coeff[90] )
1173{
1174
1175
1176 memcpy(am.swb_in_coeff_tmp, swb_in_coeff, 90*sizeof(int16));
1177 memcpy(am.swb_out_coeff_tmp, swb_out_coeff, 90*sizeof(int16));
1178
1179
1180 //write FIR coefiicient when some application is running.
1181 // Otherwise, the coefficient will be reloaed under AM_Enqueue()
1182 if(am.state !=0) {
1183 AM_WriteSWbSpeechCompensationFilter(am.swb_in_coeff_tmp, am.swb_out_coeff_tmp);
1184 }
1185}
1186void AM_WriteSWbIirCoeffs( const int16 swb_in_coeff[42], const int16 swb_out_coeff[42],const int16 swb_Mic1_coeff[20],const int16 swb_Mic2_coeff[20] )
1187{
1188
1189// #if __RELOAD_DSP_COEFF__
1190 memcpy(am.swb_IIR_in_coeff_tmp, swb_in_coeff, 42*sizeof(int16));
1191 memcpy(am.swb_IIR_out_coeff_tmp, swb_out_coeff, 42*sizeof(int16));
1192 memcpy(am.swb_MIC1_IIR_coeff_tmp, swb_Mic1_coeff, 20*sizeof(int16));
1193 memcpy(am.swb_MIC2_IIR_coeff_tmp, swb_Mic2_coeff, 20*sizeof(int16));
1194// #endif
1195
1196 //writeIIR coefiicient when some application is running.
1197 // Otherwise, the coefficient will be reloaed under AM_Enqueue()
1198 if(am.state !=0) {
1199 AM_WriteSWbSpeechIIRCompensationFilter(am.swb_IIR_in_coeff_tmp, am.swb_IIR_out_coeff_tmp,am.swb_MIC1_IIR_coeff_tmp,am.swb_MIC2_IIR_coeff_tmp);
1200 }
1201}
1202#endif
1203// SRC coefiicient using in DSP
1204const signed short Audio_Flt_Coeff[82] =
1205{
1206 0, 96, 162, -92, -488, -302, 408, 372, -660, -780,
1207 782, 1272, -958, -2094, 1088, 3458, -1200, -6426, 1266, 20318,
1208 30834, 20318, 1266, -6426, -1200, 3458, 1088, -2094, -958, 1272,
1209 782, -780, -660, 372, 408, -302, -488, -92, 162, 96,
1210 0, /* SRC Up-Sampling */
1211 0, 0, -36, -175, -262, -51, 277, 146, -376, -317,
1212 489, 595, -597, -1034, 689, 1777, -744, -3351, 727, 10500,
1213 15852, 10500, 727, -3351, -744, 1777, 689, -1034, -597, 595,
1214 489, -317, -376, 146, 277, -51, -262, -175, -36, 0,
1215 0 /* SRC Down-Sampling */
1216};
1217
1218const signed short Sph_SRCPlus_Flt_Coeff[148] =
1219{
1220 50, 163, 186, 27, -141, -49, 157, 87, -185, -143, 211,
1221218, -233, -313, 243, 431, -239, -573, 214, 743, -160, -945,
122268, 1188, 76,-1486, -297, 1867, 639,-2392,-1199, 3213, 2245,
1223-4839,-4904,10502,28344,28344,10502,-4904,-4839, 2245, 3213,-1199,
1224-2392, 639, 1867, -297,-1486, 76, 1188, 68, -945, -160, 743,
1225214, -573, -239, 431, 243, -313, -233, 218, 211, -143, -185,
122687, 157, -49, -141, 27, 186, 163, 50, /* SRC Up-Sampling */
1227 25, 82, 93, 14, -71, -25, 79, 44, -93, -72, 106,
1228 109, -117, -157, 122, 216, -120, -287, 107, 372, -80, -473,
1229 34, 594, 38, -743, -149, 934, 320, -1196, -600, 1607, 1123,
1230 -2420, -2452, 5251, 14172, 14172, 5251, -2452, -2420, 1123, 1607, -600,
1231 -1196, 320, 934, -149, -743, 38, 594, 34, -473, -80, 372,
1232 107, -287, -120, 216, 122, -157, -117, 109, 106, -72, -93,
1233 44, 79, -25, -71, 14, 93, 82, 25 /* SRC Down-Sampling */
1234
1235/* -12, 16, 48, -98, -312, -234, 100, 180, -130, -238, 136, 312, -134, -404, 122, 512, -94, -640,
1236 46, 792, 28, -970, -134, 1188, 286, -1458, -510, 1818, 852, -2336, -1464, 3052, 2446, -4652, -5070, 10232,
123728264, 28264, 10232, -5070, -4652, 2446, 3052, -1464, -2336, 852, 1818, -510, -1458, 286, 1188, -134, -970, 28,
1238 92, 46, -640, -94, 512, 122, -404, -134, 312, 136, -238, -130, 180, 100, -234, -312, -98, 48,
1239 16, -12, 0 // SRC Up-Sampling */
1240};
1241
1242const signed short Sph_SRCPlus_Flt_SWB_Coeff[296] =
1243{
124425, 82, 130, 185, 199, 166, 81, -27, -117, -146, -99, 7, 119, 177, 141, 20, -128, -222, -202, -64,
1245128, 272, 279, 127, -117, -325, -372, -212, 89, 376, 482, 324, -38, -421, -607, -466, -42, 456, 748, 645,
1246158, -475, -907, -867, -323, 471, 1086, 1147, 552, -435, -1291, -1506, -873, 351, 1535, 1986, 1339, -191, -1845, -2678,
1247-2063, -106, 2295, 3811, 3351, 711, -3116, -6193, -6400, -2401, 5617, 15802, 25197, 30823, 30823, 25197, 15802, 5617, -2401, -6400,
1248-6193, -3116, 711, 3351, 3811, 2295, -106, -2063, -2678, -1845, -191, 1339, 1986, 1535, 351, -873, -1506, -1291, -435, 552,
12491147, 1086, 471, -323, -867, -907, -475, 158, 645, 748, 456, -42, -466, -607, -421, -38, 324, 482, 376, 89,
1250-212, -372, -325, -117, 127, 279, 272, 128, -64, -202, -222, -128, 20, 141, 177, 119, 7, -99, -146, -117,
1251-27, 81, 166, 199, 185, 130, 82, 25, /* SRC Up-Sampling */
12526, 21, 33, 46, 50, 42, 20, -7, -29, -37, -25, 2, 30, 44, 35, 5, -32, -56, -51, -16,
125332, 68, 70, 32, -29, -81, -93, -53, 22, 94, 121, 81, -10, -105, -152, -117, -11, 114, 187, 161,
125440, -119, -227, -217, -81, 118, 272, 287, 138, -109, -323, -377, -218, 88, 384, 497, 335, -48, -461, -670,
1255-516, -27, 574, 953, 838, 178, -779, -1548, -1600, -600, 1404, 3951, 6299, 7706, 7706, 6299, 3951, 1404, -600, -1600,
1256-1548, -779, 178, 838, 953, 574, -27, -516, -670, -461, -48, 335, 497, 384, 88, -218, -377, -323, -109, 138,
1257287, 272, 118, -81, -217, -227, -119, 40, 161, 187, 114, -11, -117, -152, -105, -10, 81, 121, 94, 22,
1258-53, -93, -81, -29, 32, 70, 68, 32, -16, -51, -56, -32, 5, 35, 44, 30, 2, -25, -37, -29,
1259-7, 20, 42, 50, 46, 33, 21, 6 /* SRC Down-Sampling */
1260};
1261
1262const signed short Sph_SRC_IIR_Flt_Coeff[12] =
1263{
126429909, 35641, 17819, 28766, 5421, 21716, 24199, 32394, 11027, 24904, 10224, 32768
1265};
1266
1267#if 0
1268/* under construction !*/
1269/* under construction !*/
1270/* under construction !*/
1271/* under construction !*/
1272/* under construction !*/
1273/* under construction !*/
1274/* under construction !*/
1275/* under construction !*/
1276/* under construction !*/
1277/* under construction !*/
1278/* under construction !*/
1279/* under construction !*/
1280/* under construction !*/
1281/* under construction !*/
1282/* under construction !*/
1283/* under construction !*/
1284/* under construction !*/
1285/* under construction !*/
1286/* under construction !*/
1287/* under construction !*/
1288/* under construction !*/
1289/* under construction !*/
1290/* under construction !*/
1291/* under construction !*/
1292/* under construction !*/
1293/* under construction !*/
1294/* under construction !*/
1295/* under construction !*/
1296/* under construction !*/
1297/* under construction !*/
1298/* under construction !*/
1299/* under construction !*/
1300#endif
1301
1302signed short Sph_Notch_Filter_Param[SAL_PARAMETERLEN_NOTCH] = {
1303 -7708, 15853, 7980, -15929, 7980,
1304 -7788, 15937, 8180, -16330, 8180,
1305 -7948, 16103, 8190, -16346, 8190
1306};
1307
1308void AM_SetNotchFilterParam(int16 *param)
1309{
1310 memcpy(Sph_Notch_Filter_Param, param, SAL_PARAMETERLEN_NOTCH*sizeof(int16));
1311}
1312
1313/**
1314 This function should used when DSP is turn on
1315*/
1316void AM_DSP_WriteNotchFilterParam( void )
1317{
1318 int I;
1319 volatile uint16* toPtr = SAL_Notch_GetFltCoefAddr();
1320 int16 *fromPtr = Sph_Notch_Filter_Param;
1321
1322 for( I = SAL_PARAMETERLEN_NOTCH; --I >= 0 ; )
1323 *toPtr++ = *fromPtr++;
1324
1325 Data_Sync_Barrier();
1326}
1327
1328
1329
1330/* For 65nm process, MCU has to reload DSP coefficient at each wake-up */
1331static void AM_ReloadDSPCoefficient( void )
1332{
1333 // AM_WriteSidetoneFIR(); // 93 not dsp sidetone so remove it
1334
1335 // if(!am.toneLoopbackRec) lagency
1336
1337#if defined(_SPE_ENH_MD_PARSE_)
1338 AM_WriteSpeechCompensationFilter(am.in_coeff_tmp, am.out_coeff_tmp);
1339 AM_WriteSpeechIIRCompensationFilter(am.IIR_in_coeff_tmp, am.IIR_out_coeff_tmp,am.MIC1_IIR_coeff_tmp,am.MIC2_IIR_coeff_tmp);
1340 AM_WriteWbSpeechCompensationFilter(am.wb_in_coeff_tmp, am.wb_out_coeff_tmp);
1341 AM_WriteWbSpeechIIRCompensationFilter(am.wb_IIR_in_coeff_tmp, am.wb_IIR_out_coeff_tmp,am.wb_MIC1_IIR_coeff_tmp,am.wb_MIC2_IIR_coeff_tmp);
1342 AM_WriteSWbSpeechCompensationFilter(am.swb_in_coeff_tmp, am.swb_out_coeff_tmp);
1343 AM_WriteWbSpeechIIRCompensationFilter(am.swb_IIR_in_coeff_tmp, am.swb_IIR_out_coeff_tmp,am.swb_MIC1_IIR_coeff_tmp,am.swb_MIC2_IIR_coeff_tmp);
1344#endif
1345 // AM_WriteAntiAliasFilter();
1346 // L1SP_Reload_MagiClarity_Para();
1347
1348 if ( !(am.state & AM_STATE_SPEECH) )
1349 L1SP_Reload_SPE_Para();
1350}
1351
1352
1353/* ========================================================================= */
1354/* internal function Functions */
1355/* ========================================================================= */
1356
1357/**
1358 This function should call "after AFE_Turnoff8K" and "before AFE_TurnOn8K".
1359 No user, so phase it out. The AFE_SetVoice8KMode is set directly by AP
1360*/
1361
1362/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
1363// static void AM_DSP_VMRecordOff( uint32 data , uint32 extraInfo);
1364
1365extern kal_uint32 SP3G_GetCodecMode(void);
1366#if defined(__C2K_SPEECH_SUPPORT__)
1367void AM_DSP_TurnOnC2KSDSP(int codec, uint32 extraInfo );
1368void AM_TurnOffC2KSDSP(void);
1369#endif
1370static void AM_DSP_SpeechOn( uint32 rat_mode, uint32 extraInfo )
1371{
1372 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
1373 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(5), L1AUDIO_Str_onoff(1) );
1374
1375 SAL_UltraSound_Removal_Switch(false);
1376 SAL_Set_OpenDsp(L1SP_GetOpenDSPFlag());
1377
1378 if(rat_mode == RAT_2G_MODE)
1379 {
1380#if defined(__VOLTE_SUPPORT__)
1381 am.sp4g_flag = false;
1382#endif
1383 am.sp3g_flag = false;
1384 if(L1SP_TCH_State()){
1385 AM_Get2GCodecInfo(&am.speech_mode, &am.sub_channel);
1386 }else{
1387 am.speech_mode = 0;
1388 am.sub_channel = 0;
1389 }
1390
1391#if defined(__SMART_PHONE_MODEM__)
1392 if(spc_isAcLoopback()){
1393 if(L1SP_TCH_State() == KAL_FALSE) {
1394 cc_Standby_Call_Open(0x3);
1395 }
1396 else {
1397 cc_2G_Call_Open(0, 0, am.sub_channel, ((extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON));
1398 }
1399 }
1400 else
1401#endif // __SMART_PHONE_MODEM__
1402 {
1403 if(L1SP_TCH_State() == KAL_FALSE) {
1404 cc_Standby_Call_Open(0x3);
1405 }
1406 else {
1407 cc_2G_Call_Open(am.speech_mode, am.speech_mode, am.sub_channel,
1408 ((extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON));
1409 }
1410 }
1411
1412 }
1413
1414#if defined( __UMTS_RAT__ )
1415 else if(rat_mode == RAT_3G_MODE
1416#ifdef __VIDEO_CALL_SUPPORT__
1417 || rat_mode == RAT_3G324M_MODE
1418#endif
1419 ){
1420 kal_uint16 delayR, delayW, delayM;
1421 kal_uint32 u32CurTime64us;
1422
1423 am.speech_mode = SP3G_GetCodecMode();
1424 am.sp3g_flag = true;
1425#if defined(__VOLTE_SUPPORT__)
1426 am.sp4g_flag = false;
1427#endif
1428 // only use Bit[0] to inidicate the resync require
1429
1430
1431 SP3G_GetSyncDelayRW( &delayR, &delayW, &delayM, &u32CurTime64us);
1432
1433 cc_3G_Call_Open(am.speech_mode, am.speech_mode, SP3G_IsDTXOn(), delayR, delayW, delayM, u32CurTime64us,
1434 ((extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON));
1435 }
1436#endif
1437#if defined(__VOLTE_SUPPORT__)
1438 else if(rat_mode == RAT_4G_MODE){
1439 am.speech_mode = SP4G_GetCodecMode();
1440 am.sp3g_flag = false;
1441 am.sp4g_flag = true;
1442 //get InitCodec
1443 //SAL_4G_Call_Open(am.speech_mode);
1444 SP4G_Call_Open(am.speech_mode, ((extraInfo&1)? PS_SRST_TYPE_DEV: PS_SRST_TYPE_CALLON));
1445 }
1446#endif
1447#if defined(__C2K_SPEECH_SUPPORT__)
1448 else if(rat_mode == RAT_C2K_MODE){
1449 am.sp3g_flag = false;
1450#if defined(__VOLTE_SUPPORT__)
1451 am.sp4g_flag = false;
1452#endif
1453 am.spc2k_flag = true;
1454 AM_DSP_TurnOnC2KSDSP(L1SP_GetC2KSO_Codec(), (extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON);
1455 }
1456#endif
1457 am.state |= AM_STATE_SPEECH;
1458 am.pre_speech_mode = am.speech_mode;
1459
1460 l1sp_NetworkStatusNotification();
1461 RB_INIT(am.ramp_point_queue);
1462}
1463
1464uint32 AM_GetNetworkRate()
1465{
1466 switch(L1SP_GetState()){
1467 case L1SP_STATE_2G_SPEECH_ON:
1468 return RAT_2G_MODE;
1469#if defined( __UMTS_RAT__ )
1470 case L1SP_STATE_3G_SPEECH_ON:
1471 case L1SP_STATE_3G_SPEECH_CLOSING:
1472 return RAT_3G_MODE;
1473#ifdef __VIDEO_CALL_SUPPORT__
1474 case L1SP_STATE_3G324M_SPEECH_ON:
1475 return RAT_3G324M_MODE;
1476#endif
1477#endif
1478#if defined(__VOLTE_SUPPORT__)
1479 case L1SP_STATE_4G_SPEECH_ON:
1480 case L1SP_STATE_4G_SPEECH_CLOSING:
1481 return RAT_4G_MODE;
1482#endif
1483#if defined(__C2K_SPEECH_SUPPORT__)
1484 case L1SP_STATE_C2K_SPEECH_ON:
1485 return RAT_C2K_MODE;
1486#endif
1487 default:
1488 return RAT_NONE_MODE;
1489 }
1490}
1491
1492/**
1493 @rat_mode: indicat the 2g/3g call status
1494 @extraInfo: bit[0]: 1 for device change to resync
1495*/
1496void AM_SpeechOn(uint32 rat_mode, uint32 extraInfo)
1497{
1498 MD_TRC_L1Audio_Msg_AM_Speech(1);
1499 AFE_TurnOn8K();//SAL user need to handle this for DSP Speech
1500
1501 AM_Enqueue( AM_DSP_SpeechOn, rat_mode, extraInfo, (rat_mode == RAT_2G_MODE) && L1SP_TCH_State() );
1502
1503 if(rat_mode == RAT_2G_MODE)
1504 AM_FlushQFunction();
1505}
1506
1507
1508static void AM_DSP_SpeechOff( uint32 data , uint32 extraInfo)
1509{
1510 (void)data;
1511
1512 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(5), L1AUDIO_Str_onoff(0) );
1513 // am.speech_off_delay = 10;
1514 //fix BIANCO
1515 //DP_KT_ATT = 0x0; // avoid SD buffer repeating if tone/keytone continues
1516
1517 Data_Sync_Barrier();
1518// cc_set_VBI_for_FSM(1);
1519 /*
1520 if( am.speech_state & SP_STATE_VMR ) // call drop while conversation recording
1521 AM_DSP_VMRecordOff( 0 , 0 );
1522 */
1523
1524 am.state &= ~AM_STATE_SPEECH;
1525
1526#if defined(__VOLTE_SUPPORT__)
1527 if(am.sp4g_flag){
1528 SP4G_Call_Close();
1529 am.sp4g_flag = false;
1530 }else
1531#endif
1532#if defined( __UMTS_RAT__ )
1533 if( am.sp3g_flag ){
1534 cc_3G_Call_Close(true);
1535
1536 am.sp3g_flag = false;
1537 }
1538 else
1539#endif
1540#if defined(__C2K_SPEECH_SUPPORT__)
1541 if( am.spc2k_flag ){
1542
1543 AM_TurnOffC2KSDSP();
1544
1545 am.spc2k_flag = false;
1546 } else
1547#endif
1548 cc_2G_Call_Close(true );
1549 //am.speech_mode = SAL_C2K_COD_MODE_UNDEF;
1550
1551
1552// cc_set_VBI_for_FSM(2);
1553}
1554
1555
1556/**
1557 @info: bit[0]: need to force dsp8k off or not; 1 for force, 0 for not
1558*/
1559void AM_SpeechOff( uint32 info )
1560{
yu.donge372c322023-08-30 20:25:04 -07001561 MD_TRC_VM_REC_DEBUG_VOC_DISABLE_STATE(am.state, am.speech_state);
rjw6c1fd8f2022-11-30 14:33:01 +08001562 SP_DSPTone_ForceEnd();
1563
1564 // if((info == 0)|| ((info&1)!=0))
1565 cc_set_VBI_for_FSM(1);
1566
1567 MD_TRC_L1Audio_Msg_AM_Speech(0);
1568 AM_Enqueue( AM_DSP_SpeechOff, info, 0, false );
1569
1570 AM_FlushQFunction();
1571
1572 // if((info == 0)|| ((info&1)!=0))
1573 cc_set_VBI_for_FSM(2);
1574
1575 if( (am.state == 0) || ((info&1)!=0))
1576 AFE_TurnOff8K();
1577}
1578
1579bool AM_IsSpeechOn( void )
1580{
1581 return( (bool)((am.state & AM_STATE_SPEECH) != 0) );
1582}
1583
1584bool AM_IsDataCardOn( void )
1585{
1586 return( (bool)((am.speech_state &= SP_STATE_DACA) != 0) );
1587}
1588
1589bool AM_IsAmInSpeechState( void )
1590{
1591 if ((am.state & (AM_STATE_SPEECH | AM_STATE_VOICE | AM_STATE_VOIP )) != 0)
1592 return true;
1593 else
1594 return false;
1595}
1596
1597void AM_SetSpeechMode( uint16 speech_mode, int8 sub_channel )
1598{
1599 am.speech_mode = speech_mode;
1600 am.sub_channel = sub_channel;
1601}
1602
1603uint16 AM_GetSpeechMode(void)
1604{
1605 return am.speech_mode;
1606}
1607
1608kal_bool AM_IsSpeechWB( void )
1609{
1610 return IsWBLink(am.speech_mode);
1611}
1612
1613#if defined( __UMTS_RAT__ )
1614/**
1615 extraInfo: come from rate
1616*/
1617void AM_DSP_RAT_sub_2G( uint32 data , uint32 extraInfo)
1618{
1619 (void)data;
1620 if(L1SP_TCH_State()){
1621 AM_Get2GCodecInfo(&am.speech_mode, &am.sub_channel);
1622 }else{
1623 am.speech_mode = 0;
1624 am.sub_channel = 0;
1625 }
1626 if( !(am.state & AM_STATE_SPEECH) )
1627 return;
1628 //VBI_End(); //When DSP in NB-AMR, driver set SC,SD mode as WB-AMR, and DSP will assert, and vice versa
1629 if(extraInfo == SAL_APP_TYPE_2GCall){
1630 cc_2G_Call_Close(true);
1631 }
1632 else if(extraInfo == SAL_APP_TYPE_3GCall){
1633 cc_3G_Call_Close(true);
1634 am.sp3g_flag = false;
1635 }
1636#if defined(__C2K_SPEECH_SUPPORT__)
1637 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1638 AM_DSP_TurnOffC2KSDSP(0, 0);
1639 }
1640#endif
1641#if defined(__VOLTE_SUPPORT__)
1642 else if(extraInfo == SAL_APP_TYPE_4GCall){
1643 SP4G_Call_Close();
1644 am.sp4g_flag = false;
1645 }
1646#endif
1647 cc_2G_Call_Open(am.speech_mode, am.speech_mode, am.sub_channel, SAL_SRST_TYPE_HO);
1648 AM_Reset_Enh(am.speech_mode);
1649 l1sp_NetworkStatusNotification();
1650 // l1sp_CodecStatusNotification(am.speech_mode);
1651}
1652
1653void AM_DSP_InterRAT_3G_to_2G( uint32 codec , uint32 extraInfo)
1654{
1655 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_3GCall);
1656 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_2G(am.speech_mode);
1657}
1658#if defined(__C2K_SPEECH_SUPPORT__)
1659void AM_DSP_InterRAT_C2K_to_2G( uint32 codec , uint32 extraInfo)
1660{
1661 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_C2KCall);
1662 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_2G(am.speech_mode);
1663}
1664#endif
1665#if defined(__VOLTE_SUPPORT__)
1666void AM_DSP_InterRAT_4G_to_2G( uint32 codec , uint32 extraInfo)
1667{
1668 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_4GCall);
1669 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_2G(am.speech_mode);
1670}
1671#endif
1672void AM_DSP_InterRAT_Standby_to_2G( uint32 codec , uint32 extraInfo)
1673{
1674 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_2GCall);
1675 MD_TRC_L1Audio_Msg_INTERRAT_STANDBY_TO_2G(am.speech_mode);
1676}
1677
1678void AM_InterRAT_3G_to_2G()
1679{
1680 AM_Enqueue( AM_DSP_InterRAT_3G_to_2G, 0, 0, false );
1681 AM_FlushQFunction();
1682}
1683#if defined(__C2K_SPEECH_SUPPORT__)
1684void AM_InterRAT_C2K_to_2G()
1685{
1686 AM_Enqueue( AM_DSP_InterRAT_C2K_to_2G, 0, 0, false );
1687 AM_FlushQFunction();
1688}
1689#endif
1690#if defined(__VOLTE_SUPPORT__)
1691void AM_InterRAT_4G_to_2G()
1692{
1693 AM_Enqueue( AM_DSP_InterRAT_4G_to_2G, 0, 0, false );
1694 AM_FlushQFunction();
1695}
1696#endif
1697void AM_InterRAT_Standby_to_2G()
1698{
1699 AM_Enqueue( AM_DSP_InterRAT_Standby_to_2G, 0, 0, false );
1700 AM_FlushQFunction();
1701}
1702
1703void AM_DSP_RAT_sub_3G(uint32 codec , uint32 extraInfo)
1704{
1705 kal_uint16 u16DelayR, u16DelayW, u16DelayM;
1706 kal_uint32 u32CurTime64us;
1707 am.speech_mode = codec;
1708 if( !(am.state & AM_STATE_SPEECH) )
1709 return;
1710 if(extraInfo == SAL_APP_TYPE_2GCall){
1711 cc_2G_Call_Close(true);
1712 }else if(extraInfo == SAL_APP_TYPE_3GCall){
1713 cc_3G_Call_Close(true);
1714 }
1715#if defined(__C2K_SPEECH_SUPPORT__)
1716 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1717 AM_DSP_TurnOffC2KSDSP(0, 0);
1718 }
1719#endif
1720#if defined(__VOLTE_SUPPORT__)
1721 else if(extraInfo == SAL_APP_TYPE_4GCall){
1722 SP4G_Call_Close();
1723 am.sp4g_flag = false;
1724 }
1725#endif
1726
1727 SP3G_GetSyncDelayRW( &u16DelayR, &u16DelayW, &u16DelayM, &u32CurTime64us);
1728 SAL_3G_Upd_Enc_Cod(codec);//for 3g codec internal, MT6280
1729 SAL_3G_Upd_Dec_Cod(codec);//for 3g codec internal, MT6280
1730#if defined(_MODEM_RESYNC_3G_)
1731 MD_TRC_L1Audio_Msg_AM_3G_Reset_Time_Drift();
1732#if defined( __UMTS_RAT__ )
1733 switch(L1SP_GetSIMStatus()){
1734 case SP_3G_SIM_FDD_ACTIVE:
1735 UL1D_Speech_Resync_Reset_Time_Offset();
1736 break;
1737#if defined(__UMTS_TDD128_MODE__)
1738 case SP_3G_SIM_TDD_ACTIVE:
1739 TL1C_Reset_Time_Drift();
1740 break;
1741#endif
1742 default:
1743 ASSERT(0);
1744 }
1745#endif
1746#endif
1747
1748#if defined( __UMTS_RAT__ ) && !defined(__L1_STANDALONE__)
1749 switch(L1SP_GetSIMStatus()){
1750 case SP_3G_SIM_FDD_ACTIVE:
1751 if(query_ps_conf_test_mode()==PS_CONF_TEST_FTA)
1752 SP3G_SetDTX(false);
1753 else
1754 SP3G_SetDTX(true);
1755 break;
1756 case SP_3G_SIM_TDD_ACTIVE:
1757 break;
1758 default:
1759 ASSERT(0);
1760 }
1761#endif
1762 cc_3G_Call_Open(codec, codec, SP3G_IsDTXOn(), u16DelayR, u16DelayW, u16DelayM, u32CurTime64us, SAL_SRST_TYPE_HO);
1763 MD_TRC_L1Audio_Msg_SP3G_FORCE_RESYNC( codec, codec, u16DelayR, u16DelayW);
1764 am.sp3g_flag = true;
1765 AM_Reset_Enh(codec);
1766 l1sp_NetworkStatusNotification();
1767 // l1sp_CodecStatusNotification(am.speech_mode);
1768}
1769
1770void AM_DSP_InterRAT_2G_to_3G( uint32 codec , uint32 extraInfo)
1771{
1772 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_2GCall);
1773 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_3G(codec);
1774}
1775
1776void AM_DSP_3G_INTRARAT (uint32 codec, uint32 extraInfo)
1777{
1778 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_3GCall);
1779 MD_TRC_L1Audio_Msg_3G_INTRARAT(codec);
1780}
1781
1782#if defined(__C2K_SPEECH_SUPPORT__)
1783void AM_DSP_InterRAT_C2K_to_3G( uint32 codec , uint32 extraInfo)
1784{
1785 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_C2KCall);
1786 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_3G(codec);
1787}
1788#endif
1789
1790#if defined(__VOLTE_SUPPORT__)
1791void AM_DSP_InterRAT_4G_to_3G( uint32 codec , uint32 extraInfo)
1792{
1793 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_4GCall);
1794 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_3G(codec);
1795}
1796#endif
1797
1798void AM_InterRAT_2G_to_3G(uint32 codec)
1799{
1800 AM_Enqueue( AM_DSP_InterRAT_2G_to_3G, codec, 0, false );
1801 AM_FlushQFunction();
1802}
1803
1804void AM_3G_INTRARAT(uint32 codec)
1805{
1806 AM_Enqueue( AM_DSP_3G_INTRARAT, codec, 0, false );
1807 AM_FlushQFunction();
1808}
1809
1810#if defined(__C2K_SPEECH_SUPPORT__)
1811void AM_InterRAT_C2K_to_3G(uint32 codec)
1812{
1813 AM_Enqueue( AM_DSP_InterRAT_C2K_to_3G, codec, 0, false );
1814 AM_FlushQFunction();
1815}
1816#endif
1817
1818#if defined(__VOLTE_SUPPORT__)
1819void AM_InterRAT_4G_to_3G(uint32 codec)
1820{
1821 AM_Enqueue( AM_DSP_InterRAT_4G_to_3G, codec, 0, false );
1822 AM_FlushQFunction();
1823}
1824#endif
1825#endif
1826
1827#if defined(__C2K_SPEECH_SUPPORT__)
1828/*
1829 extraInfo: 0:call on; 1: HO; 2: resync; 3: dev Change
1830*/
1831void AM_DSP_TurnOnC2KSDSP(int codec, uint32 extraInfo ){
1832
1833 uint16 DelR, DelW, DelM;
1834
1835 MD_TRC_C2K_AM_DSP_TurnOnC2KSDSP(am.speech_mode, codec);
1836
1837 SPC2K_GetSyncDelayRW( &DelR, &DelW, &DelM);
1838 if((am.speech_mode != codec) && (!am.c2k_flag)) {
1839 cc_C2K_Call_Open (codec, _C2K_DTX_SUPPORT_, DelR, DelW, DelM, extraInfo); //VBIRest();
1840
1841 am.speech_mode = codec;
1842 am.c2k_flag = true; // ys
1843 }else{
1844 cc_C2K_Call_Open (codec, _C2K_DTX_SUPPORT_, DelR, DelW, DelM, extraInfo);//check by daniel//VBIRest();
1845 }
1846}
1847void AM_DSP_TurnOffC2KSDSP(uint32 data , uint32 extraInfo)
1848{
1849 MD_TRC_C2K_AM_DSP_TurnOffC2KSDSP();
1850
1851 cc_C2K_Call_Close(true);
1852
1853 //am.speech_mode = SAL_C2K_COD_MODE_UNDEF;
1854 am.c2k_flag = false;
1855}
1856
1857void AM_TurnOffC2KSDSP(void)
1858{
1859 //TO , move c2kflag here for symmetry
1860 AM_Enqueue( AM_DSP_TurnOffC2KSDSP, 0, 0, false );
1861 AM_FlushQFunction();
1862}
1863
1864void AM_DSP_RAT_sub_C2K(uint32 codec , uint32 extraInfo)
1865{
1866 if( !(am.state & AM_STATE_SPEECH) )
1867 return;
1868 if(extraInfo == SAL_APP_TYPE_2GCall){
1869 cc_2G_Call_Close(true);
1870 } else if(extraInfo == SAL_APP_TYPE_3GCall){
1871 cc_3G_Call_Close(true);
1872 am.sp3g_flag = false;
1873 }
1874#if defined(__VOLTE_SUPPORT__)
1875 else if(extraInfo == SAL_APP_TYPE_4GCall){
1876 SP4G_Call_Close();
1877 am.sp4g_flag = false;
1878 }
1879#endif
1880#if defined(__C2K_SPEECH_SUPPORT__)
1881 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1882 AM_DSP_TurnOffC2KSDSP(0, 0);
1883 }
1884#endif
1885 AM_DSP_TurnOnC2KSDSP(codec, 1);
1886 am.spc2k_flag = true;
1887 AM_Reset_Enh(codec);
1888 l1sp_NetworkStatusNotification();
1889}
1890
1891void AM_DSP_InterRAT_2G_to_C2K( uint32 codec , uint32 extraInfo)
1892{
1893 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_2GCall);
1894 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_C2K(codec);
1895}
1896
1897void AM_DSP_C2K_IntraRAT (uint32 codec, uint32 extraInfo)
1898{
1899 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_C2KCall);
1900 MD_TRC_L1Audio_Msg_C2K_INTRARAT(codec);
1901}
1902
1903#if defined( __UMTS_RAT__ )
1904void AM_DSP_InterRAT_3G_to_C2K( uint32 codec , uint32 extraInfo)
1905{
1906 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_3GCall);
1907 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_C2K(codec);
1908}
1909#endif
1910#if defined(__VOLTE_SUPPORT__)
1911void AM_DSP_InterRAT_4G_to_C2K( uint32 codec , uint32 extraInfo)
1912{
1913 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_4GCall);
1914 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_C2K(codec);
1915}
1916#endif
1917
1918void AM_InterRAT_2G_to_C2K(uint32 codec)
1919{
1920 AM_Enqueue( AM_DSP_InterRAT_2G_to_C2K, codec, 0, false );
1921 AM_FlushQFunction();
1922}
1923
1924void AM_C2K_IntraRAT(uint32 codec)
1925{
1926 AM_Enqueue( AM_DSP_C2K_IntraRAT, codec, 0, false );
1927 AM_FlushQFunction();
1928}
1929#if defined( __UMTS_RAT__ )
1930void AM_InterRAT_3G_to_C2K(uint32 codec)
1931{
1932 AM_Enqueue( AM_DSP_InterRAT_3G_to_C2K, codec, 0, false );
1933 AM_FlushQFunction();
1934}
1935#endif
1936#if defined(__VOLTE_SUPPORT__)
1937void AM_InterRAT_4G_to_C2K(uint32 codec)
1938{
1939 AM_Enqueue( AM_DSP_InterRAT_4G_to_C2K, codec, 0, false );
1940 AM_FlushQFunction();
1941}
1942#endif
1943#endif
1944
1945#if defined(__VOLTE_SUPPORT__)
1946void AM_DSP_RAT_sub_4G(uint32 codec , uint32 extraInfo, uint32 resetType)
1947{
1948 //kal_uint16 u16DelayR, u16DelayW; //unused
1949 am.speech_mode = codec;
1950 if( !(am.state & AM_STATE_SPEECH) )
1951 return;
1952
1953 if(PS_SRST_TYPE_HO_WITH_VBIEND == resetType)
1954 {
1955 if(extraInfo == SAL_APP_TYPE_2GCall){
1956 cc_2G_Call_Close(true);
1957 } else if(extraInfo == SAL_APP_TYPE_3GCall){
1958 cc_3G_Call_Close(true);
1959 am.sp3g_flag = false;
1960 }
1961#if defined(__C2K_SPEECH_SUPPORT__)
1962 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1963 AM_DSP_TurnOffC2KSDSP(0, 0);
1964 }
1965#endif
1966 else if(extraInfo == SAL_APP_TYPE_4GCall){
1967 SP4G_Call_Close();
1968 }
1969 }
1970
1971 //SP3G_GetSyncDelayRW( &u16DelayR, &u16DelayW);//????
1972 //SAL_4G_Upd_Enc_Cod(codec);//for 3g codec internal, MT6280
1973 //SAL_4G_Upd_Dec_Cod(codec);//for 3g codec internal, MT6280
1974 switch(SP4G_GetL2Mode()){
1975#if defined(__LTE_RAT__)
1976 case SP_PSCALL_EMAC:
1977 SAL_Set_PSRANType(SAL_PSRAN_TYPE_LTE);
1978 break;
1979#endif
1980#if defined(__NR_RAT__)
1981 case SP_PSCALL_NMAC:
1982 SAL_Set_PSRANType(SAL_PSRAN_TYPE_NR);
1983 break;
1984#endif
1985 case SP_PSCALL_NONE:
1986 SAL_Set_PSRANType(SAL_PSRAN_TYPE_NONE);
1987 break;
1988 default:
1989 ASSERT(0);
1990 break;
1991 }
1992 //SAL_4G_Call_Open(codec);
1993 SP4G_Call_Open(codec, resetType);
1994 AM_Reset_Enh(codec);
1995 l1sp_NetworkStatusNotification();
1996 // l1sp_CodecStatusNotification(am.speech_mode);
1997 am.sp4g_flag = true;
1998}
1999
2000void AM_DSP_InterRAT_2G_to_4G( uint32 codec , uint32 extraInfo)
2001{
2002 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729);//context is under task level, so g-series cannot be used
2003 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_2GCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2004 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2005}
2006#if defined( __UMTS_RAT__ )
2007void AM_DSP_InterRAT_3G_to_4G( uint32 codec , uint32 extraInfo)
2008{
2009 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729);//context is under task level, so g-series cannot be used
2010 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_3GCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2011 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2012}
2013#endif
2014#if defined(__C2K_SPEECH_SUPPORT__)
2015void AM_DSP_InterRAT_C2K_to_4G( uint32 codec , uint32 extraInfo)
2016{
2017 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_C2KCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2018 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2019}
2020#endif
2021
2022void AM_DSP_4G_INTRARAT (uint32 codec, uint32 resetType)
2023{
2024 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729); context is under task level, so g-series can be used
2025 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_4GCall, resetType);
2026 MD_TRC_L1Audio_Msg_4G_INTRARAT(codec, resetType);
2027}
2028
2029void AM_InterRAT_2G_to_4G(uint32 codec)
2030{
2031 AM_Enqueue( AM_DSP_InterRAT_2G_to_4G, codec, 0, false );
2032 AM_FlushQFunction();
2033}
2034#if defined( __UMTS_RAT__ )
2035void AM_InterRAT_3G_to_4G(uint32 codec)
2036{
2037 AM_Enqueue( AM_DSP_InterRAT_3G_to_4G, codec, 0, false );
2038 AM_FlushQFunction();
2039}
2040#endif
2041#if defined(__C2K_SPEECH_SUPPORT__)
2042void AM_InterRAT_C2K_to_4G(uint32 codec)
2043{
2044 AM_Enqueue( AM_DSP_InterRAT_C2K_to_4G, codec, 0, false );
2045 AM_FlushQFunction();
2046}
2047#endif
2048void AM_4G_INTRARAT(uint32 codec, uint32 resetType)
2049{
2050 AM_Enqueue( AM_DSP_4G_INTRARAT, codec, resetType, false );
2051 AM_FlushQFunction();
2052}
2053
2054void SAL_4G_AMRCall_Open(int codec, kal_bool isDTX, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType);
2055void SAL_4G_AMRCall_Close();
2056#if defined(__G_CODEC_SUPPORT__)
2057void SAL_4G_GSeriesCall_Open(int codec, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType);
2058void SAL_4G_GSeriesCall_Close(int codec);
2059#endif
2060#if defined(__EVS_CODEC_SUPPORT__)
2061void SAL_4G_EVSCall_Open(int codec, kal_bool isDTX, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType);
2062void SAL_4G_EVSCall_Close(void);
2063#endif //#if defined(__EVS_CODEC_SUPPORT__)
2064
2065void SP4G_Call_Open(uint16 codec, PS_RESET_TYPE_t resetType)
2066{
2067 kal_uint16 delayR, delayW, delayM;
2068 kal_uint32 u32CurTime64us;
2069
2070 if(PS_SRST_TYPE_HO_WITH_VBIEND == resetType)
2071 {
2072 ASSERT(am.codec_4g == -1);
2073 }
2074 SAL_Set_AWBPlusFlag(0);
2075 am.codec_4g = codec;
2076 SP4G_GetSyncDelayRW( &delayR, &delayW, &delayM, &u32CurTime64us);
2077#if defined(__G_CODEC_SUPPORT__)
2078 if((codec >= SP4G_CODEC_G711) && (codec <= SP4G_CODEC_G729)){
2079 SAL_4G_GSeriesCall_Open(codec, delayR, delayW, delayM, u32CurTime64us, resetType);
2080 }else
2081#endif
2082 {
2083#if defined(__EVS_CODEC_SUPPORT__)
2084 if(is_EVS_codec((uint8)codec)){
2085 if( get_sp4g_fake_EVS_IO() )
2086 {
2087 SAL_Set_AWBPlusFlag(1);
2088 }
2089 SAL_4G_EVSCall_Open((kal_uint32)codec, (kal_uint32)SP4G_IsDTXOn(), (kal_uint32)delayR, (kal_uint32)delayW, (kal_uint32)delayM, (kal_uint32)u32CurTime64us, resetType);
2090 }else
2091#endif //#if defined(__EVS_CODEC_SUPPORT__)
2092 {
2093 SAL_4G_AMRCall_Open(codec, SP4G_IsDTXOn(), delayR, delayW, delayM, u32CurTime64us, resetType);
2094 }
2095 }
2096}
2097
2098void SP4G_Call_Close(void){
2099 ASSERT(am.codec_4g != -1);
2100 SAL_Set_AWBPlusFlag(0);
2101#if defined(__G_CODEC_SUPPORT__)
2102 if( is_g_codec(am.codec_4g) ){
2103 SAL_4G_GSeriesCall_Close(SAL_PCM_NARROWBAND);
2104 }else
2105#endif
2106 {
2107#if defined(__EVS_CODEC_SUPPORT__)
2108 if(is_EVS_codec(am.codec_4g)){
2109 SAL_4G_EVSCall_Close();
2110 }else
2111#endif //#if defined(__EVS_CODEC_SUPPORT__)
2112 {
2113 SAL_4G_AMRCall_Close();
2114 }
2115 }
2116 am.codec_4g = -1;
2117}
2118//extern void SAL_Set4G(bool b);
2119void SAL_4G_AMRCall_Open(int codec, kal_bool isDTX, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType)
2120{
2121 //SP4G_GetSyncDelayRW( &u16DelayR, &u16DelayW);
2122 SAL_3G_Upd_Enc_Cod(codec);
2123 SAL_3G_Upd_Dec_Cod(codec);
2124 //cc_3G_Call_Open(codec, codec, SP4G_IsDTXOn(), u16DelayR, u16DelayW, DSP_PCM_IDLE_DELAY_TABLE[6][2]);
2125 //SAL_Set4G(true);
2126 cc_4G_Call_Open_temp(codec, codec, isDTX, u16DelayR, u16DelayW, idle_delay, u32CurTime64us, resetType);
2127 MD_TRC_L1Audio_Msg_SP4G_FORCE_RESYNC( codec, codec, u16DelayR, u16DelayW);
2128};
2129
2130void SAL_4G_AMRCall_Close()
2131{
2132 cc_4G_Call_Close_temp(true);
2133 //SAL_Set4G(false);
2134}
2135
2136
2137void SAL_4G_GSeriesCall_Open(int codec, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us,
2138 kal_uint32 resetType){
2139 int band_mod = SAL_NB;
2140 if(SP4G_CODEC_G722 == codec )
2141 band_mod = SAL_WB;
2142
2143 //SAL_Set4G(true);
2144 //memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
2145 //cfg.idle = false;//true;
2146 //cfg.swi = SAL_PCMEX_SWITCH_ON;
2147 //cfg.type = SAL_PCMEX_TYPE_VOLTE;
2148 //cfg.band = band;//SAL_PCM_NARROWBAND
2149 //SAL_PcmEx_Config(&cfg);
2150
2151 /*if(band == SAL_PCM_WIDEBAND)
2152 {
2153 AMR_codec_temp = SP4G_CODEC_WBAMR_12_65;
2154 }
2155 else
2156 {
2157 AMR_codec_temp = SP4G_CODEC_AMR_12_2;
2158 }
2159 SAL_3G_Upd_Enc_Cod(AMR_codec_temp);
2160 SAL_3G_Upd_Dec_Cod(AMR_codec_temp);*/
2161 cc_4G_G_Codec_Call_Open(band_mod, u16DelayR, u16DelayW, idle_delay, u32CurTime64us, resetType);
2162
2163 {
2164 void GSeries_Encode_Init(SP4G_Codec codec);
2165 void GSeries_Decode_Init(SP4G_Codec codec);
2166 GSeries_Encode_Init(codec);
2167 GSeries_Decode_Init(codec);
2168 //SP4G_SetCodec(codec);//fix
2169 }
2170 Extcodec_Call_Open();
2171#if 0
2172/* under construction !*/
2173/* under construction !*/
2174/* under construction !*/
2175/* under construction !*/
2176/* under construction !*/
2177/* under construction !*/
2178/* under construction !*/
2179/* under construction !*/
2180#if 0
2181/* under construction !*/
2182/* under construction !*/
2183/* under construction !*/
2184/* under construction !*/
2185/* under construction !*/
2186#else /*#if 0*/
2187/* under construction !*/
2188/* under construction !*/
2189/* under construction !*/
2190/* under construction !*/
2191/* under construction !*/
2192/* under construction !*/
2193/* under construction !*/
2194/* under construction !*/
2195/* under construction !*/
2196/* under construction !*/
2197/* under construction !*/
2198#endif /*#if 0*/
2199/* under construction !*/
2200/* under construction !*/
2201/* under construction !*/
2202/* under construction !*/
2203#ifndef L1D_TEST
2204/* under construction !*/
2205/* under construction !*/
2206#endif
2207/* under construction !*/
2208#endif
2209 kal_prompt_trace(MOD_L1SP, "[SAL_4G_GSeriesCall_Open] SAL_PcmEx_CheckState OK");
2210
2211
2212}
2213
2214
2215void SAL_4G_GSeriesCall_Close(int codec){
2216 Extcodec_Call_Close();
2217#if 0
2218/* under construction !*/
2219/* under construction !*/
2220/* under construction !*/
2221/* under construction !*/
2222/* under construction !*/
2223/* under construction !*/
2224/* under construction !*/
2225/* under construction !*/
2226/* under construction !*/
2227/* under construction !*/
2228/* under construction !*/
2229/* under construction !*/
2230/* under construction !*/
2231/* under construction !*/
2232/* under construction !*/
2233#endif
2234 ////SAL_Set4G(false);
2235 {
2236 void GSeries_Encode_DeInit();
2237 void GSeries_Decode_DeInit();
2238 }
2239
2240 //fsju
2241 cc_4G_G_Codec_Call_Close(true);
2242}
2243
2244
2245#if defined(__EVS_CODEC_SUPPORT__)
2246void SP4G_EVS_CallOpenSetPar(void);
2247#endif //#if defined(__EVS_CODEC_SUPPORT__)
2248void SAL_4G_EVSCall_Open(int codec, kal_bool isDTX, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType)
2249{
2250#if defined(__EVS_CODEC_SUPPORT__)
2251 SP4G_EVS_CallOpenSetPar();
2252#endif //#if defined(__EVS_CODEC_SUPPORT__)
2253
2254 //cc_4G_EVS_Codec_Call_Open(codec, codec, 0/*isDTX*/, u16DelayR, u16DelayW, idle_delay, u32CurTime64us);
2255 cc_4G_EVS_Codec_Call_Open((kal_uint32)codec, (kal_uint32)isDTX, (kal_uint32)u16DelayR, (kal_uint32)u16DelayW, (kal_uint32)idle_delay, (kal_uint32)u32CurTime64us, resetType);
2256
2257 //kal_prompt_trace(MOD_L1SP, "[SAL_4G_EVSCall_Open] SAL_PcmEx_CheckState OK");
2258 MD_TRC_L1Audio_Msg_SP4G_EVSSeriesCall_Open_OK();
2259}
2260
2261
2262void SAL_4G_EVSCall_Close(void)
2263{
2264 cc_4G_EVS_Codec_Call_Close(1);
2265}
2266
2267
2268#endif
2269
2270kal_bool AM_Is_4G()
2271{
2272#if defined(__VOLTE_SUPPORT__)
2273 return am.sp4g_flag;
2274#else
2275 return KAL_FALSE;
2276#endif
2277}
2278
2279
2280
2281/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2282#if 0
2283/* under construction !*/
2284/* under construction !*/
2285/* under construction !*/
2286/* under construction !*/
2287/* under construction !*/
2288/* under construction !*/
2289/* under construction !*/
2290/* under construction !*/
2291/* under construction !*/
2292/* under construction !*/
2293#endif
2294
2295/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2296static void AM_DSP_VMRecordOn( uint32 speech_mode , uint32 extraInfo)
2297{
2298 Sal_VM_Config_t cfg_t;
2299 memset(&cfg_t, 0, sizeof(Sal_VM_Config_t));
2300
2301 cfg_t.swi = SAL_VM_SWITCH_ON;
2302
2303 if( am.state & (AM_STATE_SPEECH |AM_STATE_VOIP |AM_STATE_VOICE) ) { /* Conversation Recording */
2304 ASSERT(!(am.speech_state & SP_STATE_VMR));
2305 cfg_t.idle = false;
2306 am.speech_state |= SP_STATE_VMR;
2307 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(0) , L1AUDIO_Str_onoff(1) );
2308 }
2309 else { /* VM in idle mode */
2310#if 0
2311/* under construction !*/
2312/* under construction !*/
2313/* under construction !*/
2314/* under construction !*/
2315#if defined(AMRWB_ENCODE) // not define in samrt phone
2316/* under construction !*/
2317/* under construction !*/
2318/* under construction !*/
2319/* under construction !*/
2320/* under construction !*/
2321#endif//#if defined(AMRWB_ENCODE)
2322/* under construction !*/
2323/* under construction !*/
2324/* under construction !*/
2325/* under construction !*/
2326/* under construction !*/
2327/* under construction !*/
2328/* under construction !*/
2329/* under construction !*/
2330/* under construction !*/
2331/* under construction !*/
2332#endif
2333 }
2334
2335 SAL_VM_Config(&cfg_t);
2336
2337}
2338
2339void AM_VMRecordOn( void )
2340{
2341 AM_Enqueue( AM_DSP_VMRecordOn, 0, 0, false );
2342
2343 AM_FlushQFunction();
2344}
2345
2346
2347static void AM_DSP_VMRecordOff( uint32 data , uint32 extraInfo)
2348{
2349 (void)data;
2350 Sal_VM_Config_t cfg_t;
2351 memset(&cfg_t, 0, sizeof(Sal_VM_Config_t));
2352
2353 cfg_t.swi = SAL_VM_SWITCH_OFF;
2354 cfg_t.idle = false;
2355
2356 if(am.speech_state & SP_STATE_VMR) /* Conversation Recording */
2357 {
2358 am.speech_state &= ~SP_STATE_VMR;
2359 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(0) , L1AUDIO_Str_onoff(0) );
2360 SAL_VM_Config(&cfg_t);
2361 }
2362 else /* VM in idle mode */
2363 {
2364#if 0
2365/* under construction !*/
2366/* under construction !*/
2367/* under construction !*/
2368/* under construction !*/
2369/* under construction !*/
2370/* under construction !*/
2371/* under construction !*/
2372/* under construction !*/
2373/* under construction !*/
2374#endif
2375 }
2376}
2377
2378void AM_VMRecordOff( void )
2379{
2380#if 0
2381/* under construction !*/
2382/* under construction !*/
2383/* under construction !*/
2384/* under construction !*/
2385/* under construction !*/
2386#endif
2387 AM_Enqueue( AM_DSP_VMRecordOff, 0, 0, false );
2388}
2389
2390/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2391#if 0
2392/* under construction !*/
2393/* under construction !*/
2394/* under construction !*/
2395/* under construction !*/
2396/* under construction !*/
2397/* under construction !*/
2398/* under construction !*/
2399/* under construction !*/
2400/* under construction !*/
2401/* under construction !*/
2402/* under construction !*/
2403/* under construction !*/
2404/* under construction !*/
2405/* under construction !*/
2406/* under construction !*/
2407/* under construction !*/
2408/* under construction !*/
2409/* under construction !*/
2410/* under construction !*/
2411/* under construction !*/
2412/* under construction !*/
2413/* under construction !*/
2414/* under construction !*/
2415/* under construction !*/
2416/* under construction !*/
2417/* under construction !*/
2418/* under construction !*/
2419/* under construction !*/
2420/* under construction !*/
2421/* under construction !*/
2422/* under construction !*/
2423/* under construction !*/
2424/* under construction !*/
2425/* under construction !*/
2426/* under construction !*/
2427/* under construction !*/
2428/* under construction !*/
2429/* under construction !*/
2430/* under construction !*/
2431/* under construction !*/
2432/* under construction !*/
2433/* under construction !*/
2434/* under construction !*/
2435/* under construction !*/
2436/* under construction !*/
2437/* under construction !*/
2438/* under construction !*/
2439/* under construction !*/
2440/* under construction !*/
2441/* under construction !*/
2442/* under construction !*/
2443/* under construction !*/
2444/* under construction !*/
2445/* under construction !*/
2446/* under construction !*/
2447/* under construction !*/
2448/* under construction !*/
2449/* under construction !*/
2450/* under construction !*/
2451/* under construction !*/
2452/* under construction !*/
2453/* under construction !*/
2454/* under construction !*/
2455/* under construction !*/
2456/* under construction !*/
2457/* under construction !*/
2458/* under construction !*/
2459/* under construction !*/
2460/* under construction !*/
2461/* under construction !*/
2462/* under construction !*/
2463/* under construction !*/
2464/* under construction !*/
2465/* under construction !*/
2466/* under construction !*/
2467/* under construction !*/
2468/* under construction !*/
2469/* under construction !*/
2470/* under construction !*/
2471/* under construction !*/
2472/* under construction !*/
2473/* under construction !*/
2474/* under construction !*/
2475/* under construction !*/
2476/* under construction !*/
2477/* under construction !*/
2478/* under construction !*/
2479/* under construction !*/
2480/* under construction !*/
2481/* under construction !*/
2482/* under construction !*/
2483/* under construction !*/
2484/* under construction !*/
2485/* under construction !*/
2486/* under construction !*/
2487/* under construction !*/
2488/* under construction !*/
2489/* under construction !*/
2490/* under construction !*/
2491/* under construction !*/
2492/* under construction !*/
2493/* under construction !*/
2494/* under construction !*/
2495/* under construction !*/
2496/* under construction !*/
2497/* under construction !*/
2498/* under construction !*/
2499/* under construction !*/
2500/* under construction !*/
2501/* under construction !*/
2502/* under construction !*/
2503#endif
2504
2505/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2506static void AM_DSP_KeyToneOn( uint32 data , uint32 extraInfo)
2507{
2508 (void)data;
2509 ASSERT(!(am.state & AM_STATE_KEYTONE));
2510 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(0), L1AUDIO_Str_onoff(1) );
2511
2512 if ( am.state == 0 ) { // ( (am.state & ~AM_STATE_AVSYNC) == 0 ) {
2513 AFE_TurnOn8K();
2514 // AM_Write_Idle_Delay(4); // driver dost not support idle playback function, remove
2515 VBI_Reset();
2516 }
2517 am.state |= AM_STATE_KEYTONE;
2518}
2519
2520void AM_KeyToneOn( void )
2521{
2522 AM_Enqueue( AM_DSP_KeyToneOn, 0, 0, false );
2523}
2524
2525static void AM_DSP_KeyToneOff( uint32 data , uint32 extraInfo)
2526{
2527 (void)data;
2528 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(0), L1AUDIO_Str_onoff(0) );
2529 am.state &= ~AM_STATE_KEYTONE;
2530
2531 if(am.state == 0)
2532 VBI_End();
2533
2534 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2535 AFE_TurnOff8K();
2536}
2537
2538void AM_KeyToneOff( void )
2539{
2540 AM_Enqueue( AM_DSP_KeyToneOff, 0, 0, false );
2541}
2542
2543bool AM_IsKeyToneOn( void )
2544{
2545 if (am.state & AM_STATE_KEYTONE)
2546 return true;
2547 return false;
2548}
2549
2550/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2551static void AM_DSP_ToneOn( uint32 data , uint32 extraInfo)
2552{
2553 (void)data;
2554 ASSERT(!(am.state & AM_STATE_TONE));
2555 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(1), L1AUDIO_Str_onoff(1) );
2556
2557 if( am.state == 0 ) { // ( (am.state & ~AM_STATE_AVSYNC) == 0) {
2558 AFE_TurnOn8K();
2559 // AM_Write_Idle_Delay(4); // driver not support idle playback function, so remove
2560 VBI_Reset();
2561 }
2562 am.state |= AM_STATE_TONE;
2563}
2564
2565void AM_ToneOn( void )
2566{
2567 AM_Enqueue( AM_DSP_ToneOn, 0, 0, false );
2568
2569
2570}
2571
2572static void AM_DSP_ToneOff( uint32 data , uint32 extraInfo)
2573{
2574 (void)data;
2575 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(1), L1AUDIO_Str_onoff(0) );
2576 am.state &= ~AM_STATE_TONE;
2577
2578 if( am.state == 0 )
2579 VBI_End();
2580
2581 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2582 AFE_TurnOff8K();
2583}
2584
2585void AM_ToneOff( void )
2586{
2587 AM_Enqueue( AM_DSP_ToneOff, 0, 0, false );
2588}
2589
2590bool AM_IsToneOn( void )
2591{
2592 if (am.state & AM_STATE_TONE)
2593 return true;
2594 return false;
2595}
2596
2597
2598/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2599
2600static void AM_DSP_PCM8K_PlaybackOn( uint32 data , uint32 extraInfo)
2601{
2602 uint16 u16DelayR, u16DelayW, u16DelayM;
2603
2604 (void)data;
2605
2606 if( am.state == 0 ) {
2607 AFE_TurnOn8K();
2608 SAL_Get_Delay(SAL_DEALY_PCM8K_PB, SAL_DELAY_NA, SAL_DELAY_NA, &u16DelayR, &u16DelayW, &u16DelayM);
2609 SAL_App_Open(u16DelayR, u16DelayW, u16DelayM);
2610 }
2611// #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2612 if ( data == 1 )
2613 {
2614 ASSERT(!(am.state & AM_STATE_SND_EFFECT));
2615 am.state |= AM_STATE_SND_EFFECT;
2616 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(9), L1AUDIO_Str_onoff(1) );
2617 }
2618 else
2619// #endif // #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2620 {
2621 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
2622 am.state |= AM_STATE_VOICE;
2623 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(2), L1AUDIO_Str_onoff(1) );
2624 }
2625}
2626
2627#if 0
2628/* under construction !*/
2629/* under construction !*/
2630/* under construction !*/
2631/* under construction !*/
2632/* under construction !*/
2633/* under construction !*/
2634/* under construction !*/
2635#endif
2636
2637static void AM_DSP_PCM8K_PlaybackOff( uint32 data , uint32 extraInfo)
2638{
2639 (void)data;
2640
2641// #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2642 if( data == 1 )
2643 {
2644 am.state &= ~AM_STATE_SND_EFFECT;
2645 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(9), L1AUDIO_Str_onoff(0) );
2646 }
2647 else
2648// #endif // #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2649 {
2650 am.state &= ~AM_STATE_VOICE;
2651 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(2), L1AUDIO_Str_onoff(0) );
2652 }
2653 SAL_App_Close(am.state == 0);
2654
2655 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2656 AFE_TurnOff8K();
2657}
2658
2659#if 0
2660/* under construction !*/
2661/* under construction !*/
2662/* under construction !*/
2663/* under construction !*/
2664/* under construction !*/
2665/* under construction !*/
2666/* under construction !*/
2667/* under construction !*/
2668/* under construction !*/
2669/* under construction !*/
2670/* under construction !*/
2671/* under construction !*/
2672/* under construction !*/
2673/* under construction !*/
2674/* under construction !*/
2675/* under construction !*/
2676/* under construction !*/
2677/* under construction !*/
2678/* under construction !*/
2679/* under construction !*/
2680#endif
2681
2682
2683/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2684#if 0
2685/* under construction !*/
2686/* under construction !*/
2687/* under construction !*/
2688/* under construction !*/
2689/* under construction !*/
2690/* under construction !*/
2691/* under construction !*/
2692/* under construction !*/
2693/* under construction !*/
2694/* under construction !*/
2695/* under construction !*/
2696/* under construction !*/
2697/* under construction !*/
2698/* under construction !*/
2699/* under construction !*/
2700/* under construction !*/
2701/* under construction !*/
2702/* under construction !*/
2703/* under construction !*/
2704/* under construction !*/
2705/* under construction !*/
2706/* under construction !*/
2707/* under construction !*/
2708/* under construction !*/
2709/* under construction !*/
2710/* under construction !*/
2711/* under construction !*/
2712/* under construction !*/
2713/* under construction !*/
2714/* under construction !*/
2715/* under construction !*/
2716/* under construction !*/
2717/* under construction !*/
2718/* under construction !*/
2719/* under construction !*/
2720/* under construction !*/
2721/* under construction !*/
2722/* under construction !*/
2723/* under construction !*/
2724/* under construction !*/
2725/* under construction !*/
2726/* under construction !*/
2727/* under construction !*/
2728/* under construction !*/
2729#endif
2730/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2731
2732uint32 AM_GetRecordFormat()
2733{
2734 return am.record_format;
2735}
2736
2737/**
2738 @data: bit[0:3] DL position
2739*/
2740static void AM_DSP_PCM16K_RecordOn( uint32 data , uint32 extraInfo)
2741{
2742 (void)extraInfo;
2743 Sal_PCMEx_Config_t cfg_t;
2744 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2745
2746 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
2747 am.record_format = AM_RECORD_16K;
2748
2749
2750 cfg_t.idle = true;
2751 cfg_t.band = SAL_PCM_WIDEBAND;
2752 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2753 cfg_t.swi = SAL_PCMEX_SWITCH_ON;
2754 cfg_t.PCMRec_DL_Pos = (data&0xF);
2755 SAL_Get_Delay(SAL_DEALY_PCM16K, SAL_DELAY_NA, SAL_DELAY_NA, &cfg_t.delR, &cfg_t.delW, &cfg_t.delM);
2756
2757 //config related digital device(nb/wb),
2758 // am_SetDevice();
2759
2760 AFE_TurnOn8K();
2761
2762 SAL_PcmEx_Config(&cfg_t);
2763
2764 am.state |= AM_STATE_VOICE;
2765 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(10), L1AUDIO_Str_onoff(1) );
2766}
2767
2768void AM_PCM16K_RecordOn( uint8 dlPos )
2769{
2770
2771 if(!(am.state & AM_STATE_SPEECH))
2772 {
2773 AM_Enqueue( AM_DSP_PCM16K_RecordOn, dlPos, 0, false );
2774 AM_FlushQFunction();
2775
2776 // enable enhancement
2777 if(!AM_IsBTCordlessMode())
2778 {
2779 SetSpeechEnhancement(true);
2780 }
2781 } else {
2782 DEBUG_ASSERT(0);
2783 }
2784
2785}
2786
2787static void AM_DSP_PCM16K_RecordOff( uint32 data , uint32 extraInfo)
2788{
2789 (void)data;
2790 (void)extraInfo;
2791 Sal_PCMEx_Config_t cfg_t;
2792 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2793
2794 cfg_t.swi = SAL_PCMEX_SWITCH_OFF;
2795 am.state &= ~AM_STATE_VOICE;
2796 am.record_format = AM_RECORD_NONE;
2797 cfg_t.idle = false;
2798 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(10), L1AUDIO_Str_onoff(0) );
2799
2800 if( am.state == 0 ) {
2801 cfg_t.idle = true;
2802 }
2803 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2804
2805 SAL_PcmEx_Config(&cfg_t);
2806
2807 if( am.state == 0 ) {
2808 AFE_TurnOff8K();
2809 }
2810}
2811
2812void AM_PCM16K_RecordOff( bool wait )
2813{
2814 // turn off speech enhancment
2815 if(!(am.state & AM_STATE_SPEECH))
2816 {
2817 if(!AM_IsBTCordlessMode())
2818 {
2819 SetSpeechEnhancement(false);
2820 }
2821
2822 AM_Enqueue( AM_DSP_PCM16K_RecordOff, 0, 0, false );
2823 if( wait )
2824 AM_FlushQFunction();
2825 } else {
2826 DEBUG_ASSERT(0);
2827 }
2828}
2829
2830/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2831/**
2832 @extraInfo: bit[0:3] DL position when appType is AM_PCM8KREC_APP_TYPE_PCMREC
2833*/
2834static void AM_DSP_PCM8K_RecordOn( uint32 appType , uint32 extraInfo)
2835{
2836 (void)extraInfo;
2837
2838 Sal_PCMEx_Config_t cfg_t;
2839 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2840
2841 cfg_t.idle = false;
2842 cfg_t.swi = SAL_PCMEX_SWITCH_ON;
2843
2844 am.record_format = AM_RECORD_8K;
2845
2846 if( am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)) {
2847 // REMIND: Call record and VM EPL can work in the same time,
2848 // but they use same interrupt and setting.
2849
2850 if (AM_PCM8KREC_APP_TYPE_PCMREC == appType) { // Conversation Recording
2851 if (!(am.speech_state & SP_STATE_PCM8K_REC)) {
2852 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2853 cfg_t.PCMRec_DL_Pos = (extraInfo&0xF);
2854 am.speech_state |= SP_STATE_PCM8K_REC;
2855
2856 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(1) , L1AUDIO_Str_onoff(1) );
2857 } else {
2858 return;
2859 }
2860 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // VM EPL
2861 if (!(am.speech_state & SP_STATE_VMR_EPL)) {
2862 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2863 am.speech_state |= SP_STATE_VMR_EPL;
2864 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(4) , L1AUDIO_Str_onoff(1) );
2865 } else {
2866 return;
2867 }
2868 } else {
2869 DEBUG_ASSERT(0); // unknown application type
2870 return;
2871 }
2872
2873 }else{
2874 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // idle epl
2875 if((am.state & AM_STATE_VOICE)
2876 && (!(am.speech_state & SP_STATE_VMR_EPL))) {
2877
2878 am.speech_state |= SP_STATE_VMR_EPL;
2879 cfg_t.idle = false;
2880 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2881 } else {
2882 return;
2883 }
2884 } else { // idle record
2885 if( !(am.state & AM_CONFLICT_STATE) ){
2886 am.state |= AM_STATE_VOICE;
2887
2888 cfg_t.idle = true;
2889 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2890 cfg_t.band = SAL_PCM_NARROWBAND;
2891 cfg_t.PCMRec_DL_Pos = (extraInfo&0xF);
2892 SAL_Get_Delay(SAL_DEALY_NOTAMR, SAL_DELAY_NA, SAL_DELAY_NA, &cfg_t.delR, &cfg_t.delW, &cfg_t.delM);
2893 } else {
2894 return;
2895 }
2896 }
2897 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(4), L1AUDIO_Str_onoff(1) );
2898 }
2899
2900 if(cfg_t.idle)
2901 AFE_TurnOn8K();
2902
2903 SAL_PcmEx_Config(&cfg_t);
2904}
2905
2906void AM_PCM8K_RecordOn( AM_PCM8KREC_APP_TYPE appType, uint8 dlPos )
2907{
2908
2909 AM_Enqueue( AM_DSP_PCM8K_RecordOn, (uint32)appType, dlPos, false );
2910 AM_FlushQFunction();
2911
2912 if(!(am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)))
2913 {
2914 if(!AM_IsBTCordlessMode())
2915 {
2916 SetSpeechEnhancement(true);
2917 }
2918 }
2919}
2920
2921static void AM_DSP_PCM8K_RecordOff( uint32 appType , uint32 extraInfo)
2922{
2923 Sal_PCMEx_Config_t cfg_t;
2924 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2925
2926 am.record_format = AM_RECORD_NONE;
2927 cfg_t.swi = SAL_PCMEX_SWITCH_OFF;
2928 cfg_t.idle = false;
2929
2930 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType)
2931 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2932 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType)
2933 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2934
2935 if(am.speech_state & (SP_STATE_PCM8K_REC|SP_STATE_VMR_EPL) ) // under call
2936 {
2937 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType) {
2938 am.speech_state &= ~SP_STATE_PCM8K_REC;
2939 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType){
2940 am.speech_state &= ~SP_STATE_VMR_EPL;
2941 } else {
2942 DEBUG_ASSERT(0); // unknow application type
2943 return;
2944 }
2945
2946 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType) {
2947 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(1) , L1AUDIO_Str_onoff(0) );
2948 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType){
2949 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(4) , L1AUDIO_Str_onoff(0) );
2950 }
2951 }
2952 else
2953 {
2954 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // idle VM epl
2955 am.speech_state &= ~SP_STATE_VMR_EPL;
2956 } else { // idle record
2957 am.state &= ~AM_STATE_VOICE;
2958 }
2959 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(4), L1AUDIO_Str_onoff(0) );
2960 }
2961
2962 if( am.state == 0 ) {
2963 cfg_t.idle = true;
2964 }
2965
2966 SAL_PcmEx_Config(&cfg_t);
2967 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2968 AFE_TurnOff8K();
2969}
2970
2971void AM_PCM8K_RecordOff( bool wait , AM_PCM8KREC_APP_TYPE appType)
2972{
2973 if(!(am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)))
2974 {
2975 if(!AM_IsBTCordlessMode())
2976
2977 {
2978 SetSpeechEnhancement(false);
2979 }
2980 }
2981
2982 AM_Enqueue( AM_DSP_PCM8K_RecordOff, (uint32)appType, 0, false );
2983
2984 if( wait )
2985 AM_FlushQFunction();
2986}
2987
2988/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2989int16 AM_IsAudioPlaybackOn( void )
2990{
2991#if 0
2992/* under construction !*/
2993/* under construction !*/
2994/* under construction !*/
2995#endif
2996 return -1;
2997}
2998
2999int16 AM_IsIdleState( void )
3000{
3001 if( am.state == 0 )
3002 return true;
3003 return false;
3004}
3005
3006#if 0
3007/* under construction !*/
3008/* under construction !*/
3009/* under construction !*/
3010/* under construction !*/
3011/* under construction !*/
3012/* under construction !*/
3013/* under construction !*/
3014#endif
3015
3016bool AM_IsVoiceOn( void )
3017{
3018 if(am.state !=0 ) // ( am.state & ~AM_STATE_AUDIO) // no audio state exist
3019 return true;
3020 return false;
3021}
3022
3023/* ==========================================================================*/
3024static void RampPush( RampStatus status)
3025{
3026 if(RB_FULL(am.ramp_point_queue)) {
3027 MD_TRC_L1SP_MUTE_DSP_RAMP_QUEUE_FULL();
3028 } else {
3029 RB_PUT(am.ramp_point_queue, status);
3030 }
3031}
3032
3033static void RampPop( void )
3034{
3035 if(RB_EMPTY(am.ramp_point_queue)) {
3036 MD_TRC_L1SP_MUTE_DSP_RAMP_QUEUE_EMPTY();
3037 ASSERT(0);
3038 } else {
3039 RB_CONSUME(am.ramp_point_queue);
3040 }
3041}
3042
3043void AM_RAMP_INIT(bool mute, uint16 ramp_point)
3044{
3045 Sal_Ramp_State_t preState = SAL_Ramp_GetState(ramp_point);
3046 RampStatus rampStatus;
3047 rampStatus.RampPoint = ramp_point;
3048 rampStatus.MuteState = mute;
3049 MD_TRC_L1SP_MUTE_DSP_RAMP_CONTROL(0, ramp_point, preState, mute, am.state);
3050 if(AM_IsAmInSpeechState())
3051 {
3052 if(mute) {
3053 if( SAL_RAMP_DOWN_DONE == preState) {
3054#if defined(__SMART_PHONE_MODEM__)
3055 spc_sendRampDoneAck(rampStatus.RampPoint);
3056#endif
3057 } else { // if state in RAMP_DOWN_INIT or RAMP_DOWN_RUN, it won't take effect
3058 SAL_RampDown_SetInit(ramp_point);
3059 RampPush(rampStatus);
3060 }
3061 } else { // unmute
3062 if( SAL_RAMP_DOWN_DONE == preState) { // no sound, so ramp up
3063 SAL_RampUp_SetInit(ramp_point);
3064 RampPush(rampStatus);
3065 } else { // if state in RAMP_UP_INIT or RAMP_UP_RUN, it won't take effect
3066#if defined(__SMART_PHONE_MODEM__)
3067 spc_sendRampDoneAck(rampStatus.RampPoint);
3068#endif
3069 }
3070 }
3071 } else {
3072 if( mute) {
3073 SAL_Ramp_SetMute(rampStatus.RampPoint);
3074 } else {
3075 SAL_Ramp_SetUnMute(rampStatus.RampPoint);
3076 }
3077 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] No in speech state!");
3078#if defined(__SMART_PHONE_MODEM__)
3079 spc_sendRampDoneAck(rampStatus.RampPoint);
3080#endif
3081 }
3082 MD_TRC_L1SP_MUTE_DSP_RAMP_CONTROL(1, ramp_point, SAL_Ramp_GetState(ramp_point),mute,am.state);
3083}
3084void AM_RAMP_DONE(void)
3085{
3086 RampStatus rampStatus;
3087 while (!RB_EMPTY(am.ramp_point_queue)) {
3088 RB_PEEK(am.ramp_point_queue, rampStatus);
3089 MD_TRC_L1SP_MUTE_DSP_RAMP_DONE_STATE(rampStatus.MuteState, rampStatus.RampPoint, am.state);
3090 if(AM_IsAmInSpeechState()) {
3091 if(rampStatus.MuteState) {
3092 if(SAL_RampDown_IsDone(rampStatus.RampPoint)) {
3093 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] ramp down pass!");
3094 } else {
3095 MD_TRC_L1SP_MUTE_DSP_RAMP_DELAY_MUTE();
3096 break;
3097 }
3098 } else {
3099 if(SAL_RampUp_IsDone(rampStatus.RampPoint)) {
3100 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] ramp up pass!");
3101 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3102 } else {
3103 MD_TRC_L1SP_MUTE_DSP_RAMP_DELAY_UNMUTE();
3104 break;
3105 }
3106 }
3107 } else { // force mute/unmute when call end
3108 if(rampStatus.MuteState) {
3109 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3110 SAL_Ramp_SetMute(rampStatus.RampPoint);
3111 MD_TRC_L1SP_MUTE_DSP_RAMP_FORCE_MUTE();
3112 } else {
3113 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3114 MD_TRC_L1SP_MUTE_DSP_RAMP_FORCE_UNMUTE();
3115 }
3116 }
3117 RampPop();
3118#if defined(__SMART_PHONE_MODEM__)
3119 spc_sendRampDoneAck(rampStatus.RampPoint);
3120#endif
3121 }
3122}
3123void AM_Mute_UL_EnhResult_Speech(bool mute)
3124{
3125 MD_TRC_L1SP_MUTE_DSP_UL_ENH_RESULT_CONTROL(mute);
3126 SAL_Mute_Ctrl(SAL_MUTE_UL_IN_EN, mute); // in the enhancement end point, which is set -60db to the result.
3127}
3128
3129void AM_Mute_UL_Source_Speech(bool mute)
3130{
3131 AM_RAMP_INIT(mute, SAL_RAMP_UL_PRE_EN);
3132}
3133
3134void AM_Mute_UL_Codec_Speech( bool mute )
3135{
3136 MD_TRC_L1SP_MUTE_DSP_UL_CODEC_CONTROL(mute);
3137 SAL_Mute_Ctrl(SAL_MUTE_UL_PRE_EXTCOD, mute); // need to under this position, or background sound won't be mute.
3138}
3139
3140void AM_Mute_UL_POS_EN_Speech( bool mute )
3141{
3142 AM_RAMP_INIT(mute, SAL_RAMP_UL_POS_EN);
3143
3144}
3145
3146void AM_Mute_DL_8K_Speech( bool mute )
3147{
3148 AM_RAMP_INIT(mute, SAL_RAMP_DL_PRE_DACA);
3149}
3150
3151void AM_Mute_DL_Speech_Traffic( bool mute )
3152{
3153 MD_TRC_L1SP_MUTE_DSP_DL_TRAFFIC_CONTROL(mute);
3154 SAL_Mute_Ctrl(SAL_MUTE_DL_POS_EXTCOD, mute); //considering the VT case using P2W, so mute data at this point , not at SAL_MUTE_DL_PRE_SD
3155}
3156
3157void AM_Mute_DL_PRE_PcmMixer(bool mute)
3158{
3159 AM_RAMP_INIT(mute, SAL_RAMP_DL_PRE_MIXER2);
3160}
3161
3162
3163
3164void AM_Init( void )
3165{
3166 am.dsp_2g_reset = false;
3167
3168 am.record_format = AM_RECORD_NONE;
3169 RB_INIT( am.qfunc );
3170 am.state = 0;
3171 am.speech_mode = 0;
3172 am.pre_speech_mode = 0;
3173 am.sub_channel = 0;
3174 am.is_reset_enh = 0;
3175 // am.speech_off_delay = 0;
3176 // am.pre_isWBLink = KAL_FALSE;
3177#if defined(_SPE_ENH_MD_PARSE_)
3178 am.isFirCoeffSet = false;
3179#endif
3180
3181 SAL_Dsp_Sph_Init();
3182
3183 // AM_WriteSidetoneFIR(); // 93 not dsp sidetone, so remove
3184
3185#if defined(_SPE_ENH_MD_PARSE_)
3186
3187 if( am.isFirCoeffSet == KAL_FALSE ) {
3188 AM_WriteWbFirCoeffs( WB_Speech_Input_FIR_Coeff[0], WB_Speech_Output_FIR_Coeff[0] );
3189 AM_WriteFirCoeffs( WB_Speech_Input_FIR_Coeff[0], WB_Speech_Output_FIR_Coeff[0] );
3190 }
3191 #endif
3192 // AM_WriteAntiAliasFilter();
3193
3194 am.io_type = NORMAL_MODE;
3195 am.speech_state = 0;
3196 // am.voip_state = 0;
3197 // am.fLoopBack = false;
3198 am.sp3g_flag = false;
3199#if defined(__C2K_SPEECH_SUPPORT__)
3200 am.spc2k_flag = false;
3201 am.c2k_flag = false;
3202#endif
3203#if defined(__VOLTE_SUPPORT__)
3204 am.sp4g_flag = false;
3205 am.codec_4g = -1;
3206#endif
3207
3208 // AM_DSP_SetSpeechDigitalGain(DG_DL_Speech); // replace by spGain_Init()
3209 // AM_DSP_SetSpeechEnhRefDigitalGain(DG_DL_Speech); //am.speechDlEnhRefDigtalGain init // replace by spGain_Init
3210}
3211
3212/* ========================================================================= */
3213/* Bluetooth control Functions */
3214/* ========================================================================= */
3215
3216
3217static void AM_DSP_BluetoothOn( uint32 data , uint32 extraInfo)
3218{
3219 Sal_BT_Config cfg_t;
3220 memset(&cfg_t, 0, sizeof(Sal_BT_Config));
3221 cfg_t.feed_cfg = true;
3222
3223
3224 // leave the gain control to AP. do not do any backup now
3225 // am.bt_digital_gain = AM_DSP_GetSpeechDigitalGain(); //*DP_VOL_OUT_PCM;
3226 // am.bt_dlEnhRef_digital_gain = AM_GetSpeechEnhRefDigitalGain(); // use am.speechDlEnhRefDigtalGain
3227
3228 // Zero-pending
3229 cfg_t.linear_ctrl = SAL_BT_LINEAR_GAIN_CONFIG_ZPAD;
3230 cfg_t.mode = SAL_BT_MODE_LINEAR;
3231 // MSB first
3232 cfg_t.linear_reverse = false;
3233
3234 //set mode and uplink gain
3235 cfg_t.linear_ul_gain = 1;
3236
3237 // leave the gain control to AP. do not do any backup now
3238 // AM_DSP_SetSpeechDigitalGain(default_bt_pcm_out_vol); // *DP_VOL_OUT_PCM = 0x1000;
3239 // AM_DSP_SetSpeechUplinkSwAgcGain(0); // AGC set to 0 db
3240 // AM_DSP_SetSpeechEnhRefDigitalGain(default_bt_pcm_out_enh_ref_vol); // 0db
3241
3242
3243 SAL_BT_Config(&cfg_t);
3244
3245 am.io_type = BT_EARPHONE_MODE;
3246 MD_TRC_L1Audio_Msg_AM_IO_Switch( AM_IO_Name(am.io_type) );
3247}
3248
3249static void AM_DSP_BluetoothOff( uint32 data , uint32 extraInfo)
3250{
3251 Sal_BT_Config cfg_t;
3252 memset(&cfg_t, 0, sizeof(Sal_BT_Config));
3253
3254 cfg_t.feed_cfg = false;
3255
3256 // AFE_SetBtFlag(KAL_FALSE);
3257
3258 // leave the gain control to AP. do not do restore the value to default now
3259 // AM_DSP_SetSpeechDigitalGain(am.bt_digital_gain);
3260 // AM_DSP_SetSpeechUplinkSwAgcGain(am.speechUplinkSwAgcGain);
3261 // AM_DSP_SetSpeechEnhRefDigitalGain(am.speechDlEnhRefDigtalGain);
3262
3263 SAL_BT_Config(&cfg_t);
3264
3265 am.io_type = NORMAL_MODE;
3266 MD_TRC_L1Audio_Msg_AM_IO_Switch( AM_IO_Name(am.io_type) );
3267}
3268
3269//*******************************************************************//
3270//* bt_mode: 1 for cordless mode, 2 for earphone mode *//
3271//* bt_sync_type: 0 for short sync, 1 for long sync *//
3272//* bt_sync_length: range from 1 to 8 *//
3273//*******************************************************************//
3274#if 0 // [FIXME] useless??
3275/* under construction !*/
3276/* under construction !*/
3277#endif
3278
3279void AM_BluetoothOn( uint8 bt_mode )
3280{
3281 ASSERT(bt_mode == 2); // expected earphone mode only
3282
3283 AM_Enqueue( AM_DSP_BluetoothOn, 0, 0, false );
3284
3285 AM_FlushQFunction();
3286}
3287
3288void AM_BluetoothOff( void )
3289{
3290 SP_DSPTone_ForceEnd();
3291
3292 AM_Enqueue( AM_DSP_BluetoothOff, 0, 0, false );
3293 AM_FlushQFunction();
3294}
3295
3296bool AM_IsBluetoothOn( void )
3297{
3298 return SAL_BT_IsEnable();
3299}
3300
3301bool AM_IsBTCordlessMode( void )
3302{
3303 return false;//( (*DP_AUDIO_PAR&0x1000)!=0 );
3304}
3305
3306
3307/* ========================================================================= */
3308
3309
3310void AM_SND_PlaybackOn( void )
3311{
3312 AM_Enqueue( AM_DSP_PCM8K_PlaybackOn, 1, 0, false );
3313
3314 AM_FlushQFunction();
3315}
3316
3317void AM_SND_PlaybackOff( bool wait )
3318{
3319
3320 AM_Enqueue( AM_DSP_PCM8K_PlaybackOff, 1, 0, false );
3321
3322 if( wait )
3323 AM_FlushQFunction();
3324}
3325// #endif // defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
3326
3327/* ========================================================================= */
3328/* PCM_EX control Functions */
3329/* ========================================================================= */
3330
3331void AM_DSP_PCM_EX_On(uint32 type, uint32 data)
3332{
3333 kal_bool flag;
3334 // uint8 voip_state = 0;
3335
3336 Sal_PCMEx_Config_t cfg;
3337 memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
3338
3339
3340 flag = true; //this flag is used to choose one among multiple options
3341 switch(type)
3342 {
3343 case AM_PCMEX_TYPE_DACA_DEDICATION: // 100: //DACA ACTIVE
3344 if(flag){
3345 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(3) , L1AUDIO_Str_onoff(1) );
3346 ASSERT(!(am.speech_state & SP_STATE_DACA));
3347 am.speech_state |= SP_STATE_DACA;
3348
3349 cfg.idle = false;
3350
3351 flag=false;
3352 }
3353 case AM_PCMEX_TYPE_DACA_IDLE_WO_ENH: //101: //DACA IDLE
3354 if(flag){
3355 ASSERT_REBOOT( !(am.state & AM_STATE_DACA) );
3356 ASSERT(am.state == 0);
3357 am.state |= AM_STATE_DACA;
3358
3359 cfg.idle = true;
3360
3361 flag=false;
3362 }
3363 cfg.swi = SAL_PCMEX_SWITCH_ON;
3364 cfg.type = SAL_PCMEX_TYPE_DACA;
3365 {
3366 _DACA_EX_T *dacaExData = (_DACA_EX_T *)data;
3367 kal_uint32 app_type = dacaExData->app_type;
3368 //cfg.band = (dacaExData->app_type & DACA_USE_NB) ? SAL_PCM_NARROWBAND : SAL_PCM_WIDEBAND;
3369 if(app_type & DACA_USE_NB){
3370 cfg.band = SAL_PCM_NARROWBAND;
3371 }else if(app_type & DACA_USE_WB){
3372 cfg.band = SAL_PCM_WIDEBAND;
3373 }else if(app_type & DACA_USE_SWB){
3374 cfg.band = SAL_PCM_SUPERWIDEBAND;
3375 }else if(app_type & DACA_USE_FB){
3376 cfg.band = SAL_PCM_FULLBAND;
3377 }else{
3378 ASSERT(0);
3379 }
3380 }
3381
3382 break;
3383 // ======================================================================
3384 case AM_PCMEX_TYPE_DEDICATION: // 0: //PCM4WAY CTM
3385 if(flag){
3386 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(2) , L1AUDIO_Str_onoff(1) );
3387 ASSERT(!(am.speech_state & SP_STATE_PCMNWAY));
3388
3389 am.speech_state |= SP_STATE_PCMNWAY;
3390
3391 cfg.idle = false;
3392
3393 flag=false;
3394 }
3395 /*
3396 case AM_PCMEX_TYPE_IDLE_WO_ENH: // 1: //PCM2WAY Voice
3397 if(flag){
3398 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3399 ASSERT(am.state == 0);
3400 am.state |= AM_STATE_VOICE;
3401
3402 cfg.idle = true;
3403
3404 flag = false;
3405 }
3406 */
3407 case AM_PCMEX_TYPE_IDLE: //2: PCM2WAY VoIP
3408 if(flag){
3409 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3410 ASSERT(am.state == 0);
3411 am.state |= AM_STATE_VOIP;
3412
3413 cfg.idle = true;
3414 flag = false;
3415 }
3416
3417 cfg.swi = SAL_PCMEX_SWITCH_ON;
3418 cfg.type = SAL_PCMEX_TYPE_PNW;
3419
3420 {
3421
3422 _PCMEX_T *pcmExData = (_PCMEX_T *)data;
3423
3424 cfg.D2M_ul1 = (0!=(pcmExData->cfgUL1 & USE_D2M_PATH));
3425 cfg.M2D_ul1 = (0!=(pcmExData->cfgUL1 & USE_M2D_PATH));
3426 cfg.afterEnh_ul1 = (0!=(pcmExData->cfgUL1 & DATA_SELECT_AFTER_ENH));
3427
3428 cfg.D2M_ul2 = (0!=(pcmExData->cfgUL2 & USE_D2M_PATH));
3429 cfg.M2D_ul2 = (0!=(pcmExData->cfgUL2 & USE_M2D_PATH));
3430 cfg.afterEnh_ul2 = (0!=(pcmExData->cfgUL2 & DATA_SELECT_AFTER_ENH));
3431
3432 cfg.D2M_ul3 = (0!=(pcmExData->cfgUL3 & USE_D2M_PATH));
3433 cfg.M2D_ul3 = (0!=(pcmExData->cfgUL3 & USE_M2D_PATH));
3434 cfg.afterEnh_ul3 = (0!=(pcmExData->cfgUL3 & DATA_SELECT_AFTER_ENH));
3435
3436 cfg.D2M_ul4 = (0!=(pcmExData->cfgUL4 & USE_D2M_PATH));
3437 cfg.M2D_ul4 = (0!=(pcmExData->cfgUL4 & USE_M2D_PATH));
3438 cfg.afterEnh_ul4 = (0!=(pcmExData->cfgUL4 & DATA_SELECT_AFTER_ENH));
3439
3440 cfg.D2M_dl = (0!=(pcmExData->cfgDL & USE_D2M_PATH));
3441 cfg.M2D_dl = (0!=(pcmExData->cfgDL & USE_M2D_PATH));
3442 cfg.afterEnh_dl = (0!=(pcmExData->cfgDL & DATA_SELECT_AFTER_ENH));
3443
3444
3445 if(cfg.idle){
3446 if(pcmExData->bandInfo == PCMEX_BAND_WB){
3447 cfg.band = SAL_PCM_WIDEBAND;
3448 }else if (pcmExData->bandInfo == PCMEX_BAND_NB){
3449 cfg.band = SAL_PCM_NARROWBAND;
3450 }else if (pcmExData->bandInfo == PCMEX_BAND_SWB){
3451 cfg.band = SAL_PCM_SUPERWIDEBAND;
3452 }else if (pcmExData->bandInfo == PCMEX_BAND_FB){
3453 cfg.band = SAL_PCM_FULLBAND;
3454 }else{ // should never been here
3455 ASSERT(0);
3456 }
3457 } else {
3458 cfg.band = SAL_PCM_DYNAMIC;
3459 }
3460
3461 }
3462
3463 break;
3464 default:
3465 ASSERT(0); break;
3466 }
3467
3468 if(cfg.idle == true){
3469 SAL_Get_Delay(SAL_DEALY_PCM8K_PB_VOIP, SAL_DELAY_NA, SAL_DELAY_NA, &cfg.delR, &cfg.delW, &cfg.delM);
3470 AFE_TurnOn8K();
3471 }
3472
3473 SAL_PcmEx_Config(&cfg);
3474}
3475
3476
3477void AM_DSP_PCM_EX_Off(uint32 type, uint32 data)
3478{
3479 kal_bool flag;
3480 // uint8 voip_state = 0;
3481
3482 Sal_PCMEx_Config_t cfg;
3483 memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
3484
3485 flag = true; //this flag is used to choose one among multiple options
3486 switch(type)
3487 {
3488 case AM_PCMEX_TYPE_DACA_DEDICATION: //100: DACA ACTIVE
3489 if(flag ){
3490 am.speech_state &= ~SP_STATE_DACA;
3491 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(3) , L1AUDIO_Str_onoff(0) );
3492
3493 cfg.idle = false;
3494
3495 flag = false;
3496 }
3497 case AM_PCMEX_TYPE_DACA_IDLE_WO_ENH: //101: DACA IDLE
3498 if(flag ){
3499 am.state &= ~AM_STATE_DACA;
3500 ASSERT(am.state == 0);
3501
3502 cfg.idle = true;
3503
3504 flag =false;
3505 }
3506
3507 cfg.swi = SAL_PCMEX_SWITCH_OFF;
3508 cfg.type = SAL_PCMEX_TYPE_DACA;
3509
3510 break;
3511 // ======================================================================
3512 case AM_PCMEX_TYPE_DEDICATION: //PCM4WAY CTM
3513 if(flag ){
3514 am.speech_state &= ~SP_STATE_PCMNWAY;
3515 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(2) , L1AUDIO_Str_onoff(0) );
3516
3517 cfg.idle = false;
3518
3519 flag = false;
3520 }
3521 /*
3522 case AM_PCMEX_TYPE_IDLE_WO_ENH: //PCM2WAY Voice
3523 if(flag ){
3524 am.state &= ~AM_STATE_VOICE;
3525 ASSERT(am.state == 0);
3526
3527 cfg.idle = true;
3528
3529 flag = false;
3530 }
3531 */
3532 case AM_PCMEX_TYPE_IDLE: //PCM2WAY VoIP
3533 if(flag ){
3534 am.state &= ~AM_STATE_VOIP;
3535 ASSERT(am.state == 0);
3536
3537 cfg.idle = true;
3538
3539 flag = false;
3540 }
3541
3542 cfg.swi = SAL_PCMEX_SWITCH_OFF;
3543 cfg.type = SAL_PCMEX_TYPE_PNW;
3544
3545 break;
3546 default:
3547 ASSERT(0);
3548 break;
3549 }
3550
3551 if(cfg.idle == true){
3552 cc_set_VBI_for_FSM(1);
3553 SAL_PcmEx_Config(&cfg);
3554 cc_set_VBI_for_FSM(2);
3555 AFE_TurnOff8K();
3556 } else {
3557 SAL_PcmEx_Config(&cfg);
3558 }
3559}
3560
3561/**
3562 @type: AM_PCMEX_TYPE, indicate the PCM EX type
3563 @p2exData: Addess of "glable variable" like pcmEx, dacaEx
3564*/
3565void AM_PCM_EX_On( AM_PCMEX_TYPE type, uint32 p2exData)
3566{
3567 // kal_uint8 aud_func;
3568 if(type == AM_PCMEX_TYPE_IDLE
3569#if 0
3570/* under construction !*/
3571/* under construction !*/
3572#endif
3573 || type == AM_PCMEX_TYPE_DACA_IDLE )
3574 {
3575
3576
3577 // aud_func = L1SP_SPEECH;
3578 }
3579/*
3580 else
3581 {
3582 // aud_func = L1SP_VOICE;
3583 }
3584*/
3585
3586
3587 AM_Enqueue( AM_DSP_PCM_EX_On, type, p2exData, false );
3588
3589 AM_FlushQFunction();
3590}
3591
3592
3593void AM_PCM_EX_Off( AM_PCMEX_TYPE type, uint32 p2exData)
3594{
3595/*
3596 // find out the aud_func
3597 kal_uint8 aud_func = L1SP_MAX_AUDIO;
3598
3599 if( type == AM_PCMEX_TYPE_IDLE
3600#if 0
3601 || type == AM_PCMEX_TYPE_REC_ONLY_CAL
3602 || type == AM_PCMEX_TYPE_REC_PLAY_CAL
3603#endif
3604 || type == AM_PCMEX_TYPE_DACA_IDLE ) {
3605 aud_func = L1SP_SPEECH;
3606 } else {
3607 aud_func = L1SP_VOICE;
3608 }
3609*/
3610
3611 AM_Enqueue(AM_DSP_PCM_EX_Off, type, p2exData, false );
3612 AM_FlushQFunction();
3613}
3614
3615bool AM_IsVoIPOn( void )
3616{
3617 return( (bool)((am.state & AM_STATE_VOIP) != 0) );
3618}
3619
3620/* ========================================================================= */
3621
3622uint16 AM_Status( void )
3623{
3624 return am.state;
3625}
3626
3627/* phase out. lagency
3628void AM_EnableToneLoopBackFlag( kal_bool param )
3629{
3630 if(param)
3631 am.toneLoopbackRec = KAL_TRUE;
3632 else
3633 am.toneLoopbackRec = KAL_FALSE;
3634}
3635*/
3636/* ========================================================================= */
3637/* Functions for DSP PCM Router */
3638/* ========================================================================= */
3639#define PCM_ROUTER_DELAY_READ 0
3640#define PCM_ROUTER_DELAY_WRITE 0xF0
3641#define PCM_ROUTER_DELAY_DL 0x38
3642#define PCM_ROUTER_DELAY_UL 0x118
3643
3644void AM_DSP_PcmRouter_On( uint32 voiceMode, uint32 extraInfo )
3645{
3646
3647 Sal_PCM_Router_t pcmrt;
3648
3649 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3650 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(11), L1AUDIO_Str_onoff(1) );
3651
3652 // setting
3653 memset(&pcmrt, 0 , sizeof(Sal_PCM_Router_t));
3654
3655 pcmrt.cod_band = 0; //voiceMode;
3656 pcmrt.dev_band = voiceMode;
3657 pcmrt.delR = PCM_ROUTER_DELAY_READ;
3658 pcmrt.delW = PCM_ROUTER_DELAY_WRITE;
3659 pcmrt.delM_DL = PCM_ROUTER_DELAY_DL;
3660 pcmrt.delM_UL = PCM_ROUTER_DELAY_UL;
3661
3662 // turn on 8k
3663 AFE_TurnOn8K();
3664
3665 SAL_PCM_Router_Open(&pcmrt, ((extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON));
3666
3667 am.state |= AM_STATE_VOIP;
3668}
3669
3670
3671/**
3672 @extraInfo: bit[0]: 1 for device change to resync
3673*/
3674void AM_PcmRouter_On(uint32 extraInfo)
3675{
3676 kal_uint8 voiceMode;
3677
3678 // the following chips did not provide the function
3679
3680 voiceMode = AFE_GetVoice8KMode();
3681
3682 AM_Enqueue( AM_DSP_PcmRouter_On, voiceMode, extraInfo, false );
3683
3684 AM_FlushQFunction();
3685
3686}
3687
3688void AM_DSP_PcmRouter_Off( uint32 info, uint32 extraInfo )
3689{
3690 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(11), L1AUDIO_Str_onoff(0) );
3691
3692 SAL_PCM_Router_Close(true);
3693
3694 AFE_TurnOff8K();
3695
3696 am.state &= (~AM_STATE_VOIP);
3697}
3698
3699
3700void AM_PcmRouter_Off(void)
3701{
3702
3703 AM_Enqueue( AM_DSP_PcmRouter_Off, 0, 0, false );
3704
3705 AM_FlushQFunction();
3706}
3707
3708#if 0
3709/* under construction !*/
3710/* under construction !*/
3711/* under construction !*/
3712/* under construction !*/
3713/* under construction !*/
3714/* under construction !*/
3715/* under construction !*/
3716/* under construction !*/
3717/* under construction !*/
3718/* under construction !*/
3719/* under construction !*/
3720/* under construction !*/
3721/* under construction !*/
3722/* under construction !*/
3723/* under construction !*/
3724/* under construction !*/
3725/* under construction !*/
3726/* under construction !*/
3727/* under construction !*/
3728/* under construction !*/
3729/* under construction !*/
3730#endif
3731
3732#if 0
3733/* under construction !*/
3734/* under construction !*/
3735/* under construction !*/
3736/* under construction !*/
3737/* under construction !*/
3738/* under construction !*/
3739/* under construction !*/
3740/* under construction !*/
3741/* under construction !*/
3742/* under construction !*/
3743/* under construction !*/
3744/* under construction !*/
3745/* under construction !*/
3746/* under construction !*/
3747/* under construction !*/
3748/* under construction !*/
3749/* under construction !*/
3750/* under construction !*/
3751/* under construction !*/
3752/* under construction !*/
3753/* under construction !*/
3754/* under construction !*/
3755/* under construction !*/
3756/* under construction !*/
3757/* under construction !*/
3758/* under construction !*/
3759/* under construction !*/
3760/* under construction !*/
3761/* under construction !*/
3762/* under construction !*/
3763/* under construction !*/
3764/* under construction !*/
3765/* under construction !*/
3766/* under construction !*/
3767/* under construction !*/
3768/* under construction !*/
3769/* under construction !*/
3770/* under construction !*/
3771/* under construction !*/
3772/* under construction !*/
3773#endif
3774
3775bool AM_IsConflictState( void )
3776{
3777 if( am.state & AM_CONFLICT_STATE )
3778 return true;
3779 else
3780 return false;
3781}
3782
3783
3784kal_uint32 AM_Get2GResyncThreshold(void)
3785{
3786 return AM_2G_RESYNC_THRESHOLD;
3787}
3788
3789//=============================================================================
3790// sw digital gain related
3791//=============================================================================
3792
3793void AM_DSP_SetSpeechDigitalGain(kal_uint16 digitalVol)
3794{
3795 am.speechDigitalGain = digitalVol;
3796 SAL_DGain_Set_DL(digitalVol);
3797
3798 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(1), digitalVol);
3799}
3800
3801kal_uint16 AM_DSP_GetSpeechDigitalGain(void)
3802{
3803 return SAL_DGain_Get_DL();
3804}
3805
3806
3807void AM_DSP_SetSpeechUplinkSwAgcGain(kal_uint16 digitalVol)
3808{
3809 am.speechUplinkSwAgcGain = digitalVol;
3810 SAL_AGC_SetGain(digitalVol);
3811
3812 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(3), digitalVol);
3813}
3814
3815kal_uint16 AM_GetSpeechEnhRefDigitalGain(void)
3816{
3817 return am.speechDlEnhRefDigtalGain;
3818}
3819
3820void AM_DSP_SetSpeechEnhRefDigitalGain(kal_uint16 digitalVol)
3821{
3822 am.speechDlEnhRefDigtalGain = digitalVol;
3823 SAL_ENH_Gain_Set_DL(digitalVol);
3824
3825 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(4), digitalVol);
3826}
3827