blob: 74048950e7cf9de6a7c26ecd5a26ce5fc7383383 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001
2#include "kal_public_api.h"
3#include "kal_general_types.h"
4
5#include "kal_trace.h"
6#include "l1sp_trc.h"
7#include "l1audio_trace_utmd.h"
8#include "l1audio_sph_trc.h"
9#include "event_info_utility.h" // for MODEM_WARNING_MESSAGE
10
11#include "l1audio.h"
12#include "l1aud_common_def.h"
13#include "am.h"
14#include "sp_drv.h"
15#include "vm.h"
16#include "sp_enhance.h"
17#include "sal_def.h"
18#include "sal_exp.h"
19
20#include "afe.h"
21#if defined(__CVSD_CODEC_SUPPORT__)
22#include "bt_sco_drv.h"
23#endif
24
25typedef struct {
26 bool isEnable;
27 bool isVocOn;
28
29 uint16 aud_id;
30
31
32} PCM_ROUTER_T;
33
34
35static PCM_ROUTER_T g_PcmRouter;
36
37// ============================================================================
38
39void PcmRouterStart(void)
40{
41
42 kal_uint32 module_id = MOD_L1AUDIO_SPH_SRV;
43 kal_uint32 voc_ptn = TVCI_CREATE_FILE;
44
45 //call cpd and lock sleep mode
46 g_PcmRouter.aud_id = L1Audio_GetAudioID();
47 L1Audio_SetFlag( g_PcmRouter.aud_id );
48
49 // force unmute to decople PS module
50 // turn on
51 AM_PcmRouter_On(0);
52
53 // voc
54 if(!tst_trace_check_ps_filter_off(TRACE_GROUP_VM, &module_id, 0x2))
55 {
56 tst_vc_response(TVCI_VM_LOGGING, (const kal_uint8*)&voc_ptn, 4);
57 VMREC_Start(NULL, true);
58 g_PcmRouter.isVocOn = true;
59 }
60
61 // turn on speech enhancement
62 SetSpeechEnhancement( true );
63
64 //always unmute DSP uplink when speech on (This is to keep the mute definition)
65 // SP_MuteUlFromDiffPos(false, SP_MIC_MUTE_POS_FROM_ALL);
66 // L1SP_MuteSpeaker(false);
67
68#if 0 // defined(__ECALL_SUPPORT__)
69/* under construction !*/
70/* under construction !*/
71#endif
72
73#if defined(__CVSD_CODEC_SUPPORT__)
74 if(SP_GetDevInfo() == SPH_DEVINFO_BT_CVSD_MSBC
75 || SP_GetDevInfo() == SPH_DEVINFO_BT_CVSD
76 || SP_GetDevInfo() == SPH_DEVINFO_BT_MSBC)
77 {
78 kal_uint8 voice8kMode = SP_GetDevSamplingRate();
79
80 if( (voice8kMode==0) || (voice8kMode==1) ) {
81 BT_SCO_SPEECH_ON(voice8kMode==1);
82 } else {
83 MODEM_WARNING_MESSAGE((voice8kMode==0), "PcmRouterStart(bt): incorrect Voice8kMode, %d", voice8kMode);
84 MODEM_WARNING_MESSAGE((voice8kMode==1), "PcmRouterStart(bt): incorrect Voice8kMode, %d", voice8kMode);
85 }
86
87 }
88#endif
89
90 g_PcmRouter.isEnable = true;
91}
92
93void PcmRouterStop(void)
94{
95 kal_uint32 voc_ptn = TVCI_CLOSE_FILE;
96
97 // due to AP will close DL directly before speech off, so md can mute dl directly without ramping
98 // This will prevent sound pushes to hardware buffer then cause noise
99 SAL_Mute_Ctrl(SAL_MUTE_DL_8K, KAL_TRUE); // to replace L1SP_MuteSpeaker(true);
100
101
102#if defined(__CVSD_CODEC_SUPPORT__)
103 if(BT_SCO_IS_SPEECH_ON())
104 {
105 BT_SCO_SPEECH_OFF();
106 }
107#endif
108
109#if 0 // defined(__ECALL_SUPPORT__)
110/* under construction !*/
111/* under construction !*/
112#endif
113
114
115 SetSpeechEnhancement( false );
116
117 // voc
118 if(g_PcmRouter.isVocOn)
119 {
120 tst_vc_response(TVCI_VM_LOGGING, (const kal_uint8*)(&voc_ptn), 4);
121 VMREC_Stop(true);
122 g_PcmRouter.isVocOn = false;
123 }
124
125 // turn off
126 AM_PcmRouter_Off();
127
128 SAL_Mute_Ctrl(SAL_MUTE_DL_8K, KAL_FALSE);
129 //always unmute DSP uplink after speech off to keep the mute definition
130 SP_MuteUlFromDiffPos(false, SP_MIC_MUTE_POS_FROM_ALL);
131 L1SP_MuteSpeaker(false);
132
133 // leave the mute control to PS module
134
135 //unlock sleep mode and release CPD
136 L1Audio_ClearFlag( g_PcmRouter.aud_id );
137 L1Audio_FreeAudioID( g_PcmRouter.aud_id );
138 g_PcmRouter.aud_id = 0xffff;
139
140 g_PcmRouter.isEnable = false;
141}