1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95
96 //-------------------------------------------------------------------------------------------------
97 // Include Files
98 //-------------------------------------------------------------------------------------------------
99 // Common Definition
100 #include "MsCommon.h"
101 #include "MsIRQ.h"
102 #include "MsOS.h"
103 #include "regCHIP.h"
104 #include "drvAUDIO_if.h"
105 #include "drvAUDIO.h"
106 #include "halAUDIO.h"
107
108 // Internal Definition
109 #include "halSOUND.h"
110 #include "regAUDIO.h"
111 #include "halMAD2.h"
112
113 #include "audio_mbox2.h"
114 #include "audio_comm2.h"
115
116 #if (defined ANDROID)
117
118 #include <sys/mman.h>
119 #include <cutils/ashmem.h>
120 #include <cutils/log.h>
121
122 #ifndef LOGI // android 4.1 rename LOGx to ALOGx
123 #define LOGI ALOGI
124 #endif
125
126 #ifndef LOGE // android 4.1 rename LOGx to ALOGx
127 #define LOGE ALOGE
128 #endif
129
130 #if(OMX_AUDIO_DEBUG)
131 #define HALSOUND_PRINT(fmt, args...) LOGI("<<android>> " fmt, ## args)
132 #else
133 #define HALSOUND_PRINT(fmt, args...)
134 #endif
135
136 #define HALSOUND_ERROR(fmt, args...) LOGE("<<android>> " fmt, ## args)
137
138 #else
139 #ifdef CONFIG_MBOOT //mboot Speed up
140 #define HALSOUND_PRINT(fmt, args...)
141 #define HALSOUND_ERROR(fmt, args...) printf("[[utopia]] " fmt, ## args)
142 #else
143 #define HALSOUND_PRINT(fmt, args...) printf("[[utopia]] " fmt, ## args)
144 #define HALSOUND_ERROR(fmt, args...) printf("[[utopia]] " fmt, ## args)
145 #endif
146 #endif
147
148
149 //-------------------------------------------------------------------------------------------------
150 // Driver Compiler Options
151 //-------------------------------------------------------------------------------------------------
152 #define DBG_SOUND(msg) //msg
153 #define MAX_PEQ_BAND 8
154 //-------------------------------------------------------------------------------------------------
155 // Local Defines
156 //-------------------------------------------------------------------------------------------------
157
158
159 //-------------------------------------------------------------------------------------------------
160 // Local Structures
161 //-------------------------------------------------------------------------------------------------
162
163
164 //-------------------------------------------------------------------------------------------------
165 // Global Variables
166 //-------------------------------------------------------------------------------------------------
167 extern MS_U16 g_BalanceMask;
168 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
169 //-------------------------------------------------------------------------------------------------
170 // Local Variables
171 //-------------------------------------------------------------------------------------------------
172 static MS_U32 peq_band_enable = 0xFFFFFFFF;
173 static MS_U32 peq_band_precision = 0x00000000;
174
175 const MS_U32 AVC_SOffset_TBL[13]=
176 {
177 0x200000, // Offset +0 dB, 3.21 format for DSP
178 0x23E793, // +1 dB
179 0x28491D, // +2 dB
180 0x2D3381, // +3 dB
181 0x32B771, // +4 dB
182 0x38E7AA, // +5 dB
183 0x3FD930, // +6 dB
184 0x47A39A, // +7 dB
185 0x50615F, // +8 dB
186 0x5A3031, // +9 dB
187 0x653160, // +10 dB
188 0x718A50, // +11 dB
189 0x7F64F0, // +12 dB
190 };
191 //-------------------------------------------------------------------------------------------------
192 // Debug Functions
193 //-------------------------------------------------------------------------------------------------
194
195
196 //-------------------------------------------------------------------------------------------------
197 // Local Functions
198 //-------------------------------------------------------------------------------------------------
199
200
201 //-------------------------------------------------------------------------------------------------
202 // Global Functions
203 //-------------------------------------------------------------------------------------------------
204
205 ////////////////////////////////////////////////////////////////////////////////
206 /// @brief \b Function \b Name: HAL_SOUND_Init() @@VVV
207 /// @brief \b Function \b Description: This routine is the initialization for Audio sound effect module.
208 /// @param <IN> \b InitTbl : Sound effect initial table
209 /// @param <OUT> \b NONE :
210 /// @param <RET> \b NONE :
211 /// @param <GLOBAL> \b NONE :
212 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_Init(void)213 void HAL_SOUND_Init(void)
214 {
215 // Toggle to initialize DAC DATA SRAM.
216 HAL_AUDIO_SeWriteMaskByte(0x2B40,0x02,0x02);
217 AUDIO_DELAY1US(1000);
218 HAL_AUDIO_SeWriteMaskByte(0x2B40,0x02,0x00);
219
220 //reset DSP
221 HAL_AUDIO_WriteByte( REG_SE_IDMA_CTRL0, 0x02);
222 AUDIO_DELAY1US(2000);
223 HAL_AUDIO_WriteByte( REG_SE_IDMA_CTRL0, 0x03);
224
225 }
226
227 ////////////////////////////////////////////////////////////////////////////////
228 /// @brief \b Function \b Name: HAL_SOUND_Init2
229 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_Init2(void)230 void HAL_SOUND_Init2(void)
231 {
232
233 HAL_SOUND_Init();
234 HAL_AUDSP_DspLoadCode(AU_DVB2_NONE);
235 //HAL_AUDSP_DspLoadCode(AU_SND_EFFECT);
236 HAL_AUDIO_SeSystemLoadCode(); // Do nothing in single DSP chip
237 }
238
239 ////////////////////////////////////////////////////////////////////////////////
240 /// @brief \b Function \b Name: HAL_SOUND_SetMute() @@VVV
241 /// @brief \b Function \b Description: This routine is used to set audio u8Path S/W mute.
242 /// @param <IN> \b u8Path : for audio u8Path0 ~ u8Path6
243 /// @param <IN> \b bEnable : TRUE --Mute
244 /// FALSE--Unmute
245 /// @param <OUT> \b NONE :
246 /// @param <RET> \b NONE :
247 /// @param <GLOBAL> \b NONE :
248 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMute(MS_U8 u8Path,MS_BOOL bEnable)249 void HAL_SOUND_SetMute(MS_U8 u8Path, MS_BOOL bEnable)
250 {
251 DBG_SOUND(printf("HAL_SOUND_SetMute = %x\n", (MS_U8)bEnable ));
252
253 switch(u8Path)
254 {
255 case AUDIO_PATH_SW_DMA_0:
256 case AUDIO_PATH_SW_DMA_1:
257 {
258 if(bEnable == TRUE)
259 {
260 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SW_DMA_READER_DDR_Ctrl, 0x8000, 0x8000); // bit 15
261 }
262 else
263 {
264 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SW_DMA_READER_DDR_Ctrl, 0x8000, 0x0000);
265 }
266 }
267 break;
268
269 case AUDIO_PATH_HW_DMA_0:
270 case AUDIO_PATH_HW_DMA_1:
271 {
272 if(bEnable)
273 {
274 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0x02, 0x02);
275 }
276 else
277 {
278 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0x02, 0x00);
279 }
280 }
281 break;
282
283 case AUDIO_T3_PATH_AUOUT0:
284 if(bEnable) // Mute
285 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x80, 0x80);
286 else // UnMute
287 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x80, 0x00);
288 break;
289
290 case AUDIO_T3_PATH_AUOUT1:
291 if(bEnable)
292 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x80, 0x80 );
293 else
294 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x80, 0x00 );
295 break;
296
297 case AUDIO_T3_PATH_AUOUT2:
298 if(bEnable)
299 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x80, 0x80);
300 else
301 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x80, 0x00);
302 break;
303
304 case AUDIO_T3_PATH_AUOUT3:
305 if(bEnable)
306 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x80, 0x80);
307 else
308 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x80, 0x00);
309 break;
310
311 case AUDIO_T3_PATH_I2S:
312 if(bEnable)
313 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x80, 0x80);
314 else
315 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x80, 0x00);
316 break;
317
318 case AUDIO_T3_PATH_SPDIF:
319 _HAL_AUDIO_SPDIF_SetMute(bEnable);
320 break;
321
322 case AUDIO_T3_PATH_MIXER_MAIN:
323 {
324 MS_U32 u32Value;
325
326 /* TODO
327 * It's a patch here
328 * also control multi channel volume
329 */
330 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
331
332 if(bEnable)
333 {
334 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x80, 0x80);
335
336 u32Value = u32Value | 0x008000;
337 }
338 else
339 {
340 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x80, 0x00);
341
342 u32Value = u32Value & 0xFF7FFF;
343 }
344
345 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
346
347 break;
348 }
349
350 case AUDIO_T3_PATH_MIXER_SECONDARY:
351 if(bEnable)
352 {
353 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x80, 0x80);
354 }
355 else
356 {
357 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x80, 0x00);
358 }
359 break;
360
361 case AUDIO_T3_PATH_MIXER_DMA_IN:
362 if(bEnable)
363 {
364 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x80, 0x80);
365 }
366 else
367 {
368 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x80, 0x00);
369 }
370 break;
371
372 case AUDIO_PATH_7:
373 if(bEnable)
374 {
375 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x80, 0x80);
376 }
377 else
378 {
379 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x80, 0x00);
380 }
381 break;
382
383 case AUDIO_T3_PATH_PCM_CAPTURE1:
384 {
385 MS_U32 u32Value;
386
387 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture_volume, DSP_MEM_TYPE_DM);
388
389 if(bEnable)
390 {
391 u32Value = u32Value | 0x008000;
392 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
393 }
394 else
395 {
396 u32Value = u32Value & 0xFF7FFF;
397 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
398 }
399
400 break;
401 }
402
403 case AUDIO_T3_PATH_DMA_WRITER1:
404 {
405 MS_U32 u32Value;
406
407 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_dmaWriter1_volume, DSP_MEM_TYPE_DM);
408
409 if(bEnable)
410 {
411 u32Value = u32Value | 0x008000;
412 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
413 }
414 else
415 {
416 u32Value = u32Value & 0xFF7FFF;
417 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
418 }
419
420 break;
421 }
422
423 case AUDIO_T3_PATH_PCM_CAPTURE2:
424 {
425 MS_U32 u32Value;
426
427 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture2_volume, DSP_MEM_TYPE_DM);
428
429 if(bEnable)
430 {
431 u32Value = u32Value | 0x008000;
432 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
433 }
434 else
435 {
436 u32Value = u32Value & 0xFF7FFF;
437 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
438 }
439
440 break;
441 }
442
443 case AUDIO_T3_PATH_MIXER_MCH_IN: //Multi-Ch 1~3
444 {
445 MS_U32 u32Value;
446
447 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
448
449 if(bEnable)
450 {
451 u32Value = u32Value | 0x008000;
452 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
453 }
454 else
455 {
456 u32Value = u32Value & 0xFF7FFF;
457 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
458 }
459
460 break;
461 }
462
463 default:
464 break;
465 }
466 }
467
468 ////////////////////////////////////////////////////////////////////////////////
469 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteVolume() @@VVV
470 /// @brief \b Function \b Description: This routine is used to set the absolute volume of audio u8Path.
471 /// @param <IN> \b u8Path : for audio CH1~CH6
472 /// @param <IN> \b u8u8Vol1 : MSB 7-bit register u8Value of 10-bit volume
473 /// range from 0x00 to 0x7E , gain: +12db to -114db (-1 db per step)
474 /// @param <IN> \b u8u8Vol2 : LSB 3-bit register u8Value of 10-bit volume
475 /// range from 0x00 to 0x07 , gain: -0db to -0.875db (-0.125 db per step)
476 /// @param <OUT> \b NONE :
477 /// @param <RET> \b NONE :
478 /// @param <GLOBAL> \b NONE :
479 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteVolume(MS_U8 u8Path,MS_U8 u8u8Vol1,MS_U8 u8u8Vol2)480 void HAL_SOUND_AbsoluteVolume(MS_U8 u8Path, MS_U8 u8u8Vol1, MS_U8 u8u8Vol2)
481 {
482 switch(u8Path)
483 {
484 case AUDIO_T3_PATH_AUOUT0:
485 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x7F, u8u8Vol1);
486 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
487 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x01, 0x01); // bEnable DSP CH1 sound effect
488 break;
489
490 case AUDIO_T3_PATH_AUOUT1:
491 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x7F, u8u8Vol1);
492 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
493 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x02, 0x02); // bEnable DSP CH2 sound effect
494 break;
495
496 case AUDIO_T3_PATH_AUOUT2:
497 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x7F, u8u8Vol1);
498 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
499 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x04, 0x04); // bEnable DSP CH3 sound effect
500 break;
501 case AUDIO_T3_PATH_AUOUT3:
502 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x7F, u8u8Vol1);
503 HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
504 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x08, 0x08); // bEnable DSP CH4 sound effect
505 break;
506
507 case AUDIO_T3_PATH_I2S:
508 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x7F, u8u8Vol1);
509 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
510 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x10, 0x10); // bEnable DSP CH5 sound effect
511 break;
512
513 case AUDIO_T3_PATH_SPDIF:
514 HAL_AUDIO_WriteMaskByte(REG_SOUND_SPDIF_VOLUME, 0x7F, u8u8Vol1);
515 HAL_AUDIO_WriteMaskByte(REG_SOUND_SPDIF_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
516 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x20, 0x20); // bEnable DSP CH6 sound effect
517
518 break;
519
520 case AUDIO_T3_PATH_I2S2:
521 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S2_VOLUME, 0x7F, u8u8Vol1);
522 HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S2_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
523 HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x20, 0x20); // bEnable AUDIO_T3_PATH_I2S2
524 break;
525
526 case AUDIO_T3_PATH_MIXER_MAIN: //CH5
527 {
528 MS_U32 u32Value;
529 MS_U32 u32Muteflag;
530
531 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x7F, u8u8Vol1);
532 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
533
534 /* TODO
535 * It's a patch here
536 * also control multi channel volume
537 */
538 u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
539
540 u8u8Vol1 = u8u8Vol1 & 0x7F;
541 u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
542 u32Value = ((MS_U32)u8u8Vol1)<<8;
543 u32Value = u32Value + (MS_U32)u8u8Vol2;
544 u32Value = u32Value | (u32Muteflag & 0x008000);
545 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
546
547 break;
548 }
549
550 case AUDIO_T3_PATH_MIXER_SECONDARY: //CH6
551 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x7F, u8u8Vol1);
552 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
553 break;
554
555 case AUDIO_T3_PATH_MIXER_DMA_IN: //CH8
556 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x7F, u8u8Vol1);
557 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
558 break;
559
560 case AUDIO_PATH_7: //CH7
561 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x7F, u8u8Vol1);
562 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
563 break;
564
565 case AUDIO_T3_PATH_PCM_CAPTURE1:
566 {
567 MS_U32 u32Value;
568 MS_U32 u32Muteflag;
569 u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture_volume, DSP_MEM_TYPE_DM);
570
571 u8u8Vol1 = u8u8Vol1 & 0x7F;
572 u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
573 u32Value = ((MS_U32)u8u8Vol1)<<8;
574 u32Value = u32Value + (MS_U32)u8u8Vol2;
575 u32Value = u32Value | (u32Muteflag & 0x008000);
576 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
577
578 break;
579 }
580
581 case AUDIO_T3_PATH_PCM_CAPTURE2:
582 {
583 MS_U32 u32Value;
584 MS_U32 u32Muteflag;
585 u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture2_volume, DSP_MEM_TYPE_DM);
586
587 u8u8Vol1 = u8u8Vol1 & 0x7F;
588 u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
589 u32Value = ((MS_U32)u8u8Vol1)<<8;
590 u32Value = u32Value + (MS_U32)u8u8Vol2;
591 u32Value = u32Value | (u32Muteflag & 0x008000);
592 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
593
594 break;
595 }
596
597 case AUDIO_T3_PATH_DMA_WRITER1:
598 {
599 MS_U32 u32Value;
600 MS_U32 u32Muteflag;
601 u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_dmaWriter1_volume, DSP_MEM_TYPE_DM);
602
603 u8u8Vol1 = u8u8Vol1 & 0x7F;
604 u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
605 u32Value = ((MS_U32)u8u8Vol1)<<8;
606 u32Value = u32Value + (MS_U32)u8u8Vol2;
607 u32Value = u32Value | (u32Muteflag & 0x008000);
608 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
609
610 break;
611 }
612
613 case AUDIO_T3_PATH_MIXER_MCH_IN: //Multi-Ch 1~3
614 {
615 MS_U32 u32Value;
616 MS_U32 u32Muteflag;
617 u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
618
619 u8u8Vol1 = u8u8Vol1 & 0x7F;
620 u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
621 u32Value = ((MS_U32)u8u8Vol1)<<8;
622 u32Value = u32Value + (MS_U32)u8u8Vol2;
623 u32Value = u32Value | (u32Muteflag & 0x008000);
624 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
625 break;
626 }
627
628 default:
629 break;
630 }
631
632 }
633
634 ////////////////////////////////////////////////////////////////////////////////
635 /// @brief \b Function \b Name: HAL_SOUND_SetPreScale() @@VVV
636 /// @brief \b Function \b Description: This routine is used to set the u8Prescale of audio u8Path.
637 /// @param <IN> \b u8Path : for audio u8Path0 ~ u8Path5
638 /// @param <IN> \b u8Prescale : range from 0x01 to 0xFF , gain: -13.75db to +18db (0.125 db per step)
639 /// 0x00: disable pre-scale
640 /// 0x6F: gain = 0db
641 /// 0xFF: gain = +18db
642 /// @param <OUT> \b NONE :
643 /// @param <RET> \b NONE :
644 /// @param <GLOBAL> \b NONE :
645 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetPreScale(MS_U8 u8Path,MS_U8 u8Prescale)646 void HAL_SOUND_SetPreScale(MS_U8 u8Path, MS_U8 u8Prescale)
647 {
648 switch(u8Path)
649 {
650 case AUDIO_PATH_MAIN:
651 HAL_AUDIO_WriteByte(REG_SOUND_MAIN_PERSCALE, u8Prescale);
652 break;
653
654 default:
655 HAL_AUDIO_WriteByte(REG_SOUND_MAIN_PERSCALE, u8Prescale);
656 break;
657 }
658 }
659
660 ////////////////////////////////////////////////////////////////////////////////
661 /// @brief \b Function \b Name: HAL_SOUND_GetPreScale()
662 /// @brief \b Function \b Description: This routine is used to set the u8Prescale of audio u8Path.
663 /// @param <IN> \b u8Path : for audio u8Path0 ~ u8Path5
664 /// @param <IN> \b u8Prescale : range from 0x01 to 0xFF , gain: -13.75db to +18db (0.125 db per step)
665 /// 0x00: disable pre-scale
666 /// 0x6F: gain = 0db
667 /// 0xFF: gain = +18db
668 /// @param <OUT> \b NONE :
669 /// @param <RET> \b NONE :
670 /// @param <GLOBAL> \b NONE :
671 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetPreScale(MS_U8 u8Path)672 MS_U16 HAL_SOUND_GetPreScale(MS_U8 u8Path)
673 {
674 MS_U16 tmp=0;
675 switch ( u8Path )
676 {
677 case AUDIO_PATH_MAIN:
678 tmp = HAL_AUDIO_ReadByte(REG_SOUND_MAIN_PERSCALE);
679 break;
680
681 default:
682 tmp = HAL_AUDIO_ReadByte(REG_SOUND_MAIN_PERSCALE);
683 break;
684 }
685 return tmp;
686 }
687
688 ////////////////////////////////////////////////////////////////////////////////
689 /// @brief \b Function \b Name: HAL_SOUND_SetOutputPhaseShiftMask() @@VVV
690 /// @brief \b Function \b Description: This routine is used to Set Output Signal Phase Shift Mask. ( 0 degree normal or 180 degree inverse)
691 /// @param <IN> \b u8Path : AUDIO_PATH_TYPE
692 /// @param <IN> \b u8Channel : 0 for Left channel; 1 for Right channel
693 /// @param <OUT> \b NONE :
694 /// @param <RET> \b NONE :
695 /// @param <GLOBAL> \b NONE :
696 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetOutputPhaseShiftMask(AUDIO_OUTPUT_TYPE u8Output,MS_U8 u8Channel)697 void HAL_SOUND_SetOutputPhaseShiftMask(AUDIO_OUTPUT_TYPE u8Output, MS_U8 u8Channel)
698 {
699 MS_U16 PhaseShiftMaskBit = 0;
700 MS_BOOL ctrl_flag = TRUE;
701
702 switch(u8Output)
703 {
704 case AUDIO_AUOUT0_OUTPUT:
705 if (u8Channel)
706 {
707 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC0_R_BIT;
708 }
709 else
710 {
711 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC0_L_BIT;
712 }
713 break;
714
715 case AUDIO_AUOUT1_OUTPUT:
716 case AUDIO_HP_OUTPUT:
717 if (u8Channel)
718 {
719 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC1_R_BIT;
720 }
721 else
722 {
723 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC1_L_BIT;
724 }
725 break;
726
727 case AUDIO_AUOUT2_OUTPUT:
728 if (u8Channel)
729 {
730 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC2_R_BIT;
731 }
732 else
733 {
734 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC2_L_BIT;
735 }
736 break;
737
738 case AUDIO_AUOUT3_OUTPUT:
739 if (u8Channel)
740 {
741 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC3_R_BIT;
742 }
743 else
744 {
745 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC3_L_BIT;
746 }
747 break;
748
749 case AUDIO_I2S_OUTPUT:
750 if (u8Channel)
751 {
752 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S0_R_BIT;
753 }
754 else
755 {
756 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S0_L_BIT;
757 }
758 break;
759
760 case AUDIO_I2S2_OUTPUT:
761 if (u8Channel)
762 {
763 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S1_R_BIT;
764 }
765 else
766 {
767 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S1_L_BIT;
768 }
769 break;
770
771 case AUDIO_I2S3_OUTPUT:
772 if (u8Channel)
773 {
774 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S2_R_BIT;
775 }
776 else
777 {
778 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S2_L_BIT;
779 }
780 break;
781
782 case AUDIO_I2S4_OUTPUT:
783 if (u8Channel)
784 {
785 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S3_R_BIT;
786 }
787 else
788 {
789 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S3_L_BIT;
790 }
791 break;
792
793 default:
794 ctrl_flag = FALSE;
795 printf("Warning! un-support OutputPhaseShift case(%u). \r\n", u8Output);
796 break;
797 }
798
799 if (ctrl_flag)
800 {
801 HAL_AUDIO_WriteMaskReg(M2S_MBOX_PHASE_SHIFT_CTRL, 1<<(PhaseShiftMaskBit), 1<<(PhaseShiftMaskBit));
802 }
803 }
804
805 ////////////////////////////////////////////////////////////////////////////////
806 /// @brief \b Function \b Name: HAL_SOUND_EnableBalance() @@VVV
807 /// @brief \b Function \b Description: This routine is used to Enable/Disable Balance featue.
808 /// @param <IN> \b u8Enable : Balance Enable bits
809 /// @param <OUT> \b NONE :
810 /// @param <RET> \b NONE :
811 /// @param <GLOBAL> \b NONE :
812 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableBalance(MS_U8 u8Enable)813 void HAL_SOUND_EnableBalance(MS_U8 u8Enable)
814 {
815 HAL_AUDIO_WriteMaskByte(M2S_MBOX_BALANCE_EN+1, 0x80, (u8Enable<<7)); // Balance enable flag
816
817 if(u8Enable)
818 HAL_AUDIO_WriteMaskReg(M2S_MBOX_BALANCE_EN, g_BalanceMask, 0xFFFF); // Balance enable
819 else
820 HAL_AUDIO_WriteMaskReg(M2S_MBOX_BALANCE_EN, g_BalanceMask, 0x0000); // Balance disable
821 }
822
823 ////////////////////////////////////////////////////////////////////////////////
824 /// @brief \b Function \b Name: HAL_SOUND_SetBalanceMask() @@VVV
825 /// @brief \b Function \b Description: This routine is used to Set Balance Mask.
826 /// @param <IN> \b u8Path : AUDIO_PATH_TYPE
827 /// @param <IN> \b u8Enable : TRUE or FALSE
828 /// @param <OUT> \b NONE :
829 /// @param <RET> \b NONE :
830 /// @param <GLOBAL> \b NONE :
831 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalanceMask(AUDIO_OUTPUT_TYPE u8Output,MS_BOOL u8Enable)832 void HAL_SOUND_SetBalanceMask(AUDIO_OUTPUT_TYPE u8Output, MS_BOOL u8Enable)
833 {
834 MS_U16 BalanceMaskBit = 0;
835 MS_BOOL ctrl_flag = TRUE;
836
837 switch(u8Output)
838 {
839 case AUDIO_AUOUT0_OUTPUT:
840 BalanceMaskBit = M2S_MBOX_BAL_DAC0_EN_BIT;
841 break;
842 case AUDIO_AUOUT1_OUTPUT:
843 case AUDIO_HP_OUTPUT:
844 BalanceMaskBit = M2S_MBOX_BAL_DAC1_EN_BIT;
845 break;
846 case AUDIO_AUOUT2_OUTPUT:
847 BalanceMaskBit = M2S_MBOX_BAL_DAC2_EN_BIT;
848 break;
849 case AUDIO_AUOUT3_OUTPUT:
850 BalanceMaskBit = M2S_MBOX_BAL_DAC3_EN_BIT;
851 break;
852
853 case AUDIO_I2S_OUTPUT:
854 BalanceMaskBit = M2S_MBOX_BAL_I2S0_EN_BIT;
855 break;
856 case AUDIO_I2S2_OUTPUT:
857 BalanceMaskBit = M2S_MBOX_BAL_I2S1_EN_BIT;
858 break;
859 case AUDIO_I2S3_OUTPUT:
860 BalanceMaskBit = M2S_MBOX_BAL_I2S2_EN_BIT;
861 break;
862 case AUDIO_I2S4_OUTPUT:
863 BalanceMaskBit = M2S_MBOX_BAL_I2S3_EN_BIT;
864 break;
865
866 case AUDIO_SPDIF_OUTPUT:
867 BalanceMaskBit = M2S_MBOX_BAL_SPDIF_EN_BIT;
868 break;
869
870 case AUDIO_HDMI_ARC_OUTPUT: // tmp disable, no this choice
871 ctrl_flag = FALSE;
872 break;
873
874 case AUDIO_HDMI_OUTPUT: // tmp disable, no this choice
875 ctrl_flag = FALSE;
876 break;
877
878 default:
879 printf("Warning! un-support BalanceMask case(%u). \r\n", u8Output);
880 ctrl_flag = FALSE;
881 break;
882 }
883
884 if (ctrl_flag)
885 {
886 g_BalanceMask = ((g_BalanceMask & (~(0x1<<BalanceMaskBit))) | (u8Enable<<BalanceMaskBit));
887 HAL_SOUND_EnableBalance(TRUE);
888 }
889 }
890
891 const MS_U8 BalanceTab[]=
892 {
893 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, /// 0 ~ 9
894 0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13, /// 10 ~ 19
895 0x14,0x15,0x16,0x17,0x18,0x1A,0x1B,0x1C,0x1F,0x20, /// 20 ~ 29
896 0x22,0x23,0x25,0x27,0x29,0x2B,0x2E,0x30,0x33,0x36, /// 30 ~ 39
897 0x38,0x3D,0x41,0x46,0x4B,0x51,0x59,0x66,0x72,0x8B, /// 40 ~ 49
898 0xFF /// 50
899 };
900
901 ////////////////////////////////////////////////////////////////////////////////
902 /// @brief \b Function \b Name: HAL_SOUND_SetBalance() @@VVV
903 /// @brief \b Function \b Description: This routine is used to set Balance value.
904 /// @param <IN> \b u8Balance : 0~49 -> R channel volume down
905 /// : 50 -> L/R the same (0 dB)
906 /// : 51~100 -> L channel volume down
907 /// @param <OUT> \b NONE :
908 /// @param <RET> \b NONE :
909 /// @param <GLOBAL> \b NONE :
910 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance(MS_U8 u8Balance)911 void HAL_SOUND_SetBalance(MS_U8 u8Balance)
912 {
913 MS_U8 value_l = 0, value_r = 0;
914
915 //printf("apiAud>> u8Balance = %02bx\n", u8Balance);
916 if(u8Balance==50)
917 {
918 value_l = 0x00;
919 value_r = 0x00;
920 }
921 else if(u8Balance<50)
922 {
923 value_l = 0x00;
924 value_r = BalanceTab[(50-u8Balance)];
925 }
926 else if(u8Balance>50)
927 {
928 value_l = BalanceTab[(u8Balance-50)];
929 value_r = 0x00;
930 }
931 //AUD_DEBUG(printf("\napiAud>> Balance UI:0x%bx L:0x%bx R:0x%bx",u8Balance,value_l,value_r));
932 HAL_SOUND_SetBalance_L(value_l );
933 HAL_SOUND_SetBalance_R(value_r );
934 }
935
936 ////////////////////////////////////////////////////////////////////////////////
937 /// @brief \b Function \b Name: HAL_SOUND_SetBalance_L() @@VVV
938 /// @brief \b Function \b Description: This routine is used to set Absolute Balance u8Value of main L-channel.
939 /// @param <IN> \b u8Balance_L : L-channel balance register u8Value
940 /// 0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
941 /// @param <OUT> \b NONE :
942 /// @param <RET> \b NONE :
943 /// @param <GLOBAL> \b NONE :
944 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance_L(MS_U8 u8Balance_L)945 void HAL_SOUND_SetBalance_L(MS_U8 u8Balance_L)
946 {
947 HAL_AUDIO_WriteByte(REG_SOUND_BALANCEL, u8Balance_L);
948 }
949
950 ////////////////////////////////////////////////////////////////////////////////
951 /// @brief \b Function \b Name: HAL_SOUND_GetBalance_L()
952 /// @brief \b Function \b Description: This routine is used to set absolute Balance u8Value of main u8Path L-channel.
953 /// @param <IN> \b NONE :
954 /// @param <OUT> \b u8Balance_L : L-channel balance register u8Value
955 /// 0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
956 /// @param <RET> \b NONE :
957 /// @param <GLOBAL> \b NONE :
958 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBalance_L(void)959 MS_U16 HAL_SOUND_GetBalance_L(void)
960 {
961 return(HAL_AUDIO_ReadByte(REG_SOUND_BALANCEL));
962 }
963
964 ////////////////////////////////////////////////////////////////////////////////
965 /// @brief \b Function \b Name: HAL_SOUND_SetBalance_R() @@VVV
966 /// @brief \b Function \b Description: This routine is used to set Absolute Balance u8Value of main R-channel.
967 /// @param <IN> \b u8Balance_R : R-channel balance register u8Value
968 /// 0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
969 /// @param <OUT> \b NONE :
970 /// @param <RET> \b NONE :
971 /// @param <GLOBAL> \b NONE :
972 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance_R(MS_U8 u8Balance_R)973 void HAL_SOUND_SetBalance_R(MS_U8 u8Balance_R)
974 {
975 HAL_AUDIO_WriteByte(REG_SOUND_BALANCER, u8Balance_R);
976 }
977
978 ////////////////////////////////////////////////////////////////////////////////
979 /// @brief \b Function \b Name: HAL_SOUND_GetBalance_R()
980 /// @brief \b Function \b Description: This routine is used to set absolute Balance u8Value of main u8Path R-channel.
981 /// @param <IN> \b NONE :
982 /// @param <OUT> \b u8Balance_R : R-channel balance register u8Value
983 /// 0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
984 /// @param <RET> \b NONE :
985 /// @param <GLOBAL> \b NONE :
986 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBalance_R(void)987 MS_U16 HAL_SOUND_GetBalance_R(void)
988 {
989 return(HAL_AUDIO_ReadByte(REG_SOUND_BALANCER));
990 }
991
992 ////////////////////////////////////////////////////////////////////////////////
993 /// @brief \b Function \b Name: HAL_SOUND_SetDynamicBass()
994 /// @brief \b Function \b Description: This routine is used to set the DynamicBass u8Level of main u8Path .
995 /// @param <IN> \b u8Level :
996 /// @param <OUT> \b NONE :
997 /// @param <RET> \b NONE :
998 /// @param <GLOBAL> \b NONE :
999 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDynamicBass(MS_U8 u8Level)1000 void HAL_SOUND_SetDynamicBass(MS_U8 u8Level)
1001 {
1002 HAL_AUDIO_WriteByte(M2S_MBOX_SUPBASS_CTRL, u8Level);
1003
1004 if(u8Level == 0)
1005 {
1006 HAL_AUDIO_WriteMaskByte(REG_SOUND_MAIN_SNDEFFECT, 0x20, 0x00);
1007 }
1008 else
1009 {
1010 HAL_AUDIO_WriteMaskByte(REG_SOUND_MAIN_SNDEFFECT, 0x20, 0x20);
1011 }
1012 }
1013
1014 ////////////////////////////////////////////////////////////////////////////////
1015 /// @brief \b Function \b Name: HAL_SOUND_SetBass() @@VVV
1016 /// @brief \b Function \b Description: This routine is used to set the Bass u8Value of main u8Path .
1017 /// @param <IN> \b u8Level : max: 100 (+15dB)
1018 /// 50 ( 0dB)
1019 /// min: 0 (-16dB)
1020 /// @param <OUT> \b NONE :
1021 /// @param <RET> \b NONE :
1022 /// @param <GLOBAL> \b NONE :
1023 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBass(MS_U8 u8Level)1024 void HAL_SOUND_SetBass(MS_U8 u8Level)
1025 {
1026 MS_S32 u8Value;
1027
1028 if(u8Level >= 100)
1029 {
1030 u8Value = 0x30;
1031 }
1032 else
1033 {
1034 u8Value = ((int)u8Level-50)*48/50; //16/50;
1035 }
1036
1037 DBG_SOUND(printf("Bass:%d",u8Level));
1038 DBG_SOUND(printf("==>%x\r\n",u8Value));
1039
1040 HAL_AUDIO_WriteByte(REG_SOUND_BASS, (MS_U8)u8Value);
1041 }
1042
1043 ////////////////////////////////////////////////////////////////////////////////
1044 /// @brief \b Function \b Name: HAL_SOUND_GetBass()
1045 /// @brief \b Function \b Description: This routine is used to get the u16Value gain.
1046 /// @param <IN> \b NONE :
1047 /// @param <OUT> \b u16Bass : max: 0x30 (+15dB)
1048 /// 0x00 ( 0dB), step = 0.25 (dB/step)
1049 /// min: 0xD0 (-16dB)
1050 /// @param <RET> \b NONE :
1051 /// @param <GLOBAL> \b NONE :
1052 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBass(void)1053 MS_U16 HAL_SOUND_GetBass(void)
1054 {
1055 MS_U16 u16Bass = 0;
1056
1057 u16Bass = HAL_AUDIO_ReadByte(REG_SOUND_BASS);
1058 return u16Bass;
1059 }
1060
1061 ////////////////////////////////////////////////////////////////////////////////
1062 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteBass() @@VVV
1063 /// @brief \b Function \b Description: This routine is used to set the absolute Bass u8Value of main u8Path .
1064 /// @param <IN> \b bass : max: 0x30 (+15dB)
1065 /// 0x00 ( 0dB), step = 0.25 (dB/step)
1066 /// min: 0xD0 (-16dB)
1067 /// @param <OUT> \b NONE :
1068 /// @param <RET> \b NONE :
1069 /// @param <GLOBAL> \b NONE :
1070 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteBass(MS_U8 u8Bass)1071 void HAL_SOUND_AbsoluteBass(MS_U8 u8Bass)
1072 {
1073 if ((u8Bass > 0x30) && (u8Bass <= 0x7F))
1074 {
1075 u8Bass = 0x30;
1076 }
1077 if ((u8Bass < 0xD0) && (u8Bass >= 0x80))
1078 {
1079 u8Bass = 0xD0;
1080 }
1081 HAL_AUDIO_WriteByte(REG_SOUND_BASS, u8Bass);
1082 }
1083
1084 ////////////////////////////////////////////////////////////////////////////////
1085 /// @brief \b Function \b Name: HAL_SOUND_SetTreble() @@VVV
1086 //// @brief \b Function \b Description: This routine is used to set the Treble u8Value of main u8Path .
1087 /// @param <IN> \b u8Level : max: 100 (+15dB)
1088 /// 50 ( 0dB)
1089 /// min: 0 (-16dB)
1090 /// @param <OUT> \b NONE :
1091 /// @param <RET> \b NONE :
1092 /// @param <GLOBAL> \b NONE :
1093 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetTreble(MS_U8 u8Level)1094 void HAL_SOUND_SetTreble(MS_U8 u8Level)
1095 {
1096 MS_S32 u8Value;
1097
1098 if (u8Level >= 100)
1099 {
1100 u8Value = 0x30;
1101 }
1102 else
1103 {
1104 u8Value = ((int)u8Level-50)*48/50; //16/50;
1105 }
1106
1107 DBG_SOUND(printf("Treble:%d",u8Level));
1108 DBG_SOUND(printf("==>%x\r\n",u8Value));
1109
1110 HAL_AUDIO_WriteByte(REG_SOUND_TREBLE, (MS_U8)u8Value);
1111 }
1112
1113 ////////////////////////////////////////////////////////////////////////////////
1114 /// @brief \b Function \b Name: HAL_SOUND_GetTreble()
1115 /// @brief \b Function \b Description: This routine is used to get the u16Value gain.
1116 /// @param <IN> \b NONE :
1117 /// @param <OUT> \b u16Treble : max: 0x30 (+15dB)
1118 /// 0x00 ( 0dB), step = 0.25 (dB/step)
1119 /// min: 0xD0 (-16dB)
1120 /// @param <RET> \b NONE :
1121 /// @param <GLOBAL> \b NONE :
1122 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetTreble(void)1123 MS_U16 HAL_SOUND_GetTreble(void)
1124 {
1125 MS_U16 u16Treble = 0;
1126
1127 u16Treble = HAL_AUDIO_ReadByte(REG_SOUND_TREBLE);
1128 return u16Treble;
1129 }
1130
1131 ////////////////////////////////////////////////////////////////////////////////
1132 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteTreble() @@VVV
1133 /// @brief \b Function \b Description: This routine is used to set the absolute Treble u8Value of main u8Path .
1134 /// @param <IN> \b u8Treble: max: 0x30 (+15dB)
1135 /// 0x00 ( 0dB), step = 0.25 (dB/step)
1136 /// min: 0xD0 (-16dB)
1137 /// @param <OUT> \b NONE :
1138 /// @param <RET> \b NONE :
1139 /// @param <GLOBAL> \b NONE :
1140 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteTreble(MS_U8 u8Treble)1141 void HAL_SOUND_AbsoluteTreble(MS_U8 u8Treble)
1142 {
1143 if ((u8Treble > 0x30) && (u8Treble <= 0x7F))
1144 {
1145 u8Treble = 0x30;
1146 }
1147 if ((u8Treble < 0xD0) && (u8Treble >= 0x80))
1148 {
1149 u8Treble = 0xD0;
1150 }
1151 HAL_AUDIO_WriteByte(REG_SOUND_TREBLE, u8Treble);
1152 }
1153
1154 ////////////////////////////////////////////////////////////////////////////////
1155 /// @brief \b Function \b Name: HAL_SOUND_SetEq() @@VVV
1156 /// @brief \b Function \b Description: This routine is used to set the the 5-band EQ u8Level .
1157 /// @param <IN> \b band : EQ band 0~4
1158 /// @param <IN> \b u8Level : Absolute EQ register u8Value
1159 /// @param <OUT> \b NONE :
1160 /// @param <RET> \b NONE :
1161 /// @param <GLOBAL> \b NONE :
1162 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetEq(MS_U8 u8Band,MS_U8 u8Level)1163 void HAL_SOUND_SetEq(MS_U8 u8Band, MS_U8 u8Level)
1164 {
1165 MS_U8 value;
1166
1167 if( u8Band>4)
1168 {
1169 return;
1170 }
1171
1172 if(u8Level>=100)
1173 {
1174 value = 0x30;
1175 }
1176 else
1177 {
1178 value = ((int)u8Level-50)*48/50;
1179 }
1180
1181 HAL_AUDIO_WriteByte(REG_SOUND_EQ1 + (u8Band*2), value);
1182 }
1183
1184 ////////////////////////////////////////////////////////////////////////////////
1185 /// @brief \b Function \b Name: HAL_SOUND_GetEq()
1186 /// @brief \b Function \b Description: This routine is used to set the the 5-band EQ u8Level .
1187 /// @param <IN> \b band : EQ band 0~4
1188 /// @param <IN> \b u8Level : Absolute EQ register u8Value
1189 /// @param <OUT> \b NONE :
1190 /// @param <RET> \b NONE :
1191 /// @param <GLOBAL> \b NONE :
1192 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetEq(MS_U8 u8Band)1193 MS_U16 HAL_SOUND_GetEq(MS_U8 u8Band)
1194 {
1195 MS_U16 value = 0;
1196
1197 value = HAL_AUDIO_ReadByte(REG_SOUND_EQ1 + (u8Band*2));
1198 return value;
1199 }
1200
1201 ////////////////////////////////////////////////////////////////////////////////
1202 /// @brief \b Function \b Name: HAL_SOUND_SetEq7() @@VVV
1203 /// @brief \b Function \b Description: This routine is used to set the the 7-band EQ u8Level .
1204 /// @param <IN> \b u8Band : EQ band 0~6
1205 /// @param <IN> \b u8Level : Absolute EQ register u8Value
1206 /// @param <OUT> \b NONE :
1207 /// @param <RET> \b NONE :
1208 /// @param <GLOBAL> \b NONE :
1209 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetEq7(MS_U8 u8Band,MS_U8 u8Level)1210 void HAL_SOUND_SetEq7(MS_U8 u8Band, MS_U8 u8Level)
1211 {
1212 MS_U8 value;
1213
1214 if( u8Band>6)
1215 return;
1216
1217 if(u8Level==100)
1218 value = 0x30;
1219 else
1220 value = ((int)u8Level-50)*48/50;
1221
1222 HAL_AUDIO_WriteByte(REG_SOUND_EQ_BASE + (u8Band*2), value);
1223 }
1224
1225 ////////////////////////////////////////////////////////////////////////////////
1226 /// @brief \b Function \b Name: HAL_SOUND_SetADCThreshold() @@VVV
1227 /// @brief \b Function \b Description: This routine is used to set the ADC input energy threshold to reduce the background noise .
1228 /// @param <IN> \b u8Threshold : NR threshold u8Level
1229 /// @param <OUT> \b NONE :
1230 /// @param <RET> \b NONE :
1231 /// @param <GLOBAL> \b NONE :
1232 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetADCThreshold(MS_U8 u8Threshold)1233 void HAL_SOUND_SetADCThreshold(MS_U8 u8Threshold)
1234 {
1235 HAL_AUDIO_WriteByte(REG_SOUND_NR_THRESHOLD, u8Threshold);
1236 }
1237
1238 ////////////////////////////////////////////////////////////////////////////////
1239 /// @brief \b Function \b Name: HAL_SOUND_SetDRCThreshold() @@VVV
1240 /// @brief \b Function \b Description: This routine is used to set the DRC threshold u8Level.
1241 /// @param <IN> \b u8Threshold : DRC threshold u8Level
1242 /// 0x00-- 0 dBFS
1243 /// 0x01-- -0.5 dBFS
1244 /// 0x20-- -16 dBFS
1245 /// 0x50-- -40 dBFS
1246 /// @param <IN> \b Type : SPEAKER or HEADPHONE case
1247 /// @param <OUT> \b NONE :
1248 /// @param <RET> \b NONE :
1249 /// @param <GLOBAL> \b NONE :
1250 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDRCThreshold(MS_U8 u8Level,AUDIO_SOUNDEFFECT_TYPE Type)1251 void HAL_SOUND_SetDRCThreshold(MS_U8 u8Level, AUDIO_SOUNDEFFECT_TYPE Type)
1252 {
1253 if (u8Level >= 0x50)
1254 u8Level = 0x50;
1255
1256 switch (Type)
1257 {
1258 case AUDIO_SOUNDEFFECT_SPEAKER:
1259 HAL_AUDIO_WriteByte(REG_SOUND_DRC_THRESHOLD, u8Level); //[ 7: 0]
1260 break;
1261
1262 case AUDIO_SOUNDEFFECT_HEADPHONE:
1263 HAL_AUDIO_WriteByte(REG_SOUND_DRC_THRESHOLD+1, u8Level); //[15: 8]
1264 break;
1265
1266 default:
1267 printf("Warning! Invalid AUDIO_SOUNDEFFECT_TYPE(%u). \r\n", Type);
1268 break;
1269 }
1270 }
1271
1272 ////////////////////////////////////////////////////////////////////////////////
1273 /// @brief \b Function \b Name: HAL_SOUND_GetDRCThreshold()
1274 /// @brief \b Function \b Description: This routine is used to get the DRC threshold u8Level.
1275 /// @param <IN> \b NONE
1276 /// @param <OUT> \b Threshold value :
1277 /// @param <RET> \b NONE :
1278 /// @param <GLOBAL> \b NONE :
1279 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetDRCThreshold(void)1280 MS_U16 HAL_SOUND_GetDRCThreshold(void)
1281 {
1282 return(HAL_AUDIO_SeReadByte(REG_SOUND_DRC_THRESHOLD));
1283 }
1284
1285 ////////////////////////////////////////////////////////////////////////////////
1286 /// @brief \b Function \b Name: HAL_SOUND_SetDRCEntry() @@VVV
1287 /// @brief \b Function \b Description: This routine is used to set the DRC Entry u8Enable.
1288 /// @param <IN> \b Type : SPEAKER or HEADPHONE case
1289 /// @param <IN> \b u8Enable: DRC EntrySelect u8Enable
1290 /// 0 -- DRC before VOL function; 1 -- DRC behind VOL function;
1291 /// @param <OUT> \b NONE :
1292 /// @param <RET> \b NONE :
1293 /// @param <GLOBAL> \b NONE :
1294 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDRCEntry(AUDIO_SOUNDEFFECT_TYPE Type,MS_U8 u8Enable)1295 void HAL_SOUND_SetDRCEntry(AUDIO_SOUNDEFFECT_TYPE Type, MS_U8 u8Enable)
1296 {
1297 switch (Type)
1298 {
1299 case AUDIO_SOUNDEFFECT_SPEAKER:
1300 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_SPK_VOL_BSND_CTRL_BIT), u8Enable<<(M2S_MBOX_SPK_VOL_BSND_CTRL_BIT));
1301 break;
1302
1303 case AUDIO_SOUNDEFFECT_HEADPHONE:
1304 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_HP_VOL_BSND_CTRL_BIT), u8Enable<<(M2S_MBOX_HP_VOL_BSND_CTRL_BIT));
1305 break;
1306
1307 default:
1308 printf("Warning! Invalid AUDIO_SOUNDEFFECT_TYPE(%u). \r\n", Type);
1309 break;
1310 }
1311 }
1312
1313 ////////////////////////////////////////////////////////////////////////////////
1314 /// @brief \b Function \b Name: HAL_SOUND_SetAVCThreshold() @@VVV
1315 /// @brief \b Function \b Description: This routine is used to set the AVC threshold u8Level.
1316 /// @param <IN> \b u8Threshold : AVC threshold u8Level
1317 /// 0x00-- 0 dBFS
1318 /// 0x01-- -0.5 dBFS
1319 /// 0x20-- -16 dBFS
1320 /// 0x50-- -40 dBFS
1321 /// @param <OUT> \b NONE :
1322 /// @param <RET> \b NONE :
1323 /// @param <GLOBAL> \b NONE :
1324 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAVCThreshold(MS_U8 u8Level)1325 void HAL_SOUND_SetAVCThreshold(MS_U8 u8Level)
1326 {
1327 if (u8Level >= 0x50)
1328 u8Level = 0x50;
1329
1330 HAL_AUDIO_WriteByte(REG_SOUND_AVC_THRESHOLD,u8Level);
1331 }
1332
1333 ////////////////////////////////////////////////////////////////////////////////
1334 /// @brief \b Function \b Name: HAL_SOUND_GetAVCThreshold()
1335 /// @brief \b Function \b Description: This routine is used to set the AVC threshold u8Level.
1336 /// @param <IN> \b NONE
1337 /// @param <OUT> \b Threshold value :
1338 /// @param <RET> \b NONE :
1339 /// @param <GLOBAL> \b NONE :
1340 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAVCThreshold(void)1341 MS_U16 HAL_SOUND_GetAVCThreshold(void)
1342 {
1343 return(HAL_AUDIO_SeReadByte(REG_SOUND_AVC_THRESHOLD));
1344 }
1345
1346 ////////////////////////////////////////////////////////////////////////////////
1347 /// @brief \b Function \b Name: HAL_SOUND_SetAvcMode() @@VVV
1348 /// @brief \b Function \b Description: This routine is used to set the AVC mode.
1349 /// @param <IN> \b u8AvcMode : AVC threshold u8Level
1350 /// 0: L mode
1351 /// 1: S mode
1352 /// 2: M mode
1353 /// @param <OUT> \b NONE :
1354 /// @param <RET> \b NONE :
1355 /// @param <GLOBAL> \b NONE :
1356 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcMode(MS_U8 u8AvcMode)1357 void HAL_SOUND_SetAvcMode(MS_U8 u8AvcMode )
1358 {
1359 switch(u8AvcMode)
1360 {
1361 case 0:
1362 HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x00);
1363 break;
1364 case 1:
1365 HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x01);
1366 break;
1367 case 2:
1368 HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x02);
1369 break;
1370 default:
1371 break;
1372 }
1373 }
1374
1375 ////////////////////////////////////////////////////////////////////////////////
1376 /// @brief \b Function \b Name: HAL_SOUND_GetAvcMode()
1377 /// @brief \b Function \b Description: This routine is used to set the AVC mode.
1378 /// @param <RET> \b u8AvcMode : AVC threshold u8Level
1379 /// 0: L mode
1380 /// 1: S mode
1381 /// 2: M mode
1382 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcMode(void)1383 MS_U16 HAL_SOUND_GetAvcMode(void)
1384 {
1385 return(HAL_AUDIO_ReadByte(REG_SOUND_AVC_MODE)&0x03);
1386 }
1387
1388 ////////////////////////////////////////////////////////////////////////////////
1389 /// @brief \b Function \b Name: HAL_SOUND_SetAvcAT() @@VVV
1390 /// @brief \b Function \b Description: This routine is used to set the AVC attack time .
1391 /// @param <IN> \b u8AvcAT : AVC attack time
1392 /// AvcAT = 0 --> 2 sec
1393 /// AvcAT = 1 --> 1 sec
1394 /// AvcAT = 2 --> 500 ms
1395 /// AvcAT = 3 --> 400 ms
1396 /// AvcAT = 4 --> 300 ms
1397 /// AvcAT = 5 --> 200 ms
1398 /// AvcAT = 6 --> 100 ms
1399 /// AvcAT = 7 --> 20 ms
1400 /// @param <OUT> \b NONE :
1401 /// @param <RET> \b NONE :
1402 /// @param <GLOBAL> \b NONE :
1403 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcAT(MS_U8 u8AvcAT)1404 void HAL_SOUND_SetAvcAT(MS_U8 u8AvcAT )
1405 {
1406 if(u8AvcAT>7)
1407 u8AvcAT=7;
1408
1409 HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_AT ,0xE0 ,(u8AvcAT<<5));
1410 }
1411
1412 ////////////////////////////////////////////////////////////////////////////////
1413 /// @brief \b Function \b Name: HAL_SOUND_GetAvcAT()
1414 /// @brief \b Function \b Description: This routine is used to set the AVC mode.
1415 /// @param <RET>
1416 /// AvcAT = 0 --> 2 sec
1417 /// AvcAT = 1 --> 1 sec
1418 /// AvcAT = 2 --> 500 ms
1419 /// AvcAT = 3 --> 400 ms
1420 /// AvcAT = 4 --> 300 ms
1421 /// AvcAT = 5 --> 200 ms
1422 /// AvcAT = 6 --> 100 ms
1423 /// AvcAT = 7 --> 20 ms
1424 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcAT(void)1425 MS_U16 HAL_SOUND_GetAvcAT(void)
1426 {
1427 return((HAL_AUDIO_ReadByte(REG_SOUND_AVC_AT)&0xE0)>>5);
1428 }
1429
1430 ////////////////////////////////////////////////////////////////////////////////
1431 /// @brief \b Function \b Name: HAL_SOUND_SetAvcRT() @@VVV
1432 /// @brief \b Function \b Description: This routine is used to set the AVC release time .
1433 /// @param <IN> \b u8AvcRT : AVC release time
1434 /// u8AvcRT = 0 --> 2 sec
1435 /// u8AvcRT = 1 --> 1 sec
1436 /// u8AvcRT = 2 --> 500 ms
1437 /// u8AvcRT = 3 --> 400 ms
1438 /// u8AvcRT = 4 --> 300 ms
1439 /// u8AvcRT = 5 --> 200 ms
1440 /// u8AvcRT = 6 --> 100 ms
1441 /// u8AvcRT = 7 --> 20 ms
1442 /// @param <OUT> \b NONE :
1443 /// @param <RET> \b NONE :
1444 /// @param <GLOBAL> \b NONE :
1445 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcRT(MS_U8 u8AvcRT)1446 void HAL_SOUND_SetAvcRT(MS_U8 u8AvcRT )
1447 {
1448 if(u8AvcRT>7)
1449 u8AvcRT=7;
1450
1451 HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_RT ,0x1C ,(u8AvcRT<<2));
1452 }
1453
1454 ////////////////////////////////////////////////////////////////////////////////
1455 /// @brief \b Function \b Name: HAL_SOUND_GetAvcRT()
1456 /// @brief \b Function \b Description: This routine is used to set the AVC mode.
1457 /// @param <RET> \b u8AvcRT : AVC release time
1458 /// u8AvcRT = 0 --> 2 sec
1459 /// u8AvcRT = 1 --> 1 sec
1460 /// u8AvcRT = 2 --> 500 ms
1461 /// u8AvcRT = 3 --> 400 ms
1462 /// u8AvcRT = 4 --> 300 ms
1463 /// u8AvcRT = 5 --> 200 ms
1464 /// u8AvcRT = 6 --> 100 ms
1465 /// u8AvcRT = 7 --> 20 ms
1466 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcRT(void)1467 MS_U16 HAL_SOUND_GetAvcRT(void)
1468 {
1469 MS_U16 Mode=0;
1470
1471 Mode = (HAL_AUDIO_ReadByte(REG_SOUND_AVC_RT)&0x1C) >> 2;
1472 return Mode;
1473 }
1474
1475 ////////////////////////////////////////////////////////////////////////////////
1476 /// @brief \b Function \b Name: HAL_SOUND_EnablePEQ()
1477 /// @brief \b Function \b Description: This routine is used to Enable/Disable PEQ featue
1478 /// @param <IN> \b Enpeq : TRUE -- Enable PEQ
1479 /// FALSE -- Disable PEQ
1480 /// @param <OUT> \b NONE :
1481 /// @param <RET> \b NONE :
1482 /// @param <GLOBAL> \b NONE :
1483 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnablePEQ(MS_BOOL Enpeq)1484 void HAL_SOUND_EnablePEQ(MS_BOOL Enpeq)
1485 {
1486 HAL_AUDIO_WriteMaskByte(0x2D20, 0x01, Enpeq);
1487 }
1488
1489 ////////////////////////////////////////////////////////////////////////////////
1490 /// @brief \b Function \b Name: HAL_SOUND_GetPEQ_Status()
1491 /// @brief \b Function \b Description: This routine is used to get the PEQ is enable or not
1492 /// @param <IN> \b NONE :
1493 /// @param <OUT> \b NONE :
1494 /// @param <RET> \b bEnable : TRUE -- Enable PEQ
1495 /// FALSE -- Disable PEQ
1496 /// @param <GLOBAL> \b NONE :
1497 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetPEQ_Status(void)1498 MS_U16 HAL_SOUND_GetPEQ_Status(void)
1499 {
1500 if ((HAL_AUDIO_ReadByte(0x2D20)&0x01) == 0x01)
1501 {
1502 return 1;
1503 }
1504 else
1505 {
1506 return 0;
1507 }
1508 }
1509
1510 ////////////////////////////////////////////////////////////////////////////////
1511 /// @brief \b Function \b Name: HAL_SOUND_EnableHPF() @@VVV
1512 /// @brief \b Function \b Description: This routine is used to Enable/Disable HPF featue.
1513 /// @param <IN> \b bEnable : TRUE -- Enable HPF
1514 /// FALSE -- Disable HPF
1515 /// @param <OUT> \b NONE :
1516 /// @param <RET> \b NONE :
1517 /// @param <GLOBAL> \b NONE :
1518 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableHPF(MS_BOOL bEnable)1519 void HAL_SOUND_EnableHPF(MS_BOOL bEnable)
1520 {
1521 HAL_AUDIO_WriteMaskByte(0x2D20, 0x04, bEnable<<2);
1522 }
1523
1524 ////////////////////////////////////////////////////////////////////////////////
1525 /// @brief \b Function \b Name: HAL_SOUND_GetHPF_Status()
1526 /// @brief \b Function \b Description: This routine is used to get the HPF is enable or not
1527 /// @param <IN> \b NONE :
1528 /// @param <OUT> \b NONE :
1529 /// @param <RET> \b bEnable : TRUE -- Enable HPF
1530 /// FALSE -- Disable HPF
1531 /// @param <GLOBAL> \b NONE :
1532 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetHPF_Status(void)1533 MS_U16 HAL_SOUND_GetHPF_Status(void)
1534 {
1535 if ((HAL_AUDIO_ReadByte(0x2D20)&0x04) == 0x04)
1536 {
1537 return 1;
1538 }
1539 else
1540 {
1541 return 0;
1542 }
1543 }
1544
1545 ////////////////////////////////////////////////////////////////////////////////
1546 /// @brief \b Function \b Name: HAL_SOUND_EnableDcRemove()
1547 /// @brief \b Function \b Description: This routine is used to Enable/Disable DC remove.
1548 /// @param <IN> \b EnDcRemove : TRUE -- Enable DC remove
1549 /// FALSE -- Disable DC remove
1550 /// @param <OUT> \b NONE :
1551 /// @param <RET> \b NONE :
1552 /// @param <GLOBAL> \b NONE :
1553 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableDcRemove(MS_BOOL EnDcRemove)1554 MS_BOOL HAL_SOUND_EnableDcRemove(MS_BOOL EnDcRemove)
1555 {
1556 HAL_AUDIO_WriteMaskByte(0x2D20, 0x08, EnDcRemove<<3);
1557 return 1;
1558 }
1559
1560 ////////////////////////////////////////////////////////////////////////////////
1561 /// @brief \b Function \b Name: HAL_SOUND_EnableKTVEcho() @@VVV
1562 /// @brief \b Function \b Description: This routine is used to bEnable/disable the KTVEcho featue.
1563 /// @param <IN> \b bEnable : TRUE -- Enable KTVEcho
1564 /// FALSE -- Disable KTVEcho
1565 /// @param <OUT> \b NONE :
1566 /// @param <RET> \b NONE :
1567 /// @param <GLOBAL> \b NONE :
1568 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableKTVEcho(MS_BOOL bEnable)1569 void HAL_SOUND_EnableKTVEcho(MS_BOOL bEnable)
1570 {
1571 HAL_AUDIO_WriteMaskByte(0x2D20, 0x10, bEnable<<4);
1572 }
1573
1574 ////////////////////////////////////////////////////////////////////////////////
1575 /// @brief \b Function \b Name: HAL_SOUND_EnableEaseVol() @@VVV
1576 /// @brief \b Function \b Description: This routine is used to bEnable/disable the EaseVol featue.
1577 /// @param <IN> \b bEnable : TRUE -- Enable EaseVol
1578 /// FALSE -- Disable EaseVol
1579 /// @param <OUT> \b NONE :
1580 /// @param <RET> \b NONE :
1581 /// @param <GLOBAL> \b NONE :
1582 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableEaseVol(MS_BOOL bEnable)1583 void HAL_SOUND_EnableEaseVol(MS_BOOL bEnable)
1584 {
1585 HAL_AUDIO_WriteMaskByte(0x2D20, 0x40, bEnable<<6);
1586 }
1587
1588 ////////////////////////////////////////////////////////////////////////////////
1589 /// @brief \b Function \b Name: HAL_SOUND_EnableEQ() @@VVV
1590 /// @brief \b Function \b Description: This routine is used to Enable/Disable GEQ featue.
1591 /// @param <IN> \b bEnable : TRUE -- Enable GEQ
1592 /// FALSE -- Disable GEQ
1593 /// @param <OUT> \b NONE :
1594 /// @param <RET> \b NONE :
1595 /// @param <GLOBAL> \b NONE :
1596 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableEQ(MS_BOOL bEnable)1597 void HAL_SOUND_EnableEQ(MS_BOOL bEnable)
1598 {
1599 HAL_AUDIO_WriteMaskByte(0x2D20, 0x80, bEnable<<7);
1600 }
1601
1602 ////////////////////////////////////////////////////////////////////////////////
1603 /// @brief \b Function \b Name: HAL_SOUND_GetEQ_Status()
1604 /// @brief \b Function \b Description: This routine is used to get the GEQ is enable or not
1605 /// @param <IN> \b NONE :
1606 /// @param <OUT> \b NONE :
1607 /// @param <RET> \b bEnable : TRUE -- Enable GEQ
1608 /// FALSE -- Disable GEQ
1609 /// @param <GLOBAL> \b NONE :
1610 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetEQ_Status(void)1611 MS_U16 HAL_SOUND_GetEQ_Status(void)
1612 {
1613 if((HAL_AUDIO_ReadByte(0x2D20)&0x80) == 0x80)
1614 {
1615 return 1;
1616 }
1617 else
1618 {
1619 return 0;
1620 }
1621 }
1622
1623 ////////////////////////////////////////////////////////////////////////////////
1624 /// @brief \b Function \b Name: HAL_SOUND_EnableSurround() @@VVV
1625 /// @brief \b Function \b Description: This routine is used to Enable/Disable Surround featue.
1626 /// @param <IN> \b bEnable : TRUE --Enable Surround
1627 /// FALSE--Disable Surround
1628 /// @param <OUT> \b NONE :
1629 /// @param <RET> \b NONE :
1630 /// @param <GLOBAL> \b NONE :
1631 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableSurround(MS_BOOL bEnable)1632 void HAL_SOUND_EnableSurround(MS_BOOL bEnable)
1633 {
1634 HAL_AUDIO_WriteMaskByte(0x2D21, 0x04, bEnable<<2);
1635 }
1636
1637 ////////////////////////////////////////////////////////////////////////////////
1638 /// @brief \b Function \b Name: HAL_SOUND_GetSurround_Status()
1639 /// @brief \b Function \b Description: This routine is used to get the Surround is enable or not
1640 /// @param <IN> \b NONE :
1641 /// @param <OUT> \b NONE :
1642 /// @param <RET> \b bEnable : TRUE --Enable Surround
1643 /// FALSE--Disable Surround
1644 /// @param <GLOBAL> \b NONE :
1645 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurround_Status(void)1646 MS_U16 HAL_SOUND_GetSurround_Status(void)
1647 {
1648 if((HAL_AUDIO_ReadByte(0x2D21)&0x04) == 0x04)
1649 {
1650 return 1;
1651 }
1652 else
1653 {
1654 return 0;
1655 }
1656 }
1657
1658 ////////////////////////////////////////////////////////////////////////////////
1659 /// @brief \b Function \b Name: HAL_SOUND_EnableTone() @@VVV
1660 /// @brief \b Function \b Description: This routine is used to Enable/Disable the Bass & Treble featue.
1661 /// @param <IN> \b bEnable : TRUE --Enable Tone
1662 /// FALSE--Disable Tone
1663 /// @param <OUT> \b NONE :
1664 /// @param <RET> \b NONE :
1665 /// @param <GLOBAL> \b NONE :
1666 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableTone(MS_BOOL bEnable)1667 void HAL_SOUND_EnableTone(MS_BOOL bEnable)
1668 {
1669 HAL_AUDIO_WriteMaskByte(0x2D21, 0x08, bEnable<<3);
1670 }
1671
1672 ////////////////////////////////////////////////////////////////////////////////
1673 /// @brief \b Function \b Name: HAL_SOUND_GetTone_Status()
1674 /// @brief \b Function \b Description: This routine is used to get Bass & Trebleis enable or not
1675 /// @param <IN> \b NONE :
1676 /// @param <OUT> \b NONE :
1677 /// @param <RET> \b bEnable : TRUE --Enable Tone
1678 /// FALSE--Disable Tone
1679 /// @param <GLOBAL> \b NONE :
1680 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetTone_Status(void)1681 MS_U16 HAL_SOUND_GetTone_Status(void)
1682 {
1683 if((HAL_AUDIO_ReadByte(0x2D21)&0x08) == 0x08)
1684 {
1685 return 1;
1686 }
1687 else
1688 {
1689 return 0;
1690 }
1691 }
1692
1693 ////////////////////////////////////////////////////////////////////////////////
1694 /// @brief \b Function \b Name: HAL_SOUND_EnableAutoVolume() @@VVV
1695 /// @brief \b Function \b Description: This routine is used to Enable/Disable the AVC featue.
1696 /// @param <IN> \b bEnable : TRUE -- Enable AVC (AutoVolume)
1697 /// FALSE -- Disable AVC (AutoVolume)
1698 /// @param <OUT> \b NONE :
1699 /// @param <RET> \b NONE :
1700 /// @param <GLOBAL> \b NONE :
1701 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableAutoVolume(MS_BOOL bEnable)1702 void HAL_SOUND_EnableAutoVolume(MS_BOOL bEnable)
1703 {
1704 HAL_AUDIO_WriteMaskByte(0x2D21, 0x10, bEnable<<4);
1705 }
1706
1707 ////////////////////////////////////////////////////////////////////////////////
1708 /// @brief \b Function \b Name: HAL_SOUND_GetAutoVolume_Status()
1709 /// @brief \b Function \b Description: This routine is used to get the AutoVolume is enable or not
1710 /// @param <IN> \b NONE :
1711 /// @param <OUT> \b NONE :
1712 /// @param <RET> \b bEnable : TRUE -- Enable AVC (AutoVolume)
1713 /// FALSE -- Disable AVC (AutoVolume)
1714 /// @param <GLOBAL> \b NONE :
1715 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAutoVolume_Status(void)1716 MS_U16 HAL_SOUND_GetAutoVolume_Status(void)
1717 {
1718 if((HAL_AUDIO_ReadByte(0x2D21)&0x10) == 0x10)
1719 {
1720 return 1;
1721 }
1722 else
1723 {
1724 return 0;
1725 }
1726 }
1727
1728 ////////////////////////////////////////////////////////////////////////////////
1729 /// @brief \b Function \b Name: HAL_SOUND_EnableDRC() @@VVV
1730 /// @brief \b Function \b Description: This routine is used to Enable/Disable the DRC featue.
1731 /// @param <IN> \b bEnable : TRUE -- Enable DRC
1732 /// FALSE -- Disable DRC
1733 /// @param <OUT> \b NONE :
1734 /// @param <RET> \b NONE :
1735 /// @param <GLOBAL> \b NONE :
1736 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableDRC(MS_BOOL bEnable)1737 void HAL_SOUND_EnableDRC(MS_BOOL bEnable)
1738 {
1739 HAL_AUDIO_WriteMaskByte(0x2D21, 0x20, bEnable<<5);
1740 }
1741
1742 ////////////////////////////////////////////////////////////////////////////////
1743 /// @brief \b Function \b Name: HAL_SOUND_EnableNR()
1744 /// @brief \b Function \b Description: This routine is used to Enable/Disable the NR(Noise Reduction) featue and set NR thershold.
1745 /// @param <IN> \b bEnable : TRUE --Enable NR
1746 /// FALSE--Disable NR
1747 /// @param <OUT> \b NONE :
1748 /// @param <RET> \b NONE :
1749 /// @param <GLOBAL> \b NONE :
1750 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableNR(MS_U8 u8Level)1751 void HAL_SOUND_EnableNR(MS_U8 u8Level)
1752 {
1753 HAL_AUDIO_WriteMaskByte(0x2D32, 0xFF, u8Level);
1754 }
1755
1756 ////////////////////////////////////////////////////////////////////////////////
1757 /// @brief \b Function \b Name: HAL_SOUND_SetNRAttenuate()
1758 /// @brief \b Function \b Description: This routine is used to set the attenuate u8Level while NR is bEnabled.
1759 /// @param <IN> \b u8Mode : 0 : Auto fading to -24 dB
1760 /// 1 : Auto fading to -24 dB
1761 /// 2 : Auto fading to -24 dB
1762 /// 3 : Auto fading to -24 dB
1763 /// @param <OUT> \b NONE :
1764 /// @param <RET> \b NONE :
1765 /// @param <GLOBAL> \b NONE :
1766 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetNRAttenuate(MS_U8 u8Mode)1767 void HAL_SOUND_SetNRAttenuate(MS_U8 u8Mode)
1768 {
1769 u8Mode = u8Mode;
1770 }
1771
1772 ////////////////////////////////////////////////////////////////////////////////
1773 /// @brief \b Function \b Name: HAL_SOUND_PowerDown_Wait() @@VVV
1774 /// @brief \b Function \b Description: This routine is used to DSP power-down wait function.
1775 /// @param <IN> \b bEnable : TRUE --Not wait
1776 /// FALSE--wait
1777 /// @param <OUT> \b NONE :
1778 /// @param <RET> \b NONE :
1779 /// @param <GLOBAL> \b NONE :
1780 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_PowerDown_Wait(MS_BOOL bEnable)1781 void HAL_SOUND_PowerDown_Wait(MS_BOOL bEnable)
1782 {
1783 HAL_AUDIO_WriteMaskByte(0x2D31, 0x01, bEnable);
1784 }
1785
1786 ////////////////////////////////////////////////////////////////////////////////
1787 /// @brief \b Function \b Name: HAL_SOUND_SetAdAbsoluteVolume() @@VVV
1788 /// @brief \b Function \b Description: This routine is used to set the absolute volume of AD.
1789 /// @param <IN> \b u8u8Vol1 : MSB 7-bit register u8Value of 10-bit volume
1790 /// range from 0x00 to 0x7E , gain: +12db to -114db (-1 db per step)
1791 /// @param <IN> \b u8u8Vol2 : LSB 3-bit register u8Value of 10-bit volume
1792 /// range from 0x00 to 0x07 , gain: -0db to -0.875db (-0.125 db per step)
1793 /// @param <OUT> \b NONE :
1794 /// @param <RET> \b NONE :
1795 /// @param <GLOBAL> \b NONE :
1796 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAdAbsoluteVolume(MS_U8 u8Vol1,MS_U8 u8Vol2)1797 void HAL_SOUND_SetAdAbsoluteVolume(MS_U8 u8Vol1, MS_U8 u8Vol2)
1798 {
1799 MS_U32 Vol = ((u8Vol1<<3) | (u8Vol2&0x07));
1800 HAL_DEC_R2_Set_SHM_PARAM(R2_SHM_PARAM_AD_VOLUME, ADEC1, Vol, 0);
1801 // Vol[10:0] = mute[10]|int[9:3]|fra[2:0]
1802 }
1803
1804 ////////////////////////////////////////////////////////////////////////////////
1805 /// @brief \b Function \b Name: HAL_SOUND_SetAdMute() @@VVV
1806 /// @brief \b Function \b Description: This routine is used to set AD mute.
1807 /// @param <IN> \b bEnable : TRUE --Mute AD
1808 /// FALSE--Unmute AD
1809 /// @param <OUT> \b NONE :
1810 /// @param <RET> \b NONE :
1811 /// @param <GLOBAL> \b NONE :
1812 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAdMute(MS_BOOL bEnable)1813 void HAL_SOUND_SetAdMute(MS_BOOL bEnable)
1814 {
1815 HAL_DEC_R2_Set_SHM_PARAM(R2_SHM_PARAM_AD_VOLUME_MUTE, ADEC1, bEnable, 0);
1816 }
1817
1818 ////////////////////////////////////////////////////////////////////////////////
1819 /// @brief \b Function \b Name: HAL_SOUND_SetCH1AudioDelay()
1820 /// @brief \b Function \b Description: This routine is used to set the u16Value of audio delay.
1821 /// @param <IN> \b delay : in ms unit
1822 /// @param <OUT> \b NONE :
1823 /// @param <RET> \b NONE :
1824 /// @param <GLOBAL> \b NONE :
1825 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetCH1AudioDelay(MS_U16 u16Delay)1826 void HAL_SOUND_SetCH1AudioDelay(MS_U16 u16Delay)
1827 {
1828 if (u16Delay > AUDIO_DELAY_UPPER_BOUND)
1829 {
1830 printf("Warning! Invalid value (%u), main audio delay should be less than %u ms. \r\n", u16Delay, AUDIO_DELAY_UPPER_BOUND);
1831 u16Delay = AUDIO_DELAY_UPPER_BOUND;
1832 }
1833
1834 if (u16Delay < AUDIO_DELAY_LOWER_BOUND)
1835 {
1836 printf("Warning! Invalid value (%u), main audio delay should be larger than %u ms. \r\n", u16Delay, AUDIO_DELAY_LOWER_BOUND);
1837 u16Delay = AUDIO_DELAY_LOWER_BOUND;
1838 }
1839
1840 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_mainAudioDelay, u16Delay, DSP_MEM_TYPE_PM);
1841 }
1842
1843 ////////////////////////////////////////////////////////////////////////////////
1844 /// @brief \b Function \b Name: HAL_SOUND_GetCH1AudioDelay()
1845 /// @brief \b Function \b Description: This routine is used to get the u16Value of audio delay.
1846 /// @param <RET> \b delay : in ms unit
1847 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH1AudioDelay(void)1848 MS_U16 HAL_SOUND_GetCH1AudioDelay(void)
1849 {
1850 return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_mainAudioDelay, DSP_MEM_TYPE_PM));
1851 }
1852
1853 ////////////////////////////////////////////////////////////////////////////////
1854 /// @brief \b Function \b Name: HAL_SOUND_SetCH5AudioDelay()
1855 /// @brief \b Function \b Description: This routine is used to set the u16Value of CH5 delay.
1856 /// @param <IN> \b delay : in ms unit
1857 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetCH5AudioDelay(MS_U16 u16Delay)1858 void HAL_SOUND_SetCH5AudioDelay(MS_U16 u16Delay)
1859 {
1860 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_ch5InputDelay, u16Delay, DSP_MEM_TYPE_PM);
1861 }
1862
1863 ////////////////////////////////////////////////////////////////////////////////
1864 /// @brief \b Function \b Name: HAL_SOUND_GetCH5AudioDelay()
1865 /// @brief \b Function \b Description: This routine is used to get the u16Value of audio delay.
1866 /// @param <RET> \b delay : in ms unit
1867 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH5AudioDelay(void)1868 MS_U16 HAL_SOUND_GetCH5AudioDelay(void)
1869 {
1870 return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch5InputDelay, DSP_MEM_TYPE_PM));
1871 }
1872
1873 ////////////////////////////////////////////////////////////////////////////////
1874 /// @brief \b Function \b Name: HAL_SOUND_SetCH6AudioDelay()
1875 /// @brief \b Function \b Description: This routine is used to set the u16Value of CH6 delay.
1876 /// @param <IN> \b delay : in ms unit
1877 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetCH6AudioDelay(MS_U16 u16Delay)1878 void HAL_SOUND_SetCH6AudioDelay(MS_U16 u16Delay)
1879 {
1880 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_ch6InputDelay, u16Delay, DSP_MEM_TYPE_PM);
1881 }
1882
1883 ////////////////////////////////////////////////////////////////////////////////
1884 /// @brief \b Function \b Name: HAL_SOUND_GetCH6AudioDelay()
1885 /// @brief \b Function \b Description: This routine is used to get the u16Value of audio delay.
1886 /// @param <RET> \b delay : in ms unit
1887 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH6AudioDelay(void)1888 MS_U16 HAL_SOUND_GetCH6AudioDelay(void)
1889 {
1890 return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch6InputDelay, DSP_MEM_TYPE_PM));
1891 }
1892
1893 ////////////////////////////////////////////////////////////////////////////////
1894 /// @brief \b Function \b Name: HAL_SOUND_SetSpdifAudioDelay()
1895 /// @brief \b Function \b Description: This routine is used to set the u16Value of audio delay.
1896 /// @param <IN> \b delay : in ms unit
1897 /// @param <OUT> \b NONE :
1898 /// @param <RET> \b NONE :
1899 /// @param <GLOBAL> \b NONE :
1900 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSpdifAudioDelay(MS_U16 u16Delay)1901 void HAL_SOUND_SetSpdifAudioDelay(MS_U16 u16Delay)
1902 {
1903 if (u16Delay > AUDIO_DELAY_UPPER_BOUND_SPDIF)
1904 {
1905 printf("Warning! Invalid value (%u), spdif audio delay should be less than %u ms. \r\n", u16Delay, AUDIO_DELAY_UPPER_BOUND_SPDIF);
1906 u16Delay = AUDIO_DELAY_UPPER_BOUND_SPDIF;
1907 }
1908
1909 if (u16Delay < AUDIO_DELAY_LOWER_BOUND_SPDIF)
1910 {
1911 printf("Warning! Invalid value (%u), spdif audio delay should be larger than %u ms. \r\n", u16Delay, AUDIO_DELAY_LOWER_BOUND_SPDIF);
1912 u16Delay = AUDIO_DELAY_LOWER_BOUND_SPDIF;
1913 }
1914
1915 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_spdifDelay, u16Delay, DSP_MEM_TYPE_PM);
1916 }
1917
1918 ////////////////////////////////////////////////////////////////////////////////
1919 /// @brief \b Function \b Name: HAL_SOUND_GetSpdifAudioDelay()
1920 /// @brief \b Function \b Description: This routine is used to get the u16Value of audio SPDIF delay.
1921 /// @param <RET> \b delay : in ms unit
1922 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSpdifAudioDelay(void)1923 MS_U16 HAL_SOUND_GetSpdifAudioDelay(void)
1924 {
1925 return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_spdifDelay, DSP_MEM_TYPE_PM));
1926 }
1927
1928 ////////////////////////////////////////////////////////////////////////////////
1929 /// @brief \b Function \b Name: HAL_SOUND_SetHPAudioDelay()
1930 /// @brief \b Function \b Description: This routine is used to set the u16Value of HP delay.
1931 /// @param <IN> \b delay : in ms unit
1932 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetHPAudioDelay(MS_U16 u16Delay)1933 void HAL_SOUND_SetHPAudioDelay(MS_U16 u16Delay)
1934 {
1935 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_hpDelay, u16Delay, DSP_MEM_TYPE_PM);
1936 }
1937
1938 ////////////////////////////////////////////////////////////////////////////////
1939 /// @brief \b Function \b Name: HAL_SOUND_GetHPAudioDelay()
1940 /// @brief \b Function \b Description: This routine is used to get the u16Value of audio HP delay.
1941 /// @param <RET> \b delay : in ms unit
1942 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetHPAudioDelay(void)1943 MS_U16 HAL_SOUND_GetHPAudioDelay(void)
1944 {
1945 return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_hpDelay, DSP_MEM_TYPE_PM));
1946 }
1947
1948 ////////////////////////////////////////////////////////////////////////////////
1949 /// @brief \b Function \b Name: HAL_SOUND_SetMenuSound() @@Need_Modify
1950 /// @brief \b Function \b Description: This routine is used to Play Menu Sound.
1951 /// @param <IN> \b NONE :
1952 /// @param <OUT> \b NONE :
1953 /// @param <RET> \b NONE :
1954 /// @param <GLOBAL> \b NONE :
1955 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_PlayMenuSound(void)1956 void HAL_SOUND_PlayMenuSound(void)
1957 {
1958 /*Cathy0721
1959 HAL_AUDIO_WriteMaskByte(0x2DAE, 0x01, 0x01);
1960 AUDIO_DELAY1MS(10);
1961 HAL_AUDIO_WriteMaskByte(0x2DAE, 0x01, 0x00);*/
1962 }
1963
1964 ////////////////////////////////////////////////////////////////////////////////
1965 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXA() @@VVV
1966 /// @brief \b Function \b Description: This routine is used to set the Surround xA Gain.
1967 /// @param <IN> \b u8Mode : 0 : 0.1 xA : 0x2D8A[3:2] 00: 0.1
1968 /// 1 : 0.15 01: 0.15
1969 /// 2 : 0.2 10: 0.2
1970 /// 3 : 0.25 11: 0.25
1971 /// @param <OUT> \b NONE :
1972 /// @param <RET> \b NONE :
1973 /// @param <GLOBAL> \b NONE
1974 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXA(MS_U8 u8Mode)1975 void HAL_SOUND_SetSurroundXA(MS_U8 u8Mode)
1976 {
1977 switch(u8Mode)
1978 {
1979 case 0:
1980 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x00);
1981 break;
1982 case 1:
1983 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x04);
1984 break;
1985 case 2:
1986 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x08);
1987 break;
1988 case 3:
1989 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x0C);
1990 break;
1991 default:
1992 break;
1993 }
1994 }
1995
1996 ////////////////////////////////////////////////////////////////////////////////
1997 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXA()
1998 /// @brief \b Function \b Description: This routine is used to set the Surround xA Gain.
1999 /// @param <RET> MODE \b u8Mode : 0 : 0.1 xA : 0x2D8A[3:2] 00: 0.1
2000 /// 1 : 0.15 01: 0.15
2001 /// 2 : 0.2 10: 0.2
2002 /// 3 : 0.25 11: 0.25
2003 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXA(void)2004 MS_U16 HAL_SOUND_GetSurroundXA(void)
2005 {
2006 return((HAL_AUDIO_ReadByte(0x2D26)&0x0C)>>2);
2007 }
2008
2009 ////////////////////////////////////////////////////////////////////////////////
2010 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXB() @@VVV
2011 /// @brief \b Function \b Description: This routine is used to set the Surround xB Gain.
2012 /// @param <IN> \b u8Mode : 0 : 0.25 xB : 0x2D8A[5:4] 00: 0.25
2013 /// 1 : 0.3 01: 0.3
2014 /// 2 : 0.35 10: 0.35
2015 /// 3 : 0.45 11: 0.45
2016 /// @param <OUT> \b NONE :
2017 /// @param <RET> \b NONE :
2018 /// @param <GLOBAL> \b NONE
2019 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXB(MS_U8 u8Mode)2020 void HAL_SOUND_SetSurroundXB(MS_U8 u8Mode)
2021 {
2022 switch(u8Mode)
2023 {
2024 case 0:
2025 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x00);
2026 break;
2027 case 1:
2028 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x10);
2029 break;
2030 case 2:
2031 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x20);
2032 break;
2033 case 3:
2034 HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x30);
2035 break;
2036 default:
2037 break;
2038 }
2039 }
2040
2041 ////////////////////////////////////////////////////////////////////////////////
2042 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXB()
2043 /// @brief \b Function \b Description: This routine is used to set the Surround xB Gain.
2044 /// @param <RET> MODE \b u8Mode : 0 : 0.1 xB : 0x2D8A[3:2] 00: 0.1
2045 /// 1 : 0.15 01: 0.15
2046 /// 2 : 0.2 10: 0.2
2047 /// 3 : 0.25 11: 0.25
2048 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXB(void)2049 MS_U16 HAL_SOUND_GetSurroundXB(void)
2050 {
2051 return((HAL_AUDIO_ReadByte(0x2D26)&0x30)>>4);
2052 }
2053
2054 ////////////////////////////////////////////////////////////////////////////////
2055 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXK() @@VVV
2056 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2057 /// @param <IN> \b u8Mode : 0 : 0.1 xK : 0x2D8A[7:6] 00: 0.1
2058 /// 1 : 0.2 01: 0.2
2059 /// 2 : 0.3 10: 0.3
2060 /// 3 : 0.4 11: 0.4
2061 /// @param <OUT> \b NONE :
2062 /// @param <RET> \b NONE :
2063 /// @param <GLOBAL> \b NONE
2064 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXK(MS_U8 u8Mode)2065 void HAL_SOUND_SetSurroundXK(MS_U8 u8Mode)
2066 {
2067 HAL_AUDIO_WriteMaskByte(0x2D27 ,0x07 ,u8Mode);
2068 }
2069
2070 ////////////////////////////////////////////////////////////////////////////////
2071 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXK()
2072 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2073 /// @param <RET> MODE \b u8Mode : 0 : 0.1 xK : 0x2D27[2:0] 00: 0.1
2074 /// 1 : 0.2 01: 0.2
2075 /// 2 : 0.3 10: 0.3
2076 /// 3 : 0.4 11: 0.4
2077 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXK(void)2078 MS_U16 HAL_SOUND_GetSurroundXK(void)
2079 {
2080 MS_U16 Mode=0;
2081
2082 Mode = HAL_AUDIO_ReadByte(0x2D27)&0x07;
2083
2084 return Mode;
2085 }
2086
2087 ////////////////////////////////////////////////////////////////////////////////
2088 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundLPFGain() @@VVV
2089 /// @brief \b Function \b Description: This routine is used to set the Surround LPF Gain.
2090 /// @param <IN> \b u8Mode : 0 : 0 dB LPF Gain : 0x2DA0[7:6] 00: 0 dB
2091 /// 1 : 2 dB 01: 2 dB
2092 /// 2 : 4 dB 10: 4 dB
2093 /// 3 : un-support 11: un-support
2094 /// @param <OUT> \b NONE :
2095 /// @param <RET> \b NONE :
2096 /// @param <GLOBAL> \b NONE
2097 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundLPFGain(MS_U8 u8Mode)2098 void HAL_SOUND_SetSurroundLPFGain(MS_U8 u8Mode)
2099 {
2100 switch(u8Mode)
2101 {
2102 case 0:
2103 HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x00);
2104 break;
2105 case 1:
2106 HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x40);
2107 break;
2108 case 2:
2109 HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x80);
2110 break;
2111 case 3:
2112 //HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0xC0);
2113 break;
2114 default:
2115 break;
2116 }
2117 }
2118
2119 ////////////////////////////////////////////////////////////////////////////////
2120 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundLPFGain()
2121 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2122 /// @param <RET> \b LPFGain :
2123 // 0 : 0dB
2124 /// 1 : 2dB
2125 /// 2 : 4dB
2126 /// 3 : up-support
2127 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundLPFGain(void)2128 MS_U16 HAL_SOUND_GetSurroundLPFGain(void)
2129 {
2130 return((HAL_AUDIO_ReadByte(0x2D26)&0xC0)>>6);
2131 }
2132
2133
2134 ////////////////////////////////////////////////////////////////////////////////
2135 /// @brief \b Function \b Name: HAL_SOUND_SetPEQCoef()
2136 /// @brief \b Function \b Description: This routine is used to set PEQ Coefficient.
2137 /// @param <IN> \b peq_coef
2138 /// @param <OUT> \b NONE :
2139 /// @param <RET> \b NONE :
2140 /// @param <GLOBAL> \b NONE
2141 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetPEQCoef(AUDIO_PEQ_COEF * peq_coef)2142 void HAL_SOUND_SetPEQCoef(AUDIO_PEQ_COEF *peq_coef)
2143 {
2144 MS_U16 dsp_addr;
2145 MS_U16 dsp_scale_addr;
2146
2147 if(peq_coef->sfs == 0)
2148 {
2149 DBG_SOUND(printf("!!!only support 48K coefficient ! ! !\n");)
2150 return;
2151 }
2152
2153 //PEQ setting
2154 if(peq_coef->type == AUDIO_COEF_PEQ || peq_coef->type == AUDIO_COEF_PREVER_PEQ) // PEQ setting
2155 {
2156 if(peq_coef->enable == FALSE)
2157 peq_band_enable &= (0xFFFFFFFF ^ ((MS_U32)1<<peq_coef->band));
2158 else
2159 peq_band_enable |= ((MS_U32)1<<peq_coef->band);
2160
2161 if(peq_coef->precision == AUDIO_SINGLE_PRECISION)
2162 peq_band_precision &= (0xFFFFFFFF ^ ((MS_U32)1<<peq_coef->band));
2163 else
2164 peq_band_precision |= ((MS_U32)1<<peq_coef->band);
2165
2166 dsp_addr = DSP2PmAddr_peq48KCoeffAddr + peq_coef->band*5;
2167 dsp_scale_addr = DSP2PmAddr_peqscale48KAddr + peq_coef->band;
2168
2169 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable updating coefficient to prevent pop
2170 HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2171 HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2172 HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2173 HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2174 HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2175 HAL_MAD2_Write_DSP_sram(dsp_scale_addr,(MS_U32)peq_coef->scale, DSP_MEM_TYPE_PM);
2176 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peqbandEnAddr,peq_band_enable, DSP_MEM_TYPE_PM);
2177 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peqbandDoubleAddr,peq_band_precision, DSP_MEM_TYPE_PM);
2178 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //enable coefficient update
2179 }
2180 // HLPF setting
2181 else if(peq_coef->type == AUDIO_COEF_HPF)
2182 {
2183 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable updating coefficient to prevent pop
2184 dsp_addr = DSP2PmAddr_hpf48KCoeffAddr;
2185 HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2186 HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2187 HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2188 HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2189 HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2190 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //disable oefficient update
2191 }
2192 //TONE setting
2193 else if(peq_coef->type == AUDIO_COEF_BASS ||peq_coef->type == AUDIO_COEF_TREBLE)
2194 {
2195 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable updating coefficient to prevent pop
2196 if(peq_coef->type == AUDIO_COEF_BASS)
2197 {
2198 dsp_addr = DSP2PmAddr_bass48KCoeffAddr;
2199 }
2200 else
2201 {
2202 dsp_addr = DSP2PmAddr_treble48KCoeffAddr;
2203 dsp_scale_addr =DSP2PmAddr_treblescale48KAddr;
2204 HAL_MAD2_Write_DSP_sram(dsp_scale_addr,(MS_U32)peq_coef->scale, DSP_MEM_TYPE_PM);
2205 }
2206 HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2207 HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2208 HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2209 HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2210 HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2211 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_toneSelectAddr,0x01, DSP_MEM_TYPE_PM);
2212 HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //disable oefficient update
2213 }
2214 else
2215 {
2216 DBG_SOUND(printf("!!! undefined coefficient type ! ! !\n");)
2217 return;
2218 }
2219
2220 DBG_SOUND(printf("HAL a0 = %x", (MS_U8)(peq_coef->a0>>16)));
2221 DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a0>>8)));
2222 DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a0));
2223
2224 DBG_SOUND(printf("HAL a1 = %x", (MS_U8)(peq_coef->a1>>16)));
2225 DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a1>>8)));
2226 DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a1));
2227
2228 DBG_SOUND(printf("HAL a2 = %x", (MS_U8)(peq_coef->a2>>16)));
2229 DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a2>>8)));
2230 DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a2));
2231
2232 DBG_SOUND(printf("HAL b1 = %x", (MS_U8)(peq_coef->b1>>16)));
2233 DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->b1>>8)));
2234 DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->b1));
2235
2236 DBG_SOUND(printf("HAL b2 = %x", (MS_U8)(peq_coef->b2>>16)));
2237 DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->b2>>8)));
2238 DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->b2));
2239 }
2240
2241 ////////////////////////////////////////////////////////////////////////////////
2242 /// @brief \b Function \b Name: MDrv_SOUND_SetMixModeVolume() @@VVV
2243 /// @brief \b Function \b Description: This routine is used to set the absolute volume of mix mode.
2244 /// @param <IN> \b eSourceType: for audio source
2245 /// @param <IN> \b VolType : for vol type
2246 /// @param <IN> \b u8u8Vol1 : MSB 7-bit register u8Value of 10-bit volume
2247 /// range from 0x00 to 0x7E , gain: +12db to -114db (-1 db per step)
2248 /// @param <IN> \b u8u8Vol2 : LSB 3-bit register u8Value of 10-bit volume
2249 /// range from 0x00 to 0x07 , gain: -0db to -0.875db (-0.125 db per step)
2250 /// @param <OUT> \b NONE :
2251 /// @param <RET> \b NONE :
2252 /// @param <GLOBAL> \b NONE :
2253 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_U8 u8Vol1,MS_U8 u8Vol2)2254 void HAL_SOUND_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_U8 u8Vol1, MS_U8 u8Vol2 )
2255 {
2256 switch (eSourceType)
2257 {
2258 case E_AUDIO_INFO_KTV_IN:
2259 switch(VolType)
2260 {
2261 case PCM_VOL:
2262 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_DMA_IN, u8Vol1, u8Vol2);
2263 break;
2264
2265 case MIC_VOL:
2266 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_MAIN, u8Vol1, u8Vol2);
2267 break;
2268
2269 case MP3_VOL:
2270 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_SECONDARY, u8Vol1, u8Vol2);
2271 break;
2272
2273 case ECHO1_VOL:
2274 if(u8Vol1<14)
2275 u8Vol1 = 14;
2276 HAL_AUDIO_WriteMaskByte(0x2D57, 0x7F, u8Vol1);
2277 HAL_AUDIO_WriteMaskByte(0x2D56, 0xE0, (u8Vol2<<5));
2278 break;
2279
2280 case ECHO2_VOL:
2281 HAL_AUDIO_WriteMaskByte(0x2D59, 0x7F, u8Vol1);
2282 HAL_AUDIO_WriteMaskByte(0x2D58, 0xE0, (u8Vol2<<5));
2283 break;
2284
2285 default:
2286 break;
2287 }
2288 break;
2289
2290 case E_AUDIO_INFO_GAME_IN:
2291 switch(VolType)
2292 {
2293 case PCM_VOL:
2294 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_DMA_IN, u8Vol1, u8Vol2);
2295 break;
2296
2297 case GAME1_VOL:
2298 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_MAIN, u8Vol1, u8Vol2);
2299 break;
2300
2301 case GAME2_VOL:
2302 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_SECONDARY, u8Vol1, u8Vol2);
2303 break;
2304 default:
2305 break;
2306 }
2307 break;
2308
2309 default:
2310 break;
2311 }
2312 }
2313
2314 ////////////////////////////////////////////////////////////////////////////////
2315 /// @brief \b Function \b Name: HAL_SOUND_SetMixModeMute() @@VVV
2316 /// @brief \b Function \b Description: This routine is used to set audio mix mode S/W mute.
2317 /// @param <IN> \b eSourseType: for audio source type
2318 /// @param <IN> \b VolType : for vol type
2319 /// @param <IN> \b bEnable : TRUE --Mute
2320 /// : FALSE--Unmute
2321 /// @param <OUT> \b NONE :
2322 /// @param <RET> \b NONE :
2323 /// @param <GLOBAL> \b NONE :
2324 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_BOOL EnMute)2325 void HAL_SOUND_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_BOOL EnMute )
2326 {
2327 switch (eSourceType)
2328 {
2329 case E_AUDIO_INFO_KTV_IN:
2330 switch(VolType)
2331 {
2332 case PCM_VOL:
2333 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, EnMute);
2334 break;
2335
2336 case MIC_VOL:
2337 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_MAIN, EnMute);
2338 break;
2339
2340 case MP3_VOL:
2341 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_SECONDARY, EnMute);
2342 break;
2343
2344 default:
2345 break;
2346 }
2347 break;
2348
2349 case E_AUDIO_INFO_GAME_IN:
2350 switch(VolType)
2351 {
2352 case PCM_VOL:
2353 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, EnMute);
2354 break;
2355
2356 case GAME1_VOL:
2357 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_MAIN, EnMute);
2358 break;
2359
2360 case GAME2_VOL:
2361 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_SECONDARY, EnMute);
2362 break;
2363
2364 default:
2365 break;
2366 }
2367 break;
2368
2369 default:
2370 break;
2371 }
2372 }
2373
2374 //******************************************************************************
2375 /// @brief \b Function \b Name: HAL_SOUND_SetParam()
2376 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2377 /// @return MS_BOOL \b : True / False
2378 //******************************************************************************
HAL_SOUND_SetParam(Sound_SET_Type Type,MS_U32 * p_param)2379 MS_BOOL HAL_SOUND_SetParam( Sound_SET_Type Type, MS_U32 *p_param )
2380 {
2381 MS_U8 param1 = (MS_U8)(p_param[0]);
2382 MS_U8 param2 = (MS_U8)(p_param[1]);
2383 MS_U8 param3 = (MS_U8)(p_param[2]);
2384 MS_U8 param4 = (MS_U8)(p_param[3]);
2385
2386 switch(Type)
2387 {
2388 case Sound_SET_Type_SetPreScale:
2389 HAL_SOUND_SetPreScale(param1, param2);
2390 break;
2391
2392 case Sound_SET_Type_SetMute:
2393 HAL_SOUND_SetMute(param1, param2);
2394 break;
2395
2396 case Sound_SET_Type_SetBalance:
2397 HAL_SOUND_SetBalance(param1);
2398 break;
2399
2400 case Sound_SET_Type_EnableEQ:
2401 HAL_SOUND_EnableEQ(param1);
2402 break;
2403
2404 case Sound_SET_Type_EnablePEQ:
2405 HAL_SOUND_EnablePEQ(param1);
2406 break;
2407
2408 case Sound_SET_Type_EnableTone:
2409 HAL_SOUND_EnableTone(param1);
2410 break;
2411
2412 case Sound_SET_Type_EnableAutoVolume:
2413 HAL_SOUND_EnableAutoVolume(param1);
2414 break;
2415
2416 case Sound_SET_Type_EnableSurround:
2417 HAL_SOUND_EnableSurround(param1);
2418 break;
2419
2420 case Sound_SET_Type_SetBass:
2421 HAL_SOUND_SetBass(param1);
2422 break;
2423
2424 case Sound_SET_Type_EnableBalance:
2425 HAL_SOUND_EnableBalance(param1);
2426 break;
2427
2428 case Sound_SET_Type_AbsoluteBass:
2429 HAL_SOUND_AbsoluteBass(param1);
2430 break;
2431
2432 case Sound_SET_Type_SetTreble:
2433 HAL_SOUND_SetTreble(param1);
2434 break;
2435
2436 case Sound_SET_Type_SetEq:
2437 HAL_SOUND_SetEq(param1, param2);
2438 break;
2439
2440 case Sound_SET_Type_SetEq_7band:
2441 HAL_SOUND_SetEq7(param1, param2);
2442 break;
2443
2444 case Sound_SET_Type_SetAvc:
2445 HAL_SOUND_SetAVCThreshold(param1);
2446 HAL_SOUND_SetAvcMode(param2);
2447 HAL_SOUND_SetAvcAT(param3);
2448 HAL_SOUND_SetAvcRT(param4);
2449 break;
2450
2451 case Sound_SET_Type_SetAudioDelay:
2452 HAL_SOUND_SetCH1AudioDelay(param1);
2453 break;
2454
2455 case Sound_SET_Type_SetSurround:
2456 HAL_SOUND_SetSurroundXA(param1);
2457 HAL_SOUND_SetSurroundXB(param2);
2458 HAL_SOUND_SetSurroundXK(param3);
2459 HAL_SOUND_SetSurroundLPFGain(param4);
2460 break;
2461
2462 case Sound_SET_Type_ConvertVolumeUnit:
2463 break;
2464
2465 case Sound_SET_Type_SetDCOffet:
2466 HAL_AUDIO_WriteByte(0x2B50 ,param1);
2467 HAL_AUDIO_WriteByte(0x2B51 ,param2);
2468 break;
2469
2470 case Sound_SET_Type_EnableSineTone:
2471 default:
2472 break;
2473 }
2474 return TRUE;
2475 }
2476
2477 //******************************************************************************
2478 /// @brief \b Function \b Name: HAL_SND_ProcessEnable()
2479 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2480 //******************************************************************************
HAL_SND_ProcessEnable(Sound_ENABLE_Type Type,MS_BOOL enable)2481 MS_BOOL HAL_SND_ProcessEnable(Sound_ENABLE_Type Type, MS_BOOL enable)
2482 {
2483 MS_BOOL status = FALSE;
2484
2485 switch(Type)
2486 {
2487 case Sound_ENABL_Type_EQ:
2488 HAL_SOUND_EnableEQ(enable);
2489 status = TRUE;
2490 break;
2491
2492 case Sound_ENABL_Type_PEQ:
2493 HAL_SOUND_EnablePEQ(enable);
2494 status = TRUE;
2495 break;
2496
2497 case Sound_ENABL_Type_Tone:
2498 HAL_SOUND_EnableTone(enable);
2499 status = TRUE;
2500 break;
2501
2502 case Sound_ENABL_Type_AutoVolume:
2503 HAL_SOUND_EnableAutoVolume(enable);
2504 status = TRUE;
2505 break;
2506
2507 case Sound_ENABL_Type_Surround:
2508 HAL_SOUND_EnableSurround(enable);
2509 status = TRUE;
2510 break;
2511
2512 case Sound_ENABL_Type_Balance:
2513 HAL_SOUND_EnableBalance(enable);
2514 status = TRUE;
2515 break;
2516
2517 case Sound_ENABL_Type_DRC:
2518 HAL_SOUND_EnableDRC(enable);
2519 status = TRUE;
2520 break;
2521
2522 case Sound_ENABL_Type_KTVEcho:
2523 HAL_SOUND_EnableKTVEcho(enable);
2524 status = TRUE;
2525 break;
2526
2527 case Sound_ENABL_Type_Hpf:
2528 HAL_SOUND_EnableHPF(enable);
2529 status = TRUE;
2530 break;
2531
2532 case Sound_ENABL_Type_DcRemove:
2533 HAL_SOUND_EnableDcRemove(enable);
2534 status = TRUE;
2535 break;
2536
2537 case Sound_ENABL_Type_EaseVol:
2538 HAL_SOUND_EnableEaseVol(enable);
2539 status = TRUE;
2540 break;
2541
2542 case Sound_ENABL_Type_HeadPhoneSoundEffect:
2543 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_HEADPHONEPSND_CTRL_BIT), enable<<(M2S_MBOX_HEADPHONEPSND_CTRL_BIT));
2544 status = TRUE;
2545 break;
2546
2547 default:
2548 status = FALSE;
2549 break;
2550 }
2551 return(status);
2552 }
2553
2554 //******************************************************************************
2555 /// @brief \b Function \b Name: HAL_SND_SetParam()
2556 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2557 /// @return MS_BOOL \b : True / False
2558 //******************************************************************************
HAL_SND_SetParam(Sound_SET_PARAM_Type Type,MS_U16 param1,MS_U16 param2)2559 MS_BOOL HAL_SND_SetParam(Sound_SET_PARAM_Type Type, MS_U16 param1, MS_U16 param2)
2560 {
2561 MS_BOOL status = FALSE;
2562 MS_U16 data = 0;
2563
2564 switch(Type)
2565 {
2566 case Sound_SET_PARAM_PreScale:
2567 HAL_SOUND_SetPreScale(param1, param2); //param1: path, param2:prescale
2568 status = TRUE;
2569 break;
2570
2571 case Sound_SET_PARAM_Balance:
2572 HAL_SOUND_SetBalance(param1); // param1: balance 0~100
2573 status = TRUE;
2574 break;
2575
2576 case Sound_SET_PARAM_AbsoluteBalance:
2577 HAL_SOUND_SetBalance_L((MS_U8)param1); // param1: balance L 0x00(0dB)~0xFF(mute)
2578 HAL_SOUND_SetBalance_R((MS_U8)param2); // param2: balance R 0x00(0dB)~0xFF(mute)
2579 status = TRUE;
2580 break;
2581
2582 case Sound_SET_PARAM_Bass:
2583 HAL_SOUND_SetBass(param1); // param1: bass 0~100
2584 status = TRUE;
2585 break;
2586
2587 case Sound_SET_PARAM_AbsoluteBass: // absolute bass, param1: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2588 HAL_SOUND_AbsoluteBass(param1);
2589 status = TRUE;
2590 break;
2591
2592 case Sound_SET_PARAM_Treble:
2593 HAL_SOUND_SetTreble(param1); // param1: treble 0~100
2594 status = TRUE;
2595 break;
2596
2597 case Sound_SET_PARAM_AbsoluteTreble: // absolute treble, param1: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2598 HAL_SOUND_AbsoluteTreble(param1);
2599 status = TRUE;
2600 break;
2601
2602 case Sound_SET_PARAM_EQ:
2603 HAL_SOUND_SetEq(param1, param2); //param1: band 0~4, param2:level 0~100
2604 break;
2605
2606 case Sound_SET_PARAM_AbsoluteEQ: // absolute GEQ, param1: band 0~4, param2: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2607 if(param1 > 4)
2608 {
2609 printf("Invalid value, GEQ Band should be 0~4\n");
2610 }
2611 else
2612 {
2613 if ((param2 > 0x30) && (param2 <= 0x7F))
2614 {
2615 param2 = 0x30;
2616 }
2617 if ((param2 < 0xD0) && (param2 >= 0x80))
2618 {
2619 param2 = 0xD0;
2620 }
2621 HAL_AUDIO_WriteByte(REG_SOUND_EQ1 + (param1*2), (MS_U8)param2);
2622 }
2623 break;
2624
2625 case Sound_SET_PARAM_Surround_XA:
2626 HAL_SOUND_SetSurroundXA(param1);
2627 status = TRUE;
2628 break;
2629
2630 case Sound_SET_PARAM_Surround_XB:
2631 HAL_SOUND_SetSurroundXB(param1);
2632 status = TRUE;
2633 break;
2634
2635 case Sound_SET_PARAM_Surround_XK:
2636 HAL_SOUND_SetSurroundXK(param1);
2637 status = TRUE;
2638 break;
2639
2640 case Sound_SET_PARAM_Surround_LPFGAIN:
2641 HAL_SOUND_SetSurroundLPFGain(param1);
2642 status = TRUE;
2643 break;
2644
2645 case Sound_SET_PARAM_NR_Threshold:
2646 HAL_SOUND_EnableNR((MS_U8)param1); // param1: NR threshold: 0x00~0xFF
2647 status = TRUE;
2648 break;
2649
2650 case Sound_SET_PARAM_Avc_Mode:
2651 HAL_SOUND_SetAvcMode(param1);
2652 status = TRUE;
2653 break;
2654
2655 case Sound_SET_PARAM_Avc_Threshold:
2656 HAL_SOUND_SetAVCThreshold(param1);
2657 status = TRUE;
2658 break;
2659
2660 case Sound_SET_PARAM_Avc_AT:
2661 HAL_SOUND_SetAvcAT(param1);
2662 status = TRUE;
2663 break;
2664
2665 case Sound_SET_PARAM_Avc_RT:
2666 HAL_SOUND_SetAvcRT(param1);
2667 status = TRUE;
2668 break;
2669
2670 case Sound_SET_PARAM_Drc_Threshold:
2671 HAL_SOUND_SetDRCThreshold(param1,(AUDIO_SOUNDEFFECT_TYPE)param2);
2672 status = TRUE;
2673 break;
2674
2675 case Sound_SET_PARAM_AudioDelay:
2676 HAL_SOUND_SetCH1AudioDelay(param1);
2677 status = TRUE;
2678 break;
2679
2680 case Sound_SET_PARAM_DCOffet:
2681 HAL_AUDIO_WriteByte(0x2B51, param1);
2682 HAL_AUDIO_WriteByte(0x2B50, param2);
2683 status = TRUE;
2684 break;
2685
2686 case Sound_SET_PARAM_PEQ_48K_A0:
2687 if((param1>>8) > MAX_PEQ_BAND-1)
2688 printf("PEQ paramater Band should be 0~4\n");
2689 else
2690 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2691 break;
2692
2693 case Sound_SET_PARAM_PEQ_48K_A1:
2694 if((param1>>8) > MAX_PEQ_BAND-1)
2695 printf("PEQ paramater Band should be 0~4\n");
2696 else
2697 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+1, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2698 break;
2699
2700 case Sound_SET_PARAM_PEQ_48K_A2:
2701 if((param1>>8) > MAX_PEQ_BAND-1)
2702 printf("PEQ paramater Band should be 0~4\n");
2703 else
2704 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+2, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2705 break;
2706
2707 case Sound_SET_PARAM_PEQ_48K_B1:
2708 if((param1>>8) > MAX_PEQ_BAND-1)
2709 printf("PEQ paramater Band should be 0~4\n");
2710 else
2711 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+3, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2712 break;
2713
2714 case Sound_SET_PARAM_PEQ_48K_B2:
2715 if((param1>>8) > MAX_PEQ_BAND-1)
2716 printf("PEQ paramater Band should be 0~4\n");
2717 else
2718 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+4, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2719 break;
2720
2721 case Sound_SET_PARAM_PEQ_32K_A0:
2722 // No support 32K PEQ in T12
2723 break;
2724
2725 case Sound_SET_PARAM_PEQ_32K_A1:
2726 // No support 32K PEQ in T12
2727 break;
2728
2729 case Sound_SET_PARAM_PEQ_32K_A2:
2730 // No support 32K PEQ in T12
2731 break;
2732
2733 case Sound_SET_PARAM_PEQ_32K_B1:
2734 // No support 32K PEQ in T12
2735 break;
2736
2737 case Sound_SET_PARAM_PEQ_32K_B2:
2738 // No support 32K PEQ in T12
2739 break;
2740
2741 case Sound_SET_PARAM_DMAReader:
2742 if(param1 == 0)
2743 {
2744 if(param2 >= 4)
2745 {
2746 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, true);
2747 }
2748 else
2749 {
2750 data = 0x0C + param2*4;
2751 HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_DMA_IN,data,0);
2752 HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, false);
2753 }
2754 status = TRUE;
2755 }
2756 break;
2757
2758 case Sound_SET_PARAM_AVC_S_Offset:
2759 {
2760 MS_U32 S_offset = 0x400000; // default offset: +6 dB, 3.21 format for DSP
2761 if((param1 < 0) || (param1 > 12))
2762 {
2763 printf("AVC offset is out of range 0~12 dB \n");
2764 }
2765 else
2766 {
2767 S_offset = (MS_U32)AVC_SOffset_TBL[param1];
2768 }
2769 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_AvcSOffsetAddr, S_offset, DSP_MEM_TYPE_DM);
2770 status = TRUE;
2771 break;
2772 }
2773
2774 case Sound_SET_PARAM_Ease_Type_A:
2775 case Sound_SET_PARAM_Ease_Type_B:
2776 {
2777 MS_U32 u32EaseType = AUDIO_EASE_TYPE_LINEAR;
2778 MS_U32 u32DspPmEaseBase = 0;
2779
2780 status = TRUE;
2781
2782 switch (Type)
2783 {
2784 case Sound_SET_PARAM_Ease_Type_A:
2785 {
2786 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2787 break;
2788 }
2789
2790 case Sound_SET_PARAM_Ease_Type_B:
2791 {
2792 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2793 break;
2794 }
2795
2796 default:
2797 {
2798 HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2799 status = FALSE;
2800 break;
2801 }
2802 }
2803
2804 switch (param1)
2805 {
2806 case E_AUDIO_EASE_TYPE_LINEAR:
2807 {
2808 u32EaseType = AUDIO_EASE_TYPE_LINEAR;
2809 break;
2810 }
2811
2812 case E_AUDIO_EASE_TYPE_INCUBIC:
2813 {
2814 u32EaseType = AUDIO_EASE_TYPE_INCUBIC;
2815 break;
2816 }
2817
2818 case E_AUDIO_EASE_TYPE_OUTCUBIC:
2819 {
2820 u32EaseType = AUDIO_EASE_TYPE_OUTCUBIC;
2821 break;
2822 }
2823
2824 case E_AUDIO_EASE_TYPE_INOUTCUBIC:
2825 {
2826 u32EaseType = AUDIO_EASE_TYPE_INOUTCUBIC;
2827 break;
2828 }
2829
2830 default:
2831 {
2832 HALSOUND_ERROR("%s: invalid audio ease type %d\n", __FUNCTION__, param1);
2833 status = FALSE;
2834 break;
2835 }
2836 }
2837
2838 if (status == TRUE)
2839 {
2840 HAL_MAD2_Write_DSP_sram((u32DspPmEaseBase + 2), u32EaseType, DSP_MEM_TYPE_PM);
2841 }
2842
2843 break;
2844 }
2845
2846 case Sound_SET_PARAM_Ease_Duration_A:
2847 case Sound_SET_PARAM_Ease_Duration_B:
2848 {
2849 MS_U32 u32MiniSecond = 0;
2850 MS_U32 u32SamplesOfMiniSecond = 0;
2851 MS_U32 u32DspPmEaseBase = 0;
2852
2853 status = TRUE;
2854
2855 switch (Type)
2856 {
2857 case Sound_SET_PARAM_Ease_Duration_A:
2858 {
2859 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2860 break;
2861 }
2862
2863 case Sound_SET_PARAM_Ease_Duration_B:
2864 {
2865 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2866 break;
2867 }
2868
2869 default:
2870 {
2871 HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2872 status = FALSE;
2873 break;
2874 }
2875 }
2876
2877 if (status == TRUE)
2878 {
2879 if (param1 > 60000)
2880 {
2881 HALSOUND_ERROR("%s: target duration (%d) of audio ease is too large!\n", __FUNCTION__, param1);
2882 u32MiniSecond = 60000;
2883 }
2884 else
2885 {
2886 u32MiniSecond = (MS_U32)param1;
2887 }
2888
2889 u32SamplesOfMiniSecond = u32MiniSecond * 48; /* samples of 1 ms in 48KHz */
2890 HAL_MAD2_Write_DSP_sram((u32DspPmEaseBase + 1), u32SamplesOfMiniSecond, DSP_MEM_TYPE_PM);
2891 }
2892
2893 break;
2894 }
2895
2896 case Sound_SET_PARAM_Ease_Gain_A:
2897 case Sound_SET_PARAM_Ease_Gain_B:
2898 {
2899 MS_U32 u32Gain = 0;
2900 MS_U32 u32DspPmEaseBase = 0;
2901
2902 status = TRUE;
2903
2904 switch (Type)
2905 {
2906 case Sound_SET_PARAM_Ease_Gain_A:
2907 {
2908 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2909 break;
2910 }
2911
2912 case Sound_SET_PARAM_Ease_Gain_B:
2913 {
2914 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2915 break;
2916 }
2917
2918 default:
2919 {
2920 HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2921 status = FALSE;
2922 break;
2923 }
2924 }
2925
2926 if (status == TRUE)
2927 {
2928 u32Gain = (MS_U32)(((param1 & 0xFF) << 16) | (param2 & 0xFFFF));
2929 if (u32Gain > 0x7FFFFF)
2930 {
2931 HALSOUND_ERROR("%s: target gain (0x%X) of audio ease is too large!\n", __FUNCTION__, (unsigned int)u32Gain);
2932 u32Gain = 0x7FFFFF;
2933 }
2934
2935 HAL_MAD2_Write_DSP_sram(u32DspPmEaseBase, u32Gain, DSP_MEM_TYPE_PM);
2936 }
2937
2938 break;
2939 }
2940
2941 case Sound_SET_PARAM_Ease_Target_Channel_A:
2942 case Sound_SET_PARAM_Ease_Target_Channel_B:
2943 {
2944 MS_U32 u32Mask = 0x000000;
2945 MS_U32 u32TargetChannel = AUDIO_EASE_CH_NONE;
2946 MS_U32 u32ChannelSetting = 0;
2947 MS_U32 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 8;
2948
2949 status = TRUE;
2950
2951 if (param2 == TRUE)
2952 {
2953 switch (Type)
2954 {
2955 case Sound_SET_PARAM_Ease_Target_Channel_A:
2956 {
2957 u32TargetChannel = AUDIO_EASE_CH_A;
2958 break;
2959 }
2960
2961 case Sound_SET_PARAM_Ease_Target_Channel_B:
2962 {
2963 u32TargetChannel = AUDIO_EASE_CH_B;
2964 break;
2965 }
2966
2967 default:
2968 {
2969 HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2970 status = FALSE;
2971 break;
2972 }
2973 }
2974 }
2975 else
2976 {
2977 u32TargetChannel = AUDIO_EASE_CH_NONE;
2978 }
2979
2980 switch (param1)
2981 {
2982 case AUDIO_PATH_4:
2983 {
2984 /* for Channel 5 */
2985 u32Mask = 0x000F;
2986 break;
2987 }
2988
2989 case AUDIO_PATH_5:
2990 {
2991 /* for Channel 6 */
2992 u32Mask = 0x0000F0;
2993 u32TargetChannel <<= 4;
2994 break;
2995 }
2996
2997 case AUDIO_PATH_6:
2998 {
2999 /* for Channel 7 */
3000 u32Mask = 0x000F00;
3001 u32TargetChannel <<= 8;
3002 break;
3003 }
3004
3005 case AUDIO_PATH_7:
3006 {
3007 /* for Channel 8 */
3008 u32Mask = 0x00F000;
3009 u32TargetChannel <<= 12;
3010 break;
3011 }
3012
3013 case AUDIO_PATH_0:
3014 {
3015 /* for Channel 1~4 (Multi-Channel) */
3016 u32Mask = 0x0F0000;
3017 u32TargetChannel <<= 16;
3018 break;
3019 }
3020
3021 default:
3022 {
3023 HALSOUND_ERROR("%s: invalid audio ease path %d\n", __FUNCTION__, param1);
3024 status = FALSE;
3025 break;
3026 }
3027 }
3028
3029 if (status == TRUE)
3030 {
3031 u32ChannelSetting = HAL_MAD2_Read_DSP_sram(u32DspPmEaseBase, DSP_MEM_TYPE_PM);
3032 u32ChannelSetting = (u32ChannelSetting & (~u32Mask)) | u32TargetChannel;
3033 HAL_MAD2_Write_DSP_sram(u32DspPmEaseBase, u32ChannelSetting, DSP_MEM_TYPE_PM);
3034 }
3035
3036 break;
3037 }
3038
3039 case Sound_SET_PARAM_Drc_Entry:
3040 {
3041 HAL_SOUND_SetDRCEntry((AUDIO_SOUNDEFFECT_TYPE) param1,(MS_U8)param2);
3042 status = TRUE;
3043 break;
3044 }
3045
3046 case Sound_SET_PARAM_VolFadingStep:
3047 {
3048 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingStep1, param1<<8, DSP_MEM_TYPE_PM);
3049 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingStep2, param2<<8, DSP_MEM_TYPE_PM);
3050 status = TRUE;
3051 break;
3052 }
3053
3054 case Sound_SET_PARAM_VolFadingCtrl:
3055 {
3056 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingCtrl, param1 , DSP_MEM_TYPE_PM);
3057 status = TRUE;
3058 break;
3059 }
3060
3061 case Sound_SET_PARAM_BalanceMask:
3062 {
3063 HAL_SOUND_SetBalanceMask(param1, param2);
3064 status = TRUE;
3065 break;
3066 }
3067
3068 case Sound_SET_PARAM_PhaseShiftMask:
3069 {
3070 HAL_SOUND_SetOutputPhaseShiftMask(param1, param2);
3071 status = TRUE;
3072 break;
3073 }
3074
3075 case Sound_SET_PARAM_InternalDelay_Ch1:
3076 case Sound_SET_PARAM_InternalDelay_Ch2:
3077 case Sound_SET_PARAM_InternalDelay_Ch3:
3078 case Sound_SET_PARAM_InternalDelay_Ch4:
3079 {
3080 if (param1 > MULTI_CH_INPUT_DLY_UPPER_BOUND)
3081 {
3082 HALSOUND_ERROR("Warning! Invalid value (%u), delay time should be less than %u ms. \r\n", (unsigned int)param1, MULTI_CH_INPUT_DLY_UPPER_BOUND);
3083 param1 = MULTI_CH_INPUT_DLY_UPPER_BOUND;
3084 }
3085
3086 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_multiChInputDelay, param1, DSP_MEM_TYPE_PM);
3087 status = TRUE;
3088
3089 break;
3090 }
3091
3092 case Sound_SET_PARAM_InternalDelay_Ch5:
3093 {
3094 if (param1 > CH5_INPUT_DLY_UPPER_BOUND)
3095 {
3096 HALSOUND_ERROR("Warning! Invalid value (%u), delay time should be less than %u ms. \r\n", (unsigned int)param1, CH5_INPUT_DLY_UPPER_BOUND);
3097 param1 = CH5_INPUT_DLY_UPPER_BOUND;
3098 }
3099
3100 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_ch5InputDelay, param1, DSP_MEM_TYPE_PM);
3101 status = TRUE;
3102
3103 break;
3104 }
3105
3106 case Sound_SET_PARAM_InternalDelay_Ch6:
3107 {
3108 if (param1 > CH6_INPUT_DLY_UPPER_BOUND)
3109 {
3110 HALSOUND_ERROR("Warning! Invalid value (%u), delay time should be less than %u ms. \r\n", (unsigned int)param1, CH6_INPUT_DLY_UPPER_BOUND);
3111 param1 = CH6_INPUT_DLY_UPPER_BOUND;
3112 }
3113
3114 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_ch6InputDelay, param1, DSP_MEM_TYPE_PM);
3115 status = TRUE;
3116
3117 break;
3118 }
3119
3120 case Sound_SET_PARAM_InternalDelay_Ch7:
3121 {
3122 status = TRUE;
3123
3124 break;
3125 }
3126
3127 case Sound_SET_PARAM_InternalDelay_Ch8:
3128 {
3129 status = TRUE;
3130
3131 break;
3132 }
3133
3134 default:
3135 {
3136 status = FALSE;
3137
3138 break;
3139 }
3140 }
3141 return(status);
3142 }
3143
3144 //******************************************************************************
3145 /// @brief \b Function \b Name: HAL_AUDIO_SOUND_SetParam()
3146 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3147 /// @return MS_BOOL \b : True / False
3148 //******************************************************************************
HAL_SND_GetParam(Sound_GET_PARAM_Type Type,MS_U16 param1)3149 MS_U16 HAL_SND_GetParam( Sound_GET_PARAM_Type Type, MS_U16 param1)
3150 {
3151 MS_U16 tmp=0;
3152 switch(Type)
3153 {
3154 case Sound_GET_PARAM_PreScale:
3155 tmp = HAL_SOUND_GetPreScale(param1); //param1: path
3156 break;
3157
3158 case Sound_GET_PARAM_Balance_L:
3159 tmp = HAL_SOUND_GetBalance_L(); // 0~0xFF
3160 break;
3161
3162 case Sound_GET_PARAM_Balance_R:
3163 tmp = HAL_SOUND_GetBalance_R(); // 0~0xFF
3164 break;
3165
3166 case Sound_GET_PARAM_EQ:
3167 tmp = HAL_SOUND_GetEq(param1); //param1: band 0~4
3168 break;
3169
3170 case Sound_GET_PARAM_Surround_XA:
3171 tmp = HAL_SOUND_GetSurroundXA();
3172 break;
3173
3174 case Sound_GET_PARAM_Surround_XB:
3175 tmp = HAL_SOUND_GetSurroundXB();
3176 break;
3177
3178 case Sound_GET_PARAM_Surround_XK:
3179 tmp = HAL_SOUND_GetSurroundXK();
3180 break;
3181
3182 case Sound_GET_PARAM_Surround_LPFGAIN:
3183 tmp = HAL_SOUND_GetSurroundLPFGain();
3184 break;
3185
3186 case Sound_GET_PARAM_Treble:
3187 tmp = HAL_SOUND_GetTreble();
3188 break;
3189
3190 case Sound_GET_PARAM_Bass:
3191 tmp = HAL_SOUND_GetBass();
3192 break;
3193
3194 case Sound_GET_PARAM_Avc_Mode:
3195 tmp = HAL_SOUND_GetAvcMode();
3196 break;
3197
3198 case Sound_GET_PARAM_Avc_Threshold:
3199 tmp = HAL_SOUND_GetAVCThreshold();
3200 break;
3201
3202 case Sound_GET_PARAM_Avc_AT:
3203 tmp = HAL_SOUND_GetAvcAT();
3204 break;
3205
3206 case Sound_GET_PARAM_Avc_RT:
3207 tmp = HAL_SOUND_GetAvcRT();
3208 break;
3209
3210 case Sound_GET_PARAM_AudioDelay:
3211 tmp = HAL_SOUND_GetCH1AudioDelay();
3212 break;
3213
3214 case Sound_GET_PARAM_DCOffet:
3215 tmp = HAL_AUDIO_ReadByte(0x2B51);
3216 tmp = ((MS_U16)HAL_AUDIO_ReadByte(0x2B50) |(tmp<<8));
3217 break;
3218
3219 case Sound_GET_PARAM_NR_Threshold:
3220 tmp = HAL_AUDIO_ReadByte(0x2D24);
3221 break;
3222
3223 case Sound_GET_PARAM_NR_Status:
3224 // tmp = (HAL_AUDIO_ReadByte(0x2A78) & 0x01);
3225 break;
3226
3227 case Sound_GET_PARAM_getSignal_Energy:
3228 // tmp = HAL_MAD_Read_DSP_sram(0x3F2B, DSP_MEM_TYPE_DM);
3229 break;
3230
3231 case Sound_GET_PARAM_EQ_Status:
3232 tmp = HAL_SOUND_GetEQ_Status();
3233 break;
3234
3235 case Sound_GET_PARAM_PEQ_Status:
3236 tmp = HAL_SOUND_GetPEQ_Status();
3237 break;
3238
3239 case Sound_GET_PARAM_Tone_Status:
3240 tmp = HAL_SOUND_GetTone_Status();
3241 break;
3242
3243 case Sound_GET_PARAM_AutoVolume_Status:
3244 tmp = HAL_SOUND_GetAutoVolume_Status();
3245 break;
3246
3247 case Sound_GET_PARAM_Surround_Status:
3248 tmp = HAL_SOUND_GetSurround_Status();
3249 break;
3250
3251 case Sound_GET_PARAM_Drc_Threshold:
3252 tmp = HAL_SOUND_GetDRCThreshold();
3253 break;
3254
3255 case Sound_GET_PARAM_DMAReader_Buffer_Addr:
3256 tmp = (MS_U16)(DMA_READER_TEMP_BUFFER_ADDR>>8);
3257 break;
3258
3259 case Sound_GET_PARAM_Ease_Type_A:
3260 case Sound_GET_PARAM_Ease_Type_B:
3261 {
3262 MS_U32 u32EaseType = AUDIO_EASE_TYPE_LINEAR;
3263 MS_U32 u32DspPmEaseBase = 0;
3264
3265 switch (Type)
3266 {
3267 case Sound_GET_PARAM_Ease_Type_A:
3268 {
3269 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3270 break;
3271 }
3272
3273 case Sound_GET_PARAM_Ease_Type_B:
3274 {
3275 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3276 break;
3277 }
3278
3279 default:
3280 {
3281 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3282 break;
3283 }
3284 }
3285
3286 u32EaseType = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 2), DSP_MEM_TYPE_PM);
3287
3288 switch (u32EaseType)
3289 {
3290 case AUDIO_EASE_TYPE_LINEAR:
3291 {
3292 tmp = E_AUDIO_EASE_TYPE_LINEAR;
3293 break;
3294 }
3295
3296 case AUDIO_EASE_TYPE_INCUBIC:
3297 {
3298 tmp = E_AUDIO_EASE_TYPE_INCUBIC;
3299 break;
3300 }
3301
3302 case AUDIO_EASE_TYPE_OUTCUBIC:
3303 {
3304 tmp = E_AUDIO_EASE_TYPE_OUTCUBIC;
3305 break;
3306 }
3307
3308 case AUDIO_EASE_TYPE_INOUTCUBIC:
3309 {
3310 tmp = E_AUDIO_EASE_TYPE_INOUTCUBIC;
3311 break;
3312 }
3313
3314 default:
3315 {
3316 HALSOUND_ERROR("%s: invalid audio ease type %u\n", __FUNCTION__, (unsigned int)u32EaseType);
3317 break;
3318 }
3319 }
3320
3321 break;
3322 }
3323
3324 case Sound_GET_PARAM_Ease_Duration_A:
3325 case Sound_GET_PARAM_Ease_Duration_B:
3326 {
3327 MS_U32 u32MiniSecond = 0;
3328 MS_U32 u32DspPmEaseBase = 0;
3329
3330 switch (Type)
3331 {
3332 case Sound_GET_PARAM_Ease_Duration_A:
3333 {
3334 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3335 break;
3336 }
3337
3338 case Sound_GET_PARAM_Ease_Duration_B:
3339 {
3340 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3341 break;
3342 }
3343
3344 default:
3345 {
3346 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3347 break;
3348 }
3349 }
3350
3351 u32MiniSecond = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 1), DSP_MEM_TYPE_PM) / 48;
3352 tmp = (MS_U16)u32MiniSecond;
3353
3354 break;
3355 }
3356
3357 case Sound_GET_PARAM_Ease_Gain_A:
3358 case Sound_GET_PARAM_Ease_Gain_B:
3359 {
3360 MS_U32 u32Value;
3361 MS_U32 u32DspPmEaseBase = 0;
3362
3363 switch (Type)
3364 {
3365 case Sound_GET_PARAM_Ease_Gain_A:
3366 {
3367 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3368 break;
3369 }
3370
3371 case Sound_GET_PARAM_Ease_Gain_B:
3372 {
3373 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3374 break;
3375 }
3376
3377 default:
3378 {
3379 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3380 break;
3381 }
3382 }
3383
3384 u32Value = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 3), DSP_MEM_TYPE_PM);
3385 tmp = (MS_U16)(u32Value >> 8);
3386
3387 break;
3388 }
3389
3390 case Sound_GET_PARAM_InternalDelay_Ch1:
3391 case Sound_GET_PARAM_InternalDelay_Ch2:
3392 case Sound_GET_PARAM_InternalDelay_Ch3:
3393 case Sound_GET_PARAM_InternalDelay_Ch4:
3394 {
3395 tmp = (MS_U16)HAL_MAD2_Read_DSP_sram(DSP2PmAddr_multiChInputDelay, DSP_MEM_TYPE_PM);
3396 break;
3397 }
3398
3399 case Sound_GET_PARAM_InternalDelay_Ch5:
3400 {
3401 tmp = (MS_U16)HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch5InputDelay, DSP_MEM_TYPE_PM);
3402 break;
3403 }
3404
3405 case Sound_GET_PARAM_InternalDelay_Ch6:
3406 {
3407 tmp = (MS_U16)HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch6InputDelay, DSP_MEM_TYPE_PM);
3408 break;
3409 }
3410
3411 case Sound_GET_PARAM_InternalDelay_Ch7:
3412 {
3413 break;
3414 }
3415
3416 case Sound_GET_PARAM_InternalDelay_Ch8:
3417 {
3418 break;
3419 }
3420
3421 default:
3422 break;
3423 }
3424 return tmp;
3425
3426 }
3427
3428
3429