blob: 54c096ae6ad47ea78453bf8d769de96716bd6fa6 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
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{
1561 SP_DSPTone_ForceEnd();
1562
1563 // if((info == 0)|| ((info&1)!=0))
1564 cc_set_VBI_for_FSM(1);
1565
1566 MD_TRC_L1Audio_Msg_AM_Speech(0);
1567 AM_Enqueue( AM_DSP_SpeechOff, info, 0, false );
1568
1569 AM_FlushQFunction();
1570
1571 // if((info == 0)|| ((info&1)!=0))
1572 cc_set_VBI_for_FSM(2);
1573
1574 if( (am.state == 0) || ((info&1)!=0))
1575 AFE_TurnOff8K();
1576}
1577
1578bool AM_IsSpeechOn( void )
1579{
1580 return( (bool)((am.state & AM_STATE_SPEECH) != 0) );
1581}
1582
1583bool AM_IsDataCardOn( void )
1584{
1585 return( (bool)((am.speech_state &= SP_STATE_DACA) != 0) );
1586}
1587
1588bool AM_IsAmInSpeechState( void )
1589{
1590 if ((am.state & (AM_STATE_SPEECH | AM_STATE_VOICE | AM_STATE_VOIP )) != 0)
1591 return true;
1592 else
1593 return false;
1594}
1595
1596void AM_SetSpeechMode( uint16 speech_mode, int8 sub_channel )
1597{
1598 am.speech_mode = speech_mode;
1599 am.sub_channel = sub_channel;
1600}
1601
1602uint16 AM_GetSpeechMode(void)
1603{
1604 return am.speech_mode;
1605}
1606
1607kal_bool AM_IsSpeechWB( void )
1608{
1609 return IsWBLink(am.speech_mode);
1610}
1611
1612#if defined( __UMTS_RAT__ )
1613/**
1614 extraInfo: come from rate
1615*/
1616void AM_DSP_RAT_sub_2G( uint32 data , uint32 extraInfo)
1617{
1618 (void)data;
1619 if(L1SP_TCH_State()){
1620 AM_Get2GCodecInfo(&am.speech_mode, &am.sub_channel);
1621 }else{
1622 am.speech_mode = 0;
1623 am.sub_channel = 0;
1624 }
1625 if( !(am.state & AM_STATE_SPEECH) )
1626 return;
1627 //VBI_End(); //When DSP in NB-AMR, driver set SC,SD mode as WB-AMR, and DSP will assert, and vice versa
1628 if(extraInfo == SAL_APP_TYPE_2GCall){
1629 cc_2G_Call_Close(true);
1630 }
1631 else if(extraInfo == SAL_APP_TYPE_3GCall){
1632 cc_3G_Call_Close(true);
1633 am.sp3g_flag = false;
1634 }
1635#if defined(__C2K_SPEECH_SUPPORT__)
1636 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1637 AM_DSP_TurnOffC2KSDSP(0, 0);
1638 }
1639#endif
1640#if defined(__VOLTE_SUPPORT__)
1641 else if(extraInfo == SAL_APP_TYPE_4GCall){
1642 SP4G_Call_Close();
1643 am.sp4g_flag = false;
1644 }
1645#endif
1646 cc_2G_Call_Open(am.speech_mode, am.speech_mode, am.sub_channel, SAL_SRST_TYPE_HO);
1647 AM_Reset_Enh(am.speech_mode);
1648 l1sp_NetworkStatusNotification();
1649 // l1sp_CodecStatusNotification(am.speech_mode);
1650}
1651
1652void AM_DSP_InterRAT_3G_to_2G( uint32 codec , uint32 extraInfo)
1653{
1654 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_3GCall);
1655 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_2G(am.speech_mode);
1656}
1657#if defined(__C2K_SPEECH_SUPPORT__)
1658void AM_DSP_InterRAT_C2K_to_2G( uint32 codec , uint32 extraInfo)
1659{
1660 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_C2KCall);
1661 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_2G(am.speech_mode);
1662}
1663#endif
1664#if defined(__VOLTE_SUPPORT__)
1665void AM_DSP_InterRAT_4G_to_2G( uint32 codec , uint32 extraInfo)
1666{
1667 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_4GCall);
1668 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_2G(am.speech_mode);
1669}
1670#endif
1671void AM_DSP_InterRAT_Standby_to_2G( uint32 codec , uint32 extraInfo)
1672{
1673 AM_DSP_RAT_sub_2G(0, SAL_APP_TYPE_2GCall);
1674 MD_TRC_L1Audio_Msg_INTERRAT_STANDBY_TO_2G(am.speech_mode);
1675}
1676
1677void AM_InterRAT_3G_to_2G()
1678{
1679 AM_Enqueue( AM_DSP_InterRAT_3G_to_2G, 0, 0, false );
1680 AM_FlushQFunction();
1681}
1682#if defined(__C2K_SPEECH_SUPPORT__)
1683void AM_InterRAT_C2K_to_2G()
1684{
1685 AM_Enqueue( AM_DSP_InterRAT_C2K_to_2G, 0, 0, false );
1686 AM_FlushQFunction();
1687}
1688#endif
1689#if defined(__VOLTE_SUPPORT__)
1690void AM_InterRAT_4G_to_2G()
1691{
1692 AM_Enqueue( AM_DSP_InterRAT_4G_to_2G, 0, 0, false );
1693 AM_FlushQFunction();
1694}
1695#endif
1696void AM_InterRAT_Standby_to_2G()
1697{
1698 AM_Enqueue( AM_DSP_InterRAT_Standby_to_2G, 0, 0, false );
1699 AM_FlushQFunction();
1700}
1701
1702void AM_DSP_RAT_sub_3G(uint32 codec , uint32 extraInfo)
1703{
1704 kal_uint16 u16DelayR, u16DelayW, u16DelayM;
1705 kal_uint32 u32CurTime64us;
1706 am.speech_mode = codec;
1707 if( !(am.state & AM_STATE_SPEECH) )
1708 return;
1709 if(extraInfo == SAL_APP_TYPE_2GCall){
1710 cc_2G_Call_Close(true);
1711 }else if(extraInfo == SAL_APP_TYPE_3GCall){
1712 cc_3G_Call_Close(true);
1713 }
1714#if defined(__C2K_SPEECH_SUPPORT__)
1715 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1716 AM_DSP_TurnOffC2KSDSP(0, 0);
1717 }
1718#endif
1719#if defined(__VOLTE_SUPPORT__)
1720 else if(extraInfo == SAL_APP_TYPE_4GCall){
1721 SP4G_Call_Close();
1722 am.sp4g_flag = false;
1723 }
1724#endif
1725
1726 SP3G_GetSyncDelayRW( &u16DelayR, &u16DelayW, &u16DelayM, &u32CurTime64us);
1727 SAL_3G_Upd_Enc_Cod(codec);//for 3g codec internal, MT6280
1728 SAL_3G_Upd_Dec_Cod(codec);//for 3g codec internal, MT6280
1729#if defined(_MODEM_RESYNC_3G_)
1730 MD_TRC_L1Audio_Msg_AM_3G_Reset_Time_Drift();
1731#if defined( __UMTS_RAT__ )
1732 switch(L1SP_GetSIMStatus()){
1733 case SP_3G_SIM_FDD_ACTIVE:
1734 UL1D_Speech_Resync_Reset_Time_Offset();
1735 break;
1736#if defined(__UMTS_TDD128_MODE__)
1737 case SP_3G_SIM_TDD_ACTIVE:
1738 TL1C_Reset_Time_Drift();
1739 break;
1740#endif
1741 default:
1742 ASSERT(0);
1743 }
1744#endif
1745#endif
1746
1747#if defined( __UMTS_RAT__ ) && !defined(__L1_STANDALONE__)
1748 switch(L1SP_GetSIMStatus()){
1749 case SP_3G_SIM_FDD_ACTIVE:
1750 if(query_ps_conf_test_mode()==PS_CONF_TEST_FTA)
1751 SP3G_SetDTX(false);
1752 else
1753 SP3G_SetDTX(true);
1754 break;
1755 case SP_3G_SIM_TDD_ACTIVE:
1756 break;
1757 default:
1758 ASSERT(0);
1759 }
1760#endif
1761 cc_3G_Call_Open(codec, codec, SP3G_IsDTXOn(), u16DelayR, u16DelayW, u16DelayM, u32CurTime64us, SAL_SRST_TYPE_HO);
1762 MD_TRC_L1Audio_Msg_SP3G_FORCE_RESYNC( codec, codec, u16DelayR, u16DelayW);
1763 am.sp3g_flag = true;
1764 AM_Reset_Enh(codec);
1765 l1sp_NetworkStatusNotification();
1766 // l1sp_CodecStatusNotification(am.speech_mode);
1767}
1768
1769void AM_DSP_InterRAT_2G_to_3G( uint32 codec , uint32 extraInfo)
1770{
1771 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_2GCall);
1772 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_3G(codec);
1773}
1774
1775void AM_DSP_3G_INTRARAT (uint32 codec, uint32 extraInfo)
1776{
1777 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_3GCall);
1778 MD_TRC_L1Audio_Msg_3G_INTRARAT(codec);
1779}
1780
1781#if defined(__C2K_SPEECH_SUPPORT__)
1782void AM_DSP_InterRAT_C2K_to_3G( uint32 codec , uint32 extraInfo)
1783{
1784 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_C2KCall);
1785 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_3G(codec);
1786}
1787#endif
1788
1789#if defined(__VOLTE_SUPPORT__)
1790void AM_DSP_InterRAT_4G_to_3G( uint32 codec , uint32 extraInfo)
1791{
1792 AM_DSP_RAT_sub_3G(codec, SAL_APP_TYPE_4GCall);
1793 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_3G(codec);
1794}
1795#endif
1796
1797void AM_InterRAT_2G_to_3G(uint32 codec)
1798{
1799 AM_Enqueue( AM_DSP_InterRAT_2G_to_3G, codec, 0, false );
1800 AM_FlushQFunction();
1801}
1802
1803void AM_3G_INTRARAT(uint32 codec)
1804{
1805 AM_Enqueue( AM_DSP_3G_INTRARAT, codec, 0, false );
1806 AM_FlushQFunction();
1807}
1808
1809#if defined(__C2K_SPEECH_SUPPORT__)
1810void AM_InterRAT_C2K_to_3G(uint32 codec)
1811{
1812 AM_Enqueue( AM_DSP_InterRAT_C2K_to_3G, codec, 0, false );
1813 AM_FlushQFunction();
1814}
1815#endif
1816
1817#if defined(__VOLTE_SUPPORT__)
1818void AM_InterRAT_4G_to_3G(uint32 codec)
1819{
1820 AM_Enqueue( AM_DSP_InterRAT_4G_to_3G, codec, 0, false );
1821 AM_FlushQFunction();
1822}
1823#endif
1824#endif
1825
1826#if defined(__C2K_SPEECH_SUPPORT__)
1827/*
1828 extraInfo: 0:call on; 1: HO; 2: resync; 3: dev Change
1829*/
1830void AM_DSP_TurnOnC2KSDSP(int codec, uint32 extraInfo ){
1831
1832 uint16 DelR, DelW, DelM;
1833
1834 MD_TRC_C2K_AM_DSP_TurnOnC2KSDSP(am.speech_mode, codec);
1835
1836 SPC2K_GetSyncDelayRW( &DelR, &DelW, &DelM);
1837 if((am.speech_mode != codec) && (!am.c2k_flag)) {
1838 cc_C2K_Call_Open (codec, _C2K_DTX_SUPPORT_, DelR, DelW, DelM, extraInfo); //VBIRest();
1839
1840 am.speech_mode = codec;
1841 am.c2k_flag = true; // ys
1842 }else{
1843 cc_C2K_Call_Open (codec, _C2K_DTX_SUPPORT_, DelR, DelW, DelM, extraInfo);//check by daniel//VBIRest();
1844 }
1845}
1846void AM_DSP_TurnOffC2KSDSP(uint32 data , uint32 extraInfo)
1847{
1848 MD_TRC_C2K_AM_DSP_TurnOffC2KSDSP();
1849
1850 cc_C2K_Call_Close(true);
1851
1852 //am.speech_mode = SAL_C2K_COD_MODE_UNDEF;
1853 am.c2k_flag = false;
1854}
1855
1856void AM_TurnOffC2KSDSP(void)
1857{
1858 //TO , move c2kflag here for symmetry
1859 AM_Enqueue( AM_DSP_TurnOffC2KSDSP, 0, 0, false );
1860 AM_FlushQFunction();
1861}
1862
1863void AM_DSP_RAT_sub_C2K(uint32 codec , uint32 extraInfo)
1864{
1865 if( !(am.state & AM_STATE_SPEECH) )
1866 return;
1867 if(extraInfo == SAL_APP_TYPE_2GCall){
1868 cc_2G_Call_Close(true);
1869 } else if(extraInfo == SAL_APP_TYPE_3GCall){
1870 cc_3G_Call_Close(true);
1871 am.sp3g_flag = false;
1872 }
1873#if defined(__VOLTE_SUPPORT__)
1874 else if(extraInfo == SAL_APP_TYPE_4GCall){
1875 SP4G_Call_Close();
1876 am.sp4g_flag = false;
1877 }
1878#endif
1879#if defined(__C2K_SPEECH_SUPPORT__)
1880 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1881 AM_DSP_TurnOffC2KSDSP(0, 0);
1882 }
1883#endif
1884 AM_DSP_TurnOnC2KSDSP(codec, 1);
1885 am.spc2k_flag = true;
1886 AM_Reset_Enh(codec);
1887 l1sp_NetworkStatusNotification();
1888}
1889
1890void AM_DSP_InterRAT_2G_to_C2K( uint32 codec , uint32 extraInfo)
1891{
1892 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_2GCall);
1893 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_C2K(codec);
1894}
1895
1896void AM_DSP_C2K_IntraRAT (uint32 codec, uint32 extraInfo)
1897{
1898 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_C2KCall);
1899 MD_TRC_L1Audio_Msg_C2K_INTRARAT(codec);
1900}
1901
1902#if defined( __UMTS_RAT__ )
1903void AM_DSP_InterRAT_3G_to_C2K( uint32 codec , uint32 extraInfo)
1904{
1905 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_3GCall);
1906 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_C2K(codec);
1907}
1908#endif
1909#if defined(__VOLTE_SUPPORT__)
1910void AM_DSP_InterRAT_4G_to_C2K( uint32 codec , uint32 extraInfo)
1911{
1912 AM_DSP_RAT_sub_C2K(codec, SAL_APP_TYPE_4GCall);
1913 MD_TRC_L1Audio_Msg_INTERRAT_4G_TO_C2K(codec);
1914}
1915#endif
1916
1917void AM_InterRAT_2G_to_C2K(uint32 codec)
1918{
1919 AM_Enqueue( AM_DSP_InterRAT_2G_to_C2K, codec, 0, false );
1920 AM_FlushQFunction();
1921}
1922
1923void AM_C2K_IntraRAT(uint32 codec)
1924{
1925 AM_Enqueue( AM_DSP_C2K_IntraRAT, codec, 0, false );
1926 AM_FlushQFunction();
1927}
1928#if defined( __UMTS_RAT__ )
1929void AM_InterRAT_3G_to_C2K(uint32 codec)
1930{
1931 AM_Enqueue( AM_DSP_InterRAT_3G_to_C2K, codec, 0, false );
1932 AM_FlushQFunction();
1933}
1934#endif
1935#if defined(__VOLTE_SUPPORT__)
1936void AM_InterRAT_4G_to_C2K(uint32 codec)
1937{
1938 AM_Enqueue( AM_DSP_InterRAT_4G_to_C2K, codec, 0, false );
1939 AM_FlushQFunction();
1940}
1941#endif
1942#endif
1943
1944#if defined(__VOLTE_SUPPORT__)
1945void AM_DSP_RAT_sub_4G(uint32 codec , uint32 extraInfo, uint32 resetType)
1946{
1947 //kal_uint16 u16DelayR, u16DelayW; //unused
1948 am.speech_mode = codec;
1949 if( !(am.state & AM_STATE_SPEECH) )
1950 return;
1951
1952 if(PS_SRST_TYPE_HO_WITH_VBIEND == resetType)
1953 {
1954 if(extraInfo == SAL_APP_TYPE_2GCall){
1955 cc_2G_Call_Close(true);
1956 } else if(extraInfo == SAL_APP_TYPE_3GCall){
1957 cc_3G_Call_Close(true);
1958 am.sp3g_flag = false;
1959 }
1960#if defined(__C2K_SPEECH_SUPPORT__)
1961 else if(extraInfo == SAL_APP_TYPE_C2KCall){
1962 AM_DSP_TurnOffC2KSDSP(0, 0);
1963 }
1964#endif
1965 else if(extraInfo == SAL_APP_TYPE_4GCall){
1966 SP4G_Call_Close();
1967 }
1968 }
1969
1970 //SP3G_GetSyncDelayRW( &u16DelayR, &u16DelayW);//????
1971 //SAL_4G_Upd_Enc_Cod(codec);//for 3g codec internal, MT6280
1972 //SAL_4G_Upd_Dec_Cod(codec);//for 3g codec internal, MT6280
1973 switch(SP4G_GetL2Mode()){
1974#if defined(__LTE_RAT__)
1975 case SP_PSCALL_EMAC:
1976 SAL_Set_PSRANType(SAL_PSRAN_TYPE_LTE);
1977 break;
1978#endif
1979#if defined(__NR_RAT__)
1980 case SP_PSCALL_NMAC:
1981 SAL_Set_PSRANType(SAL_PSRAN_TYPE_NR);
1982 break;
1983#endif
1984 case SP_PSCALL_NONE:
1985 SAL_Set_PSRANType(SAL_PSRAN_TYPE_NONE);
1986 break;
1987 default:
1988 ASSERT(0);
1989 break;
1990 }
1991 //SAL_4G_Call_Open(codec);
1992 SP4G_Call_Open(codec, resetType);
1993 AM_Reset_Enh(codec);
1994 l1sp_NetworkStatusNotification();
1995 // l1sp_CodecStatusNotification(am.speech_mode);
1996 am.sp4g_flag = true;
1997}
1998
1999void AM_DSP_InterRAT_2G_to_4G( uint32 codec , uint32 extraInfo)
2000{
2001 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729);//context is under task level, so g-series cannot be used
2002 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_2GCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2003 MD_TRC_L1Audio_Msg_INTERRAT_2G_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2004}
2005#if defined( __UMTS_RAT__ )
2006void AM_DSP_InterRAT_3G_to_4G( uint32 codec , uint32 extraInfo)
2007{
2008 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729);//context is under task level, so g-series cannot be used
2009 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_3GCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2010 MD_TRC_L1Audio_Msg_INTERRAT_3G_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2011}
2012#endif
2013#if defined(__C2K_SPEECH_SUPPORT__)
2014void AM_DSP_InterRAT_C2K_to_4G( uint32 codec , uint32 extraInfo)
2015{
2016 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_C2KCall, PS_SRST_TYPE_HO_WITH_VBIEND);
2017 MD_TRC_L1Audio_Msg_INTERRAT_C2K_TO_4G(codec, PS_SRST_TYPE_HO_WITH_VBIEND);
2018}
2019#endif
2020
2021void AM_DSP_4G_INTRARAT (uint32 codec, uint32 resetType)
2022{
2023 //ASSERT(codec < SP4G_CODEC_G711 || codec > SP4G_CODEC_G729); context is under task level, so g-series can be used
2024 AM_DSP_RAT_sub_4G(codec, SAL_APP_TYPE_4GCall, resetType);
2025 MD_TRC_L1Audio_Msg_4G_INTRARAT(codec, resetType);
2026}
2027
2028void AM_InterRAT_2G_to_4G(uint32 codec)
2029{
2030 AM_Enqueue( AM_DSP_InterRAT_2G_to_4G, codec, 0, false );
2031 AM_FlushQFunction();
2032}
2033#if defined( __UMTS_RAT__ )
2034void AM_InterRAT_3G_to_4G(uint32 codec)
2035{
2036 AM_Enqueue( AM_DSP_InterRAT_3G_to_4G, codec, 0, false );
2037 AM_FlushQFunction();
2038}
2039#endif
2040#if defined(__C2K_SPEECH_SUPPORT__)
2041void AM_InterRAT_C2K_to_4G(uint32 codec)
2042{
2043 AM_Enqueue( AM_DSP_InterRAT_C2K_to_4G, codec, 0, false );
2044 AM_FlushQFunction();
2045}
2046#endif
2047void AM_4G_INTRARAT(uint32 codec, uint32 resetType)
2048{
2049 AM_Enqueue( AM_DSP_4G_INTRARAT, codec, resetType, false );
2050 AM_FlushQFunction();
2051}
2052
2053void 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);
2054void SAL_4G_AMRCall_Close();
2055#if defined(__G_CODEC_SUPPORT__)
2056void SAL_4G_GSeriesCall_Open(int codec, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us, kal_uint32 resetType);
2057void SAL_4G_GSeriesCall_Close(int codec);
2058#endif
2059#if defined(__EVS_CODEC_SUPPORT__)
2060void 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);
2061void SAL_4G_EVSCall_Close(void);
2062#endif //#if defined(__EVS_CODEC_SUPPORT__)
2063
2064void SP4G_Call_Open(uint16 codec, PS_RESET_TYPE_t resetType)
2065{
2066 kal_uint16 delayR, delayW, delayM;
2067 kal_uint32 u32CurTime64us;
2068
2069 if(PS_SRST_TYPE_HO_WITH_VBIEND == resetType)
2070 {
2071 ASSERT(am.codec_4g == -1);
2072 }
2073 SAL_Set_AWBPlusFlag(0);
2074 am.codec_4g = codec;
2075 SP4G_GetSyncDelayRW( &delayR, &delayW, &delayM, &u32CurTime64us);
2076#if defined(__G_CODEC_SUPPORT__)
2077 if((codec >= SP4G_CODEC_G711) && (codec <= SP4G_CODEC_G729)){
2078 SAL_4G_GSeriesCall_Open(codec, delayR, delayW, delayM, u32CurTime64us, resetType);
2079 }else
2080#endif
2081 {
2082#if defined(__EVS_CODEC_SUPPORT__)
2083 if(is_EVS_codec((uint8)codec)){
2084 if( get_sp4g_fake_EVS_IO() )
2085 {
2086 SAL_Set_AWBPlusFlag(1);
2087 }
2088 SAL_4G_EVSCall_Open((kal_uint32)codec, (kal_uint32)SP4G_IsDTXOn(), (kal_uint32)delayR, (kal_uint32)delayW, (kal_uint32)delayM, (kal_uint32)u32CurTime64us, resetType);
2089 }else
2090#endif //#if defined(__EVS_CODEC_SUPPORT__)
2091 {
2092 SAL_4G_AMRCall_Open(codec, SP4G_IsDTXOn(), delayR, delayW, delayM, u32CurTime64us, resetType);
2093 }
2094 }
2095}
2096
2097void SP4G_Call_Close(void){
2098 ASSERT(am.codec_4g != -1);
2099 SAL_Set_AWBPlusFlag(0);
2100#if defined(__G_CODEC_SUPPORT__)
2101 if( is_g_codec(am.codec_4g) ){
2102 SAL_4G_GSeriesCall_Close(SAL_PCM_NARROWBAND);
2103 }else
2104#endif
2105 {
2106#if defined(__EVS_CODEC_SUPPORT__)
2107 if(is_EVS_codec(am.codec_4g)){
2108 SAL_4G_EVSCall_Close();
2109 }else
2110#endif //#if defined(__EVS_CODEC_SUPPORT__)
2111 {
2112 SAL_4G_AMRCall_Close();
2113 }
2114 }
2115 am.codec_4g = -1;
2116}
2117//extern void SAL_Set4G(bool b);
2118void 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)
2119{
2120 //SP4G_GetSyncDelayRW( &u16DelayR, &u16DelayW);
2121 SAL_3G_Upd_Enc_Cod(codec);
2122 SAL_3G_Upd_Dec_Cod(codec);
2123 //cc_3G_Call_Open(codec, codec, SP4G_IsDTXOn(), u16DelayR, u16DelayW, DSP_PCM_IDLE_DELAY_TABLE[6][2]);
2124 //SAL_Set4G(true);
2125 cc_4G_Call_Open_temp(codec, codec, isDTX, u16DelayR, u16DelayW, idle_delay, u32CurTime64us, resetType);
2126 MD_TRC_L1Audio_Msg_SP4G_FORCE_RESYNC( codec, codec, u16DelayR, u16DelayW);
2127};
2128
2129void SAL_4G_AMRCall_Close()
2130{
2131 cc_4G_Call_Close_temp(true);
2132 //SAL_Set4G(false);
2133}
2134
2135
2136void SAL_4G_GSeriesCall_Open(int codec, kal_uint16 u16DelayR, kal_uint16 u16DelayW, const uint16 idle_delay, kal_uint32 u32CurTime64us,
2137 kal_uint32 resetType){
2138 int band_mod = SAL_NB;
2139 if(SP4G_CODEC_G722 == codec )
2140 band_mod = SAL_WB;
2141
2142 //SAL_Set4G(true);
2143 //memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
2144 //cfg.idle = false;//true;
2145 //cfg.swi = SAL_PCMEX_SWITCH_ON;
2146 //cfg.type = SAL_PCMEX_TYPE_VOLTE;
2147 //cfg.band = band;//SAL_PCM_NARROWBAND
2148 //SAL_PcmEx_Config(&cfg);
2149
2150 /*if(band == SAL_PCM_WIDEBAND)
2151 {
2152 AMR_codec_temp = SP4G_CODEC_WBAMR_12_65;
2153 }
2154 else
2155 {
2156 AMR_codec_temp = SP4G_CODEC_AMR_12_2;
2157 }
2158 SAL_3G_Upd_Enc_Cod(AMR_codec_temp);
2159 SAL_3G_Upd_Dec_Cod(AMR_codec_temp);*/
2160 cc_4G_G_Codec_Call_Open(band_mod, u16DelayR, u16DelayW, idle_delay, u32CurTime64us, resetType);
2161
2162 {
2163 void GSeries_Encode_Init(SP4G_Codec codec);
2164 void GSeries_Decode_Init(SP4G_Codec codec);
2165 GSeries_Encode_Init(codec);
2166 GSeries_Decode_Init(codec);
2167 //SP4G_SetCodec(codec);//fix
2168 }
2169 Extcodec_Call_Open();
2170#if 0
2171/* under construction !*/
2172/* under construction !*/
2173/* under construction !*/
2174/* under construction !*/
2175/* under construction !*/
2176/* under construction !*/
2177/* under construction !*/
2178/* under construction !*/
2179#if 0
2180/* under construction !*/
2181/* under construction !*/
2182/* under construction !*/
2183/* under construction !*/
2184/* under construction !*/
2185#else /*#if 0*/
2186/* under construction !*/
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#endif /*#if 0*/
2198/* under construction !*/
2199/* under construction !*/
2200/* under construction !*/
2201/* under construction !*/
2202#ifndef L1D_TEST
2203/* under construction !*/
2204/* under construction !*/
2205#endif
2206/* under construction !*/
2207#endif
2208 kal_prompt_trace(MOD_L1SP, "[SAL_4G_GSeriesCall_Open] SAL_PcmEx_CheckState OK");
2209
2210
2211}
2212
2213
2214void SAL_4G_GSeriesCall_Close(int codec){
2215 Extcodec_Call_Close();
2216#if 0
2217/* under construction !*/
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#endif
2233 ////SAL_Set4G(false);
2234 {
2235 void GSeries_Encode_DeInit();
2236 void GSeries_Decode_DeInit();
2237 }
2238
2239 //fsju
2240 cc_4G_G_Codec_Call_Close(true);
2241}
2242
2243
2244#if defined(__EVS_CODEC_SUPPORT__)
2245void SP4G_EVS_CallOpenSetPar(void);
2246#endif //#if defined(__EVS_CODEC_SUPPORT__)
2247void 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)
2248{
2249#if defined(__EVS_CODEC_SUPPORT__)
2250 SP4G_EVS_CallOpenSetPar();
2251#endif //#if defined(__EVS_CODEC_SUPPORT__)
2252
2253 //cc_4G_EVS_Codec_Call_Open(codec, codec, 0/*isDTX*/, u16DelayR, u16DelayW, idle_delay, u32CurTime64us);
2254 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);
2255
2256 //kal_prompt_trace(MOD_L1SP, "[SAL_4G_EVSCall_Open] SAL_PcmEx_CheckState OK");
2257 MD_TRC_L1Audio_Msg_SP4G_EVSSeriesCall_Open_OK();
2258}
2259
2260
2261void SAL_4G_EVSCall_Close(void)
2262{
2263 cc_4G_EVS_Codec_Call_Close(1);
2264}
2265
2266
2267#endif
2268
2269kal_bool AM_Is_4G()
2270{
2271#if defined(__VOLTE_SUPPORT__)
2272 return am.sp4g_flag;
2273#else
2274 return KAL_FALSE;
2275#endif
2276}
2277
2278
2279
2280/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2281#if 0
2282/* under construction !*/
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#endif
2293
2294/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2295static void AM_DSP_VMRecordOn( uint32 speech_mode , uint32 extraInfo)
2296{
2297 Sal_VM_Config_t cfg_t;
2298 memset(&cfg_t, 0, sizeof(Sal_VM_Config_t));
2299
2300 cfg_t.swi = SAL_VM_SWITCH_ON;
2301
2302 if( am.state & (AM_STATE_SPEECH |AM_STATE_VOIP |AM_STATE_VOICE) ) { /* Conversation Recording */
2303 ASSERT(!(am.speech_state & SP_STATE_VMR));
2304 cfg_t.idle = false;
2305 am.speech_state |= SP_STATE_VMR;
2306 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(0) , L1AUDIO_Str_onoff(1) );
2307 }
2308 else { /* VM in idle mode */
2309#if 0
2310/* under construction !*/
2311/* under construction !*/
2312/* under construction !*/
2313/* under construction !*/
2314#if defined(AMRWB_ENCODE) // not define in samrt phone
2315/* under construction !*/
2316/* under construction !*/
2317/* under construction !*/
2318/* under construction !*/
2319/* under construction !*/
2320#endif//#if defined(AMRWB_ENCODE)
2321/* under construction !*/
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#endif
2332 }
2333
2334 SAL_VM_Config(&cfg_t);
2335
2336}
2337
2338void AM_VMRecordOn( void )
2339{
2340 AM_Enqueue( AM_DSP_VMRecordOn, 0, 0, false );
2341
2342 AM_FlushQFunction();
2343}
2344
2345
2346static void AM_DSP_VMRecordOff( uint32 data , uint32 extraInfo)
2347{
2348 (void)data;
2349 Sal_VM_Config_t cfg_t;
2350 memset(&cfg_t, 0, sizeof(Sal_VM_Config_t));
2351
2352 cfg_t.swi = SAL_VM_SWITCH_OFF;
2353 cfg_t.idle = false;
2354
2355 if(am.speech_state & SP_STATE_VMR) /* Conversation Recording */
2356 {
2357 am.speech_state &= ~SP_STATE_VMR;
2358 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(0) , L1AUDIO_Str_onoff(0) );
2359 SAL_VM_Config(&cfg_t);
2360 }
2361 else /* VM in idle mode */
2362 {
2363#if 0
2364/* under construction !*/
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#endif
2374 }
2375}
2376
2377void AM_VMRecordOff( void )
2378{
2379#if 0
2380/* under construction !*/
2381/* under construction !*/
2382/* under construction !*/
2383/* under construction !*/
2384/* under construction !*/
2385#endif
2386 AM_Enqueue( AM_DSP_VMRecordOff, 0, 0, false );
2387}
2388
2389/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2390#if 0
2391/* under construction !*/
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#endif
2503
2504/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2505static void AM_DSP_KeyToneOn( uint32 data , uint32 extraInfo)
2506{
2507 (void)data;
2508 ASSERT(!(am.state & AM_STATE_KEYTONE));
2509 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(0), L1AUDIO_Str_onoff(1) );
2510
2511 if ( am.state == 0 ) { // ( (am.state & ~AM_STATE_AVSYNC) == 0 ) {
2512 AFE_TurnOn8K();
2513 // AM_Write_Idle_Delay(4); // driver dost not support idle playback function, remove
2514 VBI_Reset();
2515 }
2516 am.state |= AM_STATE_KEYTONE;
2517}
2518
2519void AM_KeyToneOn( void )
2520{
2521 AM_Enqueue( AM_DSP_KeyToneOn, 0, 0, false );
2522}
2523
2524static void AM_DSP_KeyToneOff( uint32 data , uint32 extraInfo)
2525{
2526 (void)data;
2527 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(0), L1AUDIO_Str_onoff(0) );
2528 am.state &= ~AM_STATE_KEYTONE;
2529
2530 if(am.state == 0)
2531 VBI_End();
2532
2533 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2534 AFE_TurnOff8K();
2535}
2536
2537void AM_KeyToneOff( void )
2538{
2539 AM_Enqueue( AM_DSP_KeyToneOff, 0, 0, false );
2540}
2541
2542bool AM_IsKeyToneOn( void )
2543{
2544 if (am.state & AM_STATE_KEYTONE)
2545 return true;
2546 return false;
2547}
2548
2549/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2550static void AM_DSP_ToneOn( uint32 data , uint32 extraInfo)
2551{
2552 (void)data;
2553 ASSERT(!(am.state & AM_STATE_TONE));
2554 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(1), L1AUDIO_Str_onoff(1) );
2555
2556 if( am.state == 0 ) { // ( (am.state & ~AM_STATE_AVSYNC) == 0) {
2557 AFE_TurnOn8K();
2558 // AM_Write_Idle_Delay(4); // driver not support idle playback function, so remove
2559 VBI_Reset();
2560 }
2561 am.state |= AM_STATE_TONE;
2562}
2563
2564void AM_ToneOn( void )
2565{
2566 AM_Enqueue( AM_DSP_ToneOn, 0, 0, false );
2567
2568
2569}
2570
2571static void AM_DSP_ToneOff( uint32 data , uint32 extraInfo)
2572{
2573 (void)data;
2574 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(1), L1AUDIO_Str_onoff(0) );
2575 am.state &= ~AM_STATE_TONE;
2576
2577 if( am.state == 0 )
2578 VBI_End();
2579
2580 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2581 AFE_TurnOff8K();
2582}
2583
2584void AM_ToneOff( void )
2585{
2586 AM_Enqueue( AM_DSP_ToneOff, 0, 0, false );
2587}
2588
2589bool AM_IsToneOn( void )
2590{
2591 if (am.state & AM_STATE_TONE)
2592 return true;
2593 return false;
2594}
2595
2596
2597/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2598
2599static void AM_DSP_PCM8K_PlaybackOn( uint32 data , uint32 extraInfo)
2600{
2601 uint16 u16DelayR, u16DelayW, u16DelayM;
2602
2603 (void)data;
2604
2605 if( am.state == 0 ) {
2606 AFE_TurnOn8K();
2607 SAL_Get_Delay(SAL_DEALY_PCM8K_PB, SAL_DELAY_NA, SAL_DELAY_NA, &u16DelayR, &u16DelayW, &u16DelayM);
2608 SAL_App_Open(u16DelayR, u16DelayW, u16DelayM);
2609 }
2610// #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2611 if ( data == 1 )
2612 {
2613 ASSERT(!(am.state & AM_STATE_SND_EFFECT));
2614 am.state |= AM_STATE_SND_EFFECT;
2615 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(9), L1AUDIO_Str_onoff(1) );
2616 }
2617 else
2618// #endif // #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2619 {
2620 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
2621 am.state |= AM_STATE_VOICE;
2622 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(2), L1AUDIO_Str_onoff(1) );
2623 }
2624}
2625
2626#if 0
2627/* under construction !*/
2628/* under construction !*/
2629/* under construction !*/
2630/* under construction !*/
2631/* under construction !*/
2632/* under construction !*/
2633/* under construction !*/
2634#endif
2635
2636static void AM_DSP_PCM8K_PlaybackOff( uint32 data , uint32 extraInfo)
2637{
2638 (void)data;
2639
2640// #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2641 if( data == 1 )
2642 {
2643 am.state &= ~AM_STATE_SND_EFFECT;
2644 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(9), L1AUDIO_Str_onoff(0) );
2645 }
2646 else
2647// #endif // #if defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
2648 {
2649 am.state &= ~AM_STATE_VOICE;
2650 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(2), L1AUDIO_Str_onoff(0) );
2651 }
2652 SAL_App_Close(am.state == 0);
2653
2654 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2655 AFE_TurnOff8K();
2656}
2657
2658#if 0
2659/* under construction !*/
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#endif
2680
2681
2682/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2683#if 0
2684/* under construction !*/
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#endif
2729/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2730
2731uint32 AM_GetRecordFormat()
2732{
2733 return am.record_format;
2734}
2735
2736/**
2737 @data: bit[0:3] DL position
2738*/
2739static void AM_DSP_PCM16K_RecordOn( uint32 data , uint32 extraInfo)
2740{
2741 (void)extraInfo;
2742 Sal_PCMEx_Config_t cfg_t;
2743 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2744
2745 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
2746 am.record_format = AM_RECORD_16K;
2747
2748
2749 cfg_t.idle = true;
2750 cfg_t.band = SAL_PCM_WIDEBAND;
2751 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2752 cfg_t.swi = SAL_PCMEX_SWITCH_ON;
2753 cfg_t.PCMRec_DL_Pos = (data&0xF);
2754 SAL_Get_Delay(SAL_DEALY_PCM16K, SAL_DELAY_NA, SAL_DELAY_NA, &cfg_t.delR, &cfg_t.delW, &cfg_t.delM);
2755
2756 //config related digital device(nb/wb),
2757 // am_SetDevice();
2758
2759 AFE_TurnOn8K();
2760
2761 SAL_PcmEx_Config(&cfg_t);
2762
2763 am.state |= AM_STATE_VOICE;
2764 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(10), L1AUDIO_Str_onoff(1) );
2765}
2766
2767void AM_PCM16K_RecordOn( uint8 dlPos )
2768{
2769
2770 if(!(am.state & AM_STATE_SPEECH))
2771 {
2772 AM_Enqueue( AM_DSP_PCM16K_RecordOn, dlPos, 0, false );
2773 AM_FlushQFunction();
2774
2775 // enable enhancement
2776 if(!AM_IsBTCordlessMode())
2777 {
2778 SetSpeechEnhancement(true);
2779 }
2780 } else {
2781 DEBUG_ASSERT(0);
2782 }
2783
2784}
2785
2786static void AM_DSP_PCM16K_RecordOff( uint32 data , uint32 extraInfo)
2787{
2788 (void)data;
2789 (void)extraInfo;
2790 Sal_PCMEx_Config_t cfg_t;
2791 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2792
2793 cfg_t.swi = SAL_PCMEX_SWITCH_OFF;
2794 am.state &= ~AM_STATE_VOICE;
2795 am.record_format = AM_RECORD_NONE;
2796 cfg_t.idle = false;
2797 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(10), L1AUDIO_Str_onoff(0) );
2798
2799 if( am.state == 0 ) {
2800 cfg_t.idle = true;
2801 }
2802 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2803
2804 SAL_PcmEx_Config(&cfg_t);
2805
2806 if( am.state == 0 ) {
2807 AFE_TurnOff8K();
2808 }
2809}
2810
2811void AM_PCM16K_RecordOff( bool wait )
2812{
2813 // turn off speech enhancment
2814 if(!(am.state & AM_STATE_SPEECH))
2815 {
2816 if(!AM_IsBTCordlessMode())
2817 {
2818 SetSpeechEnhancement(false);
2819 }
2820
2821 AM_Enqueue( AM_DSP_PCM16K_RecordOff, 0, 0, false );
2822 if( wait )
2823 AM_FlushQFunction();
2824 } else {
2825 DEBUG_ASSERT(0);
2826 }
2827}
2828
2829/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2830/**
2831 @extraInfo: bit[0:3] DL position when appType is AM_PCM8KREC_APP_TYPE_PCMREC
2832*/
2833static void AM_DSP_PCM8K_RecordOn( uint32 appType , uint32 extraInfo)
2834{
2835 (void)extraInfo;
2836
2837 Sal_PCMEx_Config_t cfg_t;
2838 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2839
2840 cfg_t.idle = false;
2841 cfg_t.swi = SAL_PCMEX_SWITCH_ON;
2842
2843 am.record_format = AM_RECORD_8K;
2844
2845 if( am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)) {
2846 // REMIND: Call record and VM EPL can work in the same time,
2847 // but they use same interrupt and setting.
2848
2849 if (AM_PCM8KREC_APP_TYPE_PCMREC == appType) { // Conversation Recording
2850 if (!(am.speech_state & SP_STATE_PCM8K_REC)) {
2851 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2852 cfg_t.PCMRec_DL_Pos = (extraInfo&0xF);
2853 am.speech_state |= SP_STATE_PCM8K_REC;
2854
2855 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(1) , L1AUDIO_Str_onoff(1) );
2856 } else {
2857 return;
2858 }
2859 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // VM EPL
2860 if (!(am.speech_state & SP_STATE_VMR_EPL)) {
2861 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2862 am.speech_state |= SP_STATE_VMR_EPL;
2863 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(4) , L1AUDIO_Str_onoff(1) );
2864 } else {
2865 return;
2866 }
2867 } else {
2868 DEBUG_ASSERT(0); // unknown application type
2869 return;
2870 }
2871
2872 }else{
2873 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // idle epl
2874 if((am.state & AM_STATE_VOICE)
2875 && (!(am.speech_state & SP_STATE_VMR_EPL))) {
2876
2877 am.speech_state |= SP_STATE_VMR_EPL;
2878 cfg_t.idle = false;
2879 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2880 } else {
2881 return;
2882 }
2883 } else { // idle record
2884 if( !(am.state & AM_CONFLICT_STATE) ){
2885 am.state |= AM_STATE_VOICE;
2886
2887 cfg_t.idle = true;
2888 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2889 cfg_t.band = SAL_PCM_NARROWBAND;
2890 cfg_t.PCMRec_DL_Pos = (extraInfo&0xF);
2891 SAL_Get_Delay(SAL_DEALY_NOTAMR, SAL_DELAY_NA, SAL_DELAY_NA, &cfg_t.delR, &cfg_t.delW, &cfg_t.delM);
2892 } else {
2893 return;
2894 }
2895 }
2896 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(4), L1AUDIO_Str_onoff(1) );
2897 }
2898
2899 if(cfg_t.idle)
2900 AFE_TurnOn8K();
2901
2902 SAL_PcmEx_Config(&cfg_t);
2903}
2904
2905void AM_PCM8K_RecordOn( AM_PCM8KREC_APP_TYPE appType, uint8 dlPos )
2906{
2907
2908 AM_Enqueue( AM_DSP_PCM8K_RecordOn, (uint32)appType, dlPos, false );
2909 AM_FlushQFunction();
2910
2911 if(!(am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)))
2912 {
2913 if(!AM_IsBTCordlessMode())
2914 {
2915 SetSpeechEnhancement(true);
2916 }
2917 }
2918}
2919
2920static void AM_DSP_PCM8K_RecordOff( uint32 appType , uint32 extraInfo)
2921{
2922 Sal_PCMEx_Config_t cfg_t;
2923 memset(&cfg_t, 0, sizeof(Sal_PCMEx_Config_t));
2924
2925 am.record_format = AM_RECORD_NONE;
2926 cfg_t.swi = SAL_PCMEX_SWITCH_OFF;
2927 cfg_t.idle = false;
2928
2929 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType)
2930 cfg_t.type = SAL_PCMEX_TYPE_REC_NML;
2931 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType)
2932 cfg_t.type = SAL_PCMEX_TYPE_REC_EPL;
2933
2934 if(am.speech_state & (SP_STATE_PCM8K_REC|SP_STATE_VMR_EPL) ) // under call
2935 {
2936 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType) {
2937 am.speech_state &= ~SP_STATE_PCM8K_REC;
2938 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType){
2939 am.speech_state &= ~SP_STATE_VMR_EPL;
2940 } else {
2941 DEBUG_ASSERT(0); // unknow application type
2942 return;
2943 }
2944
2945 if(AM_PCM8KREC_APP_TYPE_PCMREC == appType) {
2946 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(1) , L1AUDIO_Str_onoff(0) );
2947 } else if(AM_PCM8KREC_APP_TYPE_VMEPL == appType){
2948 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(4) , L1AUDIO_Str_onoff(0) );
2949 }
2950 }
2951 else
2952 {
2953 if(AM_PCM8KREC_APP_TYPE_VMEPL == appType) { // idle VM epl
2954 am.speech_state &= ~SP_STATE_VMR_EPL;
2955 } else { // idle record
2956 am.state &= ~AM_STATE_VOICE;
2957 }
2958 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(4), L1AUDIO_Str_onoff(0) );
2959 }
2960
2961 if( am.state == 0 ) {
2962 cfg_t.idle = true;
2963 }
2964
2965 SAL_PcmEx_Config(&cfg_t);
2966 if( am.state == 0 ) // (am.state & ~AM_STATE_AUDIO) == 0 ) // no audio state exist
2967 AFE_TurnOff8K();
2968}
2969
2970void AM_PCM8K_RecordOff( bool wait , AM_PCM8KREC_APP_TYPE appType)
2971{
2972 if(!(am.state & (AM_STATE_SPEECH | AM_STATE_VOIP)))
2973 {
2974 if(!AM_IsBTCordlessMode())
2975
2976 {
2977 SetSpeechEnhancement(false);
2978 }
2979 }
2980
2981 AM_Enqueue( AM_DSP_PCM8K_RecordOff, (uint32)appType, 0, false );
2982
2983 if( wait )
2984 AM_FlushQFunction();
2985}
2986
2987/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2988int16 AM_IsAudioPlaybackOn( void )
2989{
2990#if 0
2991/* under construction !*/
2992/* under construction !*/
2993/* under construction !*/
2994#endif
2995 return -1;
2996}
2997
2998int16 AM_IsIdleState( void )
2999{
3000 if( am.state == 0 )
3001 return true;
3002 return false;
3003}
3004
3005#if 0
3006/* under construction !*/
3007/* under construction !*/
3008/* under construction !*/
3009/* under construction !*/
3010/* under construction !*/
3011/* under construction !*/
3012/* under construction !*/
3013#endif
3014
3015bool AM_IsVoiceOn( void )
3016{
3017 if(am.state !=0 ) // ( am.state & ~AM_STATE_AUDIO) // no audio state exist
3018 return true;
3019 return false;
3020}
3021
3022/* ==========================================================================*/
3023static void RampPush( RampStatus status)
3024{
3025 if(RB_FULL(am.ramp_point_queue)) {
3026 MD_TRC_L1SP_MUTE_DSP_RAMP_QUEUE_FULL();
3027 } else {
3028 RB_PUT(am.ramp_point_queue, status);
3029 }
3030}
3031
3032static void RampPop( void )
3033{
3034 if(RB_EMPTY(am.ramp_point_queue)) {
3035 MD_TRC_L1SP_MUTE_DSP_RAMP_QUEUE_EMPTY();
3036 ASSERT(0);
3037 } else {
3038 RB_CONSUME(am.ramp_point_queue);
3039 }
3040}
3041
3042void AM_RAMP_INIT(bool mute, uint16 ramp_point)
3043{
3044 Sal_Ramp_State_t preState = SAL_Ramp_GetState(ramp_point);
3045 RampStatus rampStatus;
3046 rampStatus.RampPoint = ramp_point;
3047 rampStatus.MuteState = mute;
3048 MD_TRC_L1SP_MUTE_DSP_RAMP_CONTROL(0, ramp_point, preState, mute, am.state);
3049 if(AM_IsAmInSpeechState())
3050 {
3051 if(mute) {
3052 if( SAL_RAMP_DOWN_DONE == preState) {
3053#if defined(__SMART_PHONE_MODEM__)
3054 spc_sendRampDoneAck(rampStatus.RampPoint);
3055#endif
3056 } else { // if state in RAMP_DOWN_INIT or RAMP_DOWN_RUN, it won't take effect
3057 SAL_RampDown_SetInit(ramp_point);
3058 RampPush(rampStatus);
3059 }
3060 } else { // unmute
3061 if( SAL_RAMP_DOWN_DONE == preState) { // no sound, so ramp up
3062 SAL_RampUp_SetInit(ramp_point);
3063 RampPush(rampStatus);
3064 } else { // if state in RAMP_UP_INIT or RAMP_UP_RUN, it won't take effect
3065#if defined(__SMART_PHONE_MODEM__)
3066 spc_sendRampDoneAck(rampStatus.RampPoint);
3067#endif
3068 }
3069 }
3070 } else {
3071 if( mute) {
3072 SAL_Ramp_SetMute(rampStatus.RampPoint);
3073 } else {
3074 SAL_Ramp_SetUnMute(rampStatus.RampPoint);
3075 }
3076 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] No in speech state!");
3077#if defined(__SMART_PHONE_MODEM__)
3078 spc_sendRampDoneAck(rampStatus.RampPoint);
3079#endif
3080 }
3081 MD_TRC_L1SP_MUTE_DSP_RAMP_CONTROL(1, ramp_point, SAL_Ramp_GetState(ramp_point),mute,am.state);
3082}
3083void AM_RAMP_DONE(void)
3084{
3085 RampStatus rampStatus;
3086 while (!RB_EMPTY(am.ramp_point_queue)) {
3087 RB_PEEK(am.ramp_point_queue, rampStatus);
3088 MD_TRC_L1SP_MUTE_DSP_RAMP_DONE_STATE(rampStatus.MuteState, rampStatus.RampPoint, am.state);
3089 if(AM_IsAmInSpeechState()) {
3090 if(rampStatus.MuteState) {
3091 if(SAL_RampDown_IsDone(rampStatus.RampPoint)) {
3092 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] ramp down pass!");
3093 } else {
3094 MD_TRC_L1SP_MUTE_DSP_RAMP_DELAY_MUTE();
3095 break;
3096 }
3097 } else {
3098 if(SAL_RampUp_IsDone(rampStatus.RampPoint)) {
3099 kal_prompt_trace(MOD_L1SP, "[AM_Ramp_Point] ramp up pass!");
3100 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3101 } else {
3102 MD_TRC_L1SP_MUTE_DSP_RAMP_DELAY_UNMUTE();
3103 break;
3104 }
3105 }
3106 } else { // force mute/unmute when call end
3107 if(rampStatus.MuteState) {
3108 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3109 SAL_Ramp_SetMute(rampStatus.RampPoint);
3110 MD_TRC_L1SP_MUTE_DSP_RAMP_FORCE_MUTE();
3111 } else {
3112 SAL_Ramp_SetFinal(rampStatus.RampPoint);
3113 MD_TRC_L1SP_MUTE_DSP_RAMP_FORCE_UNMUTE();
3114 }
3115 }
3116 RampPop();
3117#if defined(__SMART_PHONE_MODEM__)
3118 spc_sendRampDoneAck(rampStatus.RampPoint);
3119#endif
3120 }
3121}
3122void AM_Mute_UL_EnhResult_Speech(bool mute)
3123{
3124 MD_TRC_L1SP_MUTE_DSP_UL_ENH_RESULT_CONTROL(mute);
3125 SAL_Mute_Ctrl(SAL_MUTE_UL_IN_EN, mute); // in the enhancement end point, which is set -60db to the result.
3126}
3127
3128void AM_Mute_UL_Source_Speech(bool mute)
3129{
3130 AM_RAMP_INIT(mute, SAL_RAMP_UL_PRE_EN);
3131}
3132
3133void AM_Mute_UL_Codec_Speech( bool mute )
3134{
3135 MD_TRC_L1SP_MUTE_DSP_UL_CODEC_CONTROL(mute);
3136 SAL_Mute_Ctrl(SAL_MUTE_UL_PRE_EXTCOD, mute); // need to under this position, or background sound won't be mute.
3137}
3138
3139void AM_Mute_UL_POS_EN_Speech( bool mute )
3140{
3141 AM_RAMP_INIT(mute, SAL_RAMP_UL_POS_EN);
3142
3143}
3144
3145void AM_Mute_DL_8K_Speech( bool mute )
3146{
3147 AM_RAMP_INIT(mute, SAL_RAMP_DL_PRE_DACA);
3148}
3149
3150void AM_Mute_DL_Speech_Traffic( bool mute )
3151{
3152 MD_TRC_L1SP_MUTE_DSP_DL_TRAFFIC_CONTROL(mute);
3153 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
3154}
3155
3156void AM_Mute_DL_PRE_PcmMixer(bool mute)
3157{
3158 AM_RAMP_INIT(mute, SAL_RAMP_DL_PRE_MIXER2);
3159}
3160
3161
3162
3163void AM_Init( void )
3164{
3165 am.dsp_2g_reset = false;
3166
3167 am.record_format = AM_RECORD_NONE;
3168 RB_INIT( am.qfunc );
3169 am.state = 0;
3170 am.speech_mode = 0;
3171 am.pre_speech_mode = 0;
3172 am.sub_channel = 0;
3173 am.is_reset_enh = 0;
3174 // am.speech_off_delay = 0;
3175 // am.pre_isWBLink = KAL_FALSE;
3176#if defined(_SPE_ENH_MD_PARSE_)
3177 am.isFirCoeffSet = false;
3178#endif
3179
3180 SAL_Dsp_Sph_Init();
3181
3182 // AM_WriteSidetoneFIR(); // 93 not dsp sidetone, so remove
3183
3184#if defined(_SPE_ENH_MD_PARSE_)
3185
3186 if( am.isFirCoeffSet == KAL_FALSE ) {
3187 AM_WriteWbFirCoeffs( WB_Speech_Input_FIR_Coeff[0], WB_Speech_Output_FIR_Coeff[0] );
3188 AM_WriteFirCoeffs( WB_Speech_Input_FIR_Coeff[0], WB_Speech_Output_FIR_Coeff[0] );
3189 }
3190 #endif
3191 // AM_WriteAntiAliasFilter();
3192
3193 am.io_type = NORMAL_MODE;
3194 am.speech_state = 0;
3195 // am.voip_state = 0;
3196 // am.fLoopBack = false;
3197 am.sp3g_flag = false;
3198#if defined(__C2K_SPEECH_SUPPORT__)
3199 am.spc2k_flag = false;
3200 am.c2k_flag = false;
3201#endif
3202#if defined(__VOLTE_SUPPORT__)
3203 am.sp4g_flag = false;
3204 am.codec_4g = -1;
3205#endif
3206
3207 // AM_DSP_SetSpeechDigitalGain(DG_DL_Speech); // replace by spGain_Init()
3208 // AM_DSP_SetSpeechEnhRefDigitalGain(DG_DL_Speech); //am.speechDlEnhRefDigtalGain init // replace by spGain_Init
3209}
3210
3211/* ========================================================================= */
3212/* Bluetooth control Functions */
3213/* ========================================================================= */
3214
3215
3216static void AM_DSP_BluetoothOn( uint32 data , uint32 extraInfo)
3217{
3218 Sal_BT_Config cfg_t;
3219 memset(&cfg_t, 0, sizeof(Sal_BT_Config));
3220 cfg_t.feed_cfg = true;
3221
3222
3223 // leave the gain control to AP. do not do any backup now
3224 // am.bt_digital_gain = AM_DSP_GetSpeechDigitalGain(); //*DP_VOL_OUT_PCM;
3225 // am.bt_dlEnhRef_digital_gain = AM_GetSpeechEnhRefDigitalGain(); // use am.speechDlEnhRefDigtalGain
3226
3227 // Zero-pending
3228 cfg_t.linear_ctrl = SAL_BT_LINEAR_GAIN_CONFIG_ZPAD;
3229 cfg_t.mode = SAL_BT_MODE_LINEAR;
3230 // MSB first
3231 cfg_t.linear_reverse = false;
3232
3233 //set mode and uplink gain
3234 cfg_t.linear_ul_gain = 1;
3235
3236 // leave the gain control to AP. do not do any backup now
3237 // AM_DSP_SetSpeechDigitalGain(default_bt_pcm_out_vol); // *DP_VOL_OUT_PCM = 0x1000;
3238 // AM_DSP_SetSpeechUplinkSwAgcGain(0); // AGC set to 0 db
3239 // AM_DSP_SetSpeechEnhRefDigitalGain(default_bt_pcm_out_enh_ref_vol); // 0db
3240
3241
3242 SAL_BT_Config(&cfg_t);
3243
3244 am.io_type = BT_EARPHONE_MODE;
3245 MD_TRC_L1Audio_Msg_AM_IO_Switch( AM_IO_Name(am.io_type) );
3246}
3247
3248static void AM_DSP_BluetoothOff( uint32 data , uint32 extraInfo)
3249{
3250 Sal_BT_Config cfg_t;
3251 memset(&cfg_t, 0, sizeof(Sal_BT_Config));
3252
3253 cfg_t.feed_cfg = false;
3254
3255 // AFE_SetBtFlag(KAL_FALSE);
3256
3257 // leave the gain control to AP. do not do restore the value to default now
3258 // AM_DSP_SetSpeechDigitalGain(am.bt_digital_gain);
3259 // AM_DSP_SetSpeechUplinkSwAgcGain(am.speechUplinkSwAgcGain);
3260 // AM_DSP_SetSpeechEnhRefDigitalGain(am.speechDlEnhRefDigtalGain);
3261
3262 SAL_BT_Config(&cfg_t);
3263
3264 am.io_type = NORMAL_MODE;
3265 MD_TRC_L1Audio_Msg_AM_IO_Switch( AM_IO_Name(am.io_type) );
3266}
3267
3268//*******************************************************************//
3269//* bt_mode: 1 for cordless mode, 2 for earphone mode *//
3270//* bt_sync_type: 0 for short sync, 1 for long sync *//
3271//* bt_sync_length: range from 1 to 8 *//
3272//*******************************************************************//
3273#if 0 // [FIXME] useless??
3274/* under construction !*/
3275/* under construction !*/
3276#endif
3277
3278void AM_BluetoothOn( uint8 bt_mode )
3279{
3280 ASSERT(bt_mode == 2); // expected earphone mode only
3281
3282 AM_Enqueue( AM_DSP_BluetoothOn, 0, 0, false );
3283
3284 AM_FlushQFunction();
3285}
3286
3287void AM_BluetoothOff( void )
3288{
3289 SP_DSPTone_ForceEnd();
3290
3291 AM_Enqueue( AM_DSP_BluetoothOff, 0, 0, false );
3292 AM_FlushQFunction();
3293}
3294
3295bool AM_IsBluetoothOn( void )
3296{
3297 return SAL_BT_IsEnable();
3298}
3299
3300bool AM_IsBTCordlessMode( void )
3301{
3302 return false;//( (*DP_AUDIO_PAR&0x1000)!=0 );
3303}
3304
3305
3306/* ========================================================================= */
3307
3308
3309void AM_SND_PlaybackOn( void )
3310{
3311 AM_Enqueue( AM_DSP_PCM8K_PlaybackOn, 1, 0, false );
3312
3313 AM_FlushQFunction();
3314}
3315
3316void AM_SND_PlaybackOff( bool wait )
3317{
3318
3319 AM_Enqueue( AM_DSP_PCM8K_PlaybackOff, 1, 0, false );
3320
3321 if( wait )
3322 AM_FlushQFunction();
3323}
3324// #endif // defined(BGSND_ENABLE) || defined(__SMART_PHONE_MODEM__)
3325
3326/* ========================================================================= */
3327/* PCM_EX control Functions */
3328/* ========================================================================= */
3329
3330void AM_DSP_PCM_EX_On(uint32 type, uint32 data)
3331{
3332 kal_bool flag;
3333 // uint8 voip_state = 0;
3334
3335 Sal_PCMEx_Config_t cfg;
3336 memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
3337
3338
3339 flag = true; //this flag is used to choose one among multiple options
3340 switch(type)
3341 {
3342 case AM_PCMEX_TYPE_DACA_DEDICATION: // 100: //DACA ACTIVE
3343 if(flag){
3344 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(3) , L1AUDIO_Str_onoff(1) );
3345 ASSERT(!(am.speech_state & SP_STATE_DACA));
3346 am.speech_state |= SP_STATE_DACA;
3347
3348 cfg.idle = false;
3349
3350 flag=false;
3351 }
3352 case AM_PCMEX_TYPE_DACA_IDLE_WO_ENH: //101: //DACA IDLE
3353 if(flag){
3354 ASSERT_REBOOT( !(am.state & AM_STATE_DACA) );
3355 ASSERT(am.state == 0);
3356 am.state |= AM_STATE_DACA;
3357
3358 cfg.idle = true;
3359
3360 flag=false;
3361 }
3362 cfg.swi = SAL_PCMEX_SWITCH_ON;
3363 cfg.type = SAL_PCMEX_TYPE_DACA;
3364 {
3365 _DACA_EX_T *dacaExData = (_DACA_EX_T *)data;
3366 kal_uint32 app_type = dacaExData->app_type;
3367 //cfg.band = (dacaExData->app_type & DACA_USE_NB) ? SAL_PCM_NARROWBAND : SAL_PCM_WIDEBAND;
3368 if(app_type & DACA_USE_NB){
3369 cfg.band = SAL_PCM_NARROWBAND;
3370 }else if(app_type & DACA_USE_WB){
3371 cfg.band = SAL_PCM_WIDEBAND;
3372 }else if(app_type & DACA_USE_SWB){
3373 cfg.band = SAL_PCM_SUPERWIDEBAND;
3374 }else if(app_type & DACA_USE_FB){
3375 cfg.band = SAL_PCM_FULLBAND;
3376 }else{
3377 ASSERT(0);
3378 }
3379 }
3380
3381 break;
3382 // ======================================================================
3383 case AM_PCMEX_TYPE_DEDICATION: // 0: //PCM4WAY CTM
3384 if(flag){
3385 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(2) , L1AUDIO_Str_onoff(1) );
3386 ASSERT(!(am.speech_state & SP_STATE_PCMNWAY));
3387
3388 am.speech_state |= SP_STATE_PCMNWAY;
3389
3390 cfg.idle = false;
3391
3392 flag=false;
3393 }
3394 /*
3395 case AM_PCMEX_TYPE_IDLE_WO_ENH: // 1: //PCM2WAY Voice
3396 if(flag){
3397 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3398 ASSERT(am.state == 0);
3399 am.state |= AM_STATE_VOICE;
3400
3401 cfg.idle = true;
3402
3403 flag = false;
3404 }
3405 */
3406 case AM_PCMEX_TYPE_IDLE: //2: PCM2WAY VoIP
3407 if(flag){
3408 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3409 ASSERT(am.state == 0);
3410 am.state |= AM_STATE_VOIP;
3411
3412 cfg.idle = true;
3413 flag = false;
3414 }
3415
3416 cfg.swi = SAL_PCMEX_SWITCH_ON;
3417 cfg.type = SAL_PCMEX_TYPE_PNW;
3418
3419 {
3420
3421 _PCMEX_T *pcmExData = (_PCMEX_T *)data;
3422
3423 cfg.D2M_ul1 = (0!=(pcmExData->cfgUL1 & USE_D2M_PATH));
3424 cfg.M2D_ul1 = (0!=(pcmExData->cfgUL1 & USE_M2D_PATH));
3425 cfg.afterEnh_ul1 = (0!=(pcmExData->cfgUL1 & DATA_SELECT_AFTER_ENH));
3426
3427 cfg.D2M_ul2 = (0!=(pcmExData->cfgUL2 & USE_D2M_PATH));
3428 cfg.M2D_ul2 = (0!=(pcmExData->cfgUL2 & USE_M2D_PATH));
3429 cfg.afterEnh_ul2 = (0!=(pcmExData->cfgUL2 & DATA_SELECT_AFTER_ENH));
3430
3431 cfg.D2M_ul3 = (0!=(pcmExData->cfgUL3 & USE_D2M_PATH));
3432 cfg.M2D_ul3 = (0!=(pcmExData->cfgUL3 & USE_M2D_PATH));
3433 cfg.afterEnh_ul3 = (0!=(pcmExData->cfgUL3 & DATA_SELECT_AFTER_ENH));
3434
3435 cfg.D2M_ul4 = (0!=(pcmExData->cfgUL4 & USE_D2M_PATH));
3436 cfg.M2D_ul4 = (0!=(pcmExData->cfgUL4 & USE_M2D_PATH));
3437 cfg.afterEnh_ul4 = (0!=(pcmExData->cfgUL4 & DATA_SELECT_AFTER_ENH));
3438
3439 cfg.D2M_dl = (0!=(pcmExData->cfgDL & USE_D2M_PATH));
3440 cfg.M2D_dl = (0!=(pcmExData->cfgDL & USE_M2D_PATH));
3441 cfg.afterEnh_dl = (0!=(pcmExData->cfgDL & DATA_SELECT_AFTER_ENH));
3442
3443
3444 if(cfg.idle){
3445 if(pcmExData->bandInfo == PCMEX_BAND_WB){
3446 cfg.band = SAL_PCM_WIDEBAND;
3447 }else if (pcmExData->bandInfo == PCMEX_BAND_NB){
3448 cfg.band = SAL_PCM_NARROWBAND;
3449 }else if (pcmExData->bandInfo == PCMEX_BAND_SWB){
3450 cfg.band = SAL_PCM_SUPERWIDEBAND;
3451 }else if (pcmExData->bandInfo == PCMEX_BAND_FB){
3452 cfg.band = SAL_PCM_FULLBAND;
3453 }else{ // should never been here
3454 ASSERT(0);
3455 }
3456 } else {
3457 cfg.band = SAL_PCM_DYNAMIC;
3458 }
3459
3460 }
3461
3462 break;
3463 default:
3464 ASSERT(0); break;
3465 }
3466
3467 if(cfg.idle == true){
3468 SAL_Get_Delay(SAL_DEALY_PCM8K_PB_VOIP, SAL_DELAY_NA, SAL_DELAY_NA, &cfg.delR, &cfg.delW, &cfg.delM);
3469 AFE_TurnOn8K();
3470 }
3471
3472 SAL_PcmEx_Config(&cfg);
3473}
3474
3475
3476void AM_DSP_PCM_EX_Off(uint32 type, uint32 data)
3477{
3478 kal_bool flag;
3479 // uint8 voip_state = 0;
3480
3481 Sal_PCMEx_Config_t cfg;
3482 memset(&cfg, 0, sizeof(Sal_PCMEx_Config_t));
3483
3484 flag = true; //this flag is used to choose one among multiple options
3485 switch(type)
3486 {
3487 case AM_PCMEX_TYPE_DACA_DEDICATION: //100: DACA ACTIVE
3488 if(flag ){
3489 am.speech_state &= ~SP_STATE_DACA;
3490 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(3) , L1AUDIO_Str_onoff(0) );
3491
3492 cfg.idle = false;
3493
3494 flag = false;
3495 }
3496 case AM_PCMEX_TYPE_DACA_IDLE_WO_ENH: //101: DACA IDLE
3497 if(flag ){
3498 am.state &= ~AM_STATE_DACA;
3499 ASSERT(am.state == 0);
3500
3501 cfg.idle = true;
3502
3503 flag =false;
3504 }
3505
3506 cfg.swi = SAL_PCMEX_SWITCH_OFF;
3507 cfg.type = SAL_PCMEX_TYPE_DACA;
3508
3509 break;
3510 // ======================================================================
3511 case AM_PCMEX_TYPE_DEDICATION: //PCM4WAY CTM
3512 if(flag ){
3513 am.speech_state &= ~SP_STATE_PCMNWAY;
3514 MD_TRC_L1Audio_Msg_AM_SetSpeech( AM_Speech_Feature_Name(2) , L1AUDIO_Str_onoff(0) );
3515
3516 cfg.idle = false;
3517
3518 flag = false;
3519 }
3520 /*
3521 case AM_PCMEX_TYPE_IDLE_WO_ENH: //PCM2WAY Voice
3522 if(flag ){
3523 am.state &= ~AM_STATE_VOICE;
3524 ASSERT(am.state == 0);
3525
3526 cfg.idle = true;
3527
3528 flag = false;
3529 }
3530 */
3531 case AM_PCMEX_TYPE_IDLE: //PCM2WAY VoIP
3532 if(flag ){
3533 am.state &= ~AM_STATE_VOIP;
3534 ASSERT(am.state == 0);
3535
3536 cfg.idle = true;
3537
3538 flag = false;
3539 }
3540
3541 cfg.swi = SAL_PCMEX_SWITCH_OFF;
3542 cfg.type = SAL_PCMEX_TYPE_PNW;
3543
3544 break;
3545 default:
3546 ASSERT(0);
3547 break;
3548 }
3549
3550 if(cfg.idle == true){
3551 cc_set_VBI_for_FSM(1);
3552 SAL_PcmEx_Config(&cfg);
3553 cc_set_VBI_for_FSM(2);
3554 AFE_TurnOff8K();
3555 } else {
3556 SAL_PcmEx_Config(&cfg);
3557 }
3558}
3559
3560/**
3561 @type: AM_PCMEX_TYPE, indicate the PCM EX type
3562 @p2exData: Addess of "glable variable" like pcmEx, dacaEx
3563*/
3564void AM_PCM_EX_On( AM_PCMEX_TYPE type, uint32 p2exData)
3565{
3566 // kal_uint8 aud_func;
3567 if(type == AM_PCMEX_TYPE_IDLE
3568#if 0
3569/* under construction !*/
3570/* under construction !*/
3571#endif
3572 || type == AM_PCMEX_TYPE_DACA_IDLE )
3573 {
3574
3575
3576 // aud_func = L1SP_SPEECH;
3577 }
3578/*
3579 else
3580 {
3581 // aud_func = L1SP_VOICE;
3582 }
3583*/
3584
3585
3586 AM_Enqueue( AM_DSP_PCM_EX_On, type, p2exData, false );
3587
3588 AM_FlushQFunction();
3589}
3590
3591
3592void AM_PCM_EX_Off( AM_PCMEX_TYPE type, uint32 p2exData)
3593{
3594/*
3595 // find out the aud_func
3596 kal_uint8 aud_func = L1SP_MAX_AUDIO;
3597
3598 if( type == AM_PCMEX_TYPE_IDLE
3599#if 0
3600 || type == AM_PCMEX_TYPE_REC_ONLY_CAL
3601 || type == AM_PCMEX_TYPE_REC_PLAY_CAL
3602#endif
3603 || type == AM_PCMEX_TYPE_DACA_IDLE ) {
3604 aud_func = L1SP_SPEECH;
3605 } else {
3606 aud_func = L1SP_VOICE;
3607 }
3608*/
3609
3610 AM_Enqueue(AM_DSP_PCM_EX_Off, type, p2exData, false );
3611 AM_FlushQFunction();
3612}
3613
3614bool AM_IsVoIPOn( void )
3615{
3616 return( (bool)((am.state & AM_STATE_VOIP) != 0) );
3617}
3618
3619/* ========================================================================= */
3620
3621uint16 AM_Status( void )
3622{
3623 return am.state;
3624}
3625
3626/* phase out. lagency
3627void AM_EnableToneLoopBackFlag( kal_bool param )
3628{
3629 if(param)
3630 am.toneLoopbackRec = KAL_TRUE;
3631 else
3632 am.toneLoopbackRec = KAL_FALSE;
3633}
3634*/
3635/* ========================================================================= */
3636/* Functions for DSP PCM Router */
3637/* ========================================================================= */
3638#define PCM_ROUTER_DELAY_READ 0
3639#define PCM_ROUTER_DELAY_WRITE 0xF0
3640#define PCM_ROUTER_DELAY_DL 0x38
3641#define PCM_ROUTER_DELAY_UL 0x118
3642
3643void AM_DSP_PcmRouter_On( uint32 voiceMode, uint32 extraInfo )
3644{
3645
3646 Sal_PCM_Router_t pcmrt;
3647
3648 ASSERT_REBOOT( !(am.state & AM_CONFLICT_STATE) );
3649 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(11), L1AUDIO_Str_onoff(1) );
3650
3651 // setting
3652 memset(&pcmrt, 0 , sizeof(Sal_PCM_Router_t));
3653
3654 pcmrt.cod_band = 0; //voiceMode;
3655 pcmrt.dev_band = voiceMode;
3656 pcmrt.delR = PCM_ROUTER_DELAY_READ;
3657 pcmrt.delW = PCM_ROUTER_DELAY_WRITE;
3658 pcmrt.delM_DL = PCM_ROUTER_DELAY_DL;
3659 pcmrt.delM_UL = PCM_ROUTER_DELAY_UL;
3660
3661 // turn on 8k
3662 AFE_TurnOn8K();
3663
3664 SAL_PCM_Router_Open(&pcmrt, ((extraInfo&1)? SAL_SRST_TYPE_DEV: SAL_SRST_TYPE_CALLON));
3665
3666 am.state |= AM_STATE_VOIP;
3667}
3668
3669
3670/**
3671 @extraInfo: bit[0]: 1 for device change to resync
3672*/
3673void AM_PcmRouter_On(uint32 extraInfo)
3674{
3675 kal_uint8 voiceMode;
3676
3677 // the following chips did not provide the function
3678
3679 voiceMode = AFE_GetVoice8KMode();
3680
3681 AM_Enqueue( AM_DSP_PcmRouter_On, voiceMode, extraInfo, false );
3682
3683 AM_FlushQFunction();
3684
3685}
3686
3687void AM_DSP_PcmRouter_Off( uint32 info, uint32 extraInfo )
3688{
3689 MD_TRC_L1Audio_Msg_AM_Switch( AM_Switch_Name(11), L1AUDIO_Str_onoff(0) );
3690
3691 SAL_PCM_Router_Close(true);
3692
3693 AFE_TurnOff8K();
3694
3695 am.state &= (~AM_STATE_VOIP);
3696}
3697
3698
3699void AM_PcmRouter_Off(void)
3700{
3701
3702 AM_Enqueue( AM_DSP_PcmRouter_Off, 0, 0, false );
3703
3704 AM_FlushQFunction();
3705}
3706
3707#if 0
3708/* under construction !*/
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#endif
3730
3731#if 0
3732/* under construction !*/
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#endif
3773
3774bool AM_IsConflictState( void )
3775{
3776 if( am.state & AM_CONFLICT_STATE )
3777 return true;
3778 else
3779 return false;
3780}
3781
3782
3783kal_uint32 AM_Get2GResyncThreshold(void)
3784{
3785 return AM_2G_RESYNC_THRESHOLD;
3786}
3787
3788//=============================================================================
3789// sw digital gain related
3790//=============================================================================
3791
3792void AM_DSP_SetSpeechDigitalGain(kal_uint16 digitalVol)
3793{
3794 am.speechDigitalGain = digitalVol;
3795 SAL_DGain_Set_DL(digitalVol);
3796
3797 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(1), digitalVol);
3798}
3799
3800kal_uint16 AM_DSP_GetSpeechDigitalGain(void)
3801{
3802 return SAL_DGain_Get_DL();
3803}
3804
3805
3806void AM_DSP_SetSpeechUplinkSwAgcGain(kal_uint16 digitalVol)
3807{
3808 am.speechUplinkSwAgcGain = digitalVol;
3809 SAL_AGC_SetGain(digitalVol);
3810
3811 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(3), digitalVol);
3812}
3813
3814kal_uint16 AM_GetSpeechEnhRefDigitalGain(void)
3815{
3816 return am.speechDlEnhRefDigtalGain;
3817}
3818
3819void AM_DSP_SetSpeechEnhRefDigitalGain(kal_uint16 digitalVol)
3820{
3821 am.speechDlEnhRefDigtalGain = digitalVol;
3822 SAL_ENH_Gain_Set_DL(digitalVol);
3823
3824 MD_TRC_L1Audio_Msg_AM_DSP_GAIN(AM_Gain_Name(4), digitalVol);
3825}
3826