summaryrefslogtreecommitdiff
path: root/tvapi/libtv/audio/audio_api.cpp (plain)
blob: 20db36bebe905242462381e5a2f882c9c2fdd29f
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <pthread.h>
6#include <fcntl.h>
7
8#include <android/log.h>
9#include <cutils/properties.h>
10
11#include "../tvsetting/CTvSetting.h"
12#include "../tvutils/tvutils.h"
13
14#include "audio_effect.h"
15#include "audio_android.h"
16#include "audio_android_effect.h"
17#include "audio_amaudio.h"
18
19#include "audio_api.h"
20
21#define LOG_TAG "audio_api"
22#include "CTvLog.h"
23
24static int mCustomEQGainBuf[] = { 0, 0, 0, 0, 0, 0 };
25
26static int mCurEQGainBuf[] = { 0, 0, 0, 0, 0, 0 };
27
28static int8_t mCurEQGainChBuf[] = { 0, 0, 0, 0, 0, 0 };
29
30static int mWallEffectValueBuf[] = { 0, 0, 1, 2, 2, 0 };
31
32static const int CC_MUTE_TYPE_KEY_MUTE = (0);
33static const int CC_MUTE_TYPE_SYS_MUTE = (1);
34
35
36//extern int audio_device_switch;
37int audio_device_switch = 1;//showboz
38
39CTvAudio::CTvAudio()
40{
41 mAudioMuteStatusForSystem = CC_AUDIO_UNMUTE;
42 mAudioMuteStatusForTv = CC_AUDIO_UNMUTE;
43 mCurAudioMasterVolume = CC_DEF_SOUND_VOL;
44 mCurAudioBalance = CC_DEF_SOUND_BALANCE_VAL;
45 mCurAudioSupperBassVolume = CC_DEF_SUPPERBASS_VOL;
46 mCurAudioSupperBassSwitch = CC_SWITCH_OFF;
47 mCurAudioSRSSurround = CC_SWITCH_OFF;
48 mCurAudioSrsDialogClarity = CC_SWITCH_OFF;
49 mCurAudioSrsTruBass = CC_SWITCH_OFF;
50 mCurAudioSPDIFSwitch = CC_SWITCH_ON;
51 mCurAudioSPDIFMode = CC_SPDIF_MODE_PCM;
52 mCurAudioBassVolume = CC_DEF_BASS_TREBLE_VOL;
53 mCurAudioTrebleVolume = CC_DEF_BASS_TREBLE_VOL;
54 mCurAudioSoundMode = CC_SOUND_MODE_END;
55 mCurAudioWallEffect = CC_SWITCH_OFF;
56 mCurAudioEQMode = CC_EQ_MODE_START;
57 mCustomAudioMasterVolume = CC_DEF_SOUND_VOL;
58 mCustomAudioBalance = CC_DEF_SOUND_BALANCE_VAL;
59 mCustomAudioSupperBassVolume = CC_DEF_SUPPERBASS_VOL;
60 mCustomAudioSupperBassSwitch = CC_SWITCH_OFF;
61 mCustomAudioSRSSurround = CC_SWITCH_OFF;
62 mCustomAudioSrsDialogClarity = CC_SWITCH_OFF;
63 mCustomAudioSrsTruBass = CC_SWITCH_OFF;
64 mCustomAudioBassVolume = CC_DEF_BASS_TREBLE_VOL;
65 mCustomAudioTrebleVolume = CC_DEF_BASS_TREBLE_VOL;
66 mCustomAudioSoundMode = CC_SOUND_MODE_END;
67 mCustomAudioWallEffect = CC_SWITCH_OFF;
68 mCustomAudioEQMode = CC_EQ_MODE_START;
69 mCustomAudioSoundEnhancementSwitch = CC_SWITCH_OFF;
70 mVolumeCompensationVal = CC_VOLUME_COMPENSATION_DEF_VAL;
71}
72
73CTvAudio::~CTvAudio()
74{
75
76}
77
78template<typename T1, typename T2>
79int AudioArrayCopy(T1 dst_buf[], T2 src_buf[], int copy_size)
80{
81 int i = 0;
82
83 for (i = 0; i < copy_size; i++) {
84 dst_buf[i] = src_buf[i];
85 }
86
87 return 0;
88}
89
90//Audio Mute
91int CTvAudio::SetAudioMuteForSystem(int muteOrUnmute)
92{
93 int ret = 0;
94 LOGD("SetAudioMuteForSystem sysMuteStats=%d, tvMuteStatus=%d, toMute=%d", mAudioMuteStatusForSystem, mAudioMuteStatusForTv, muteOrUnmute);
95 mAudioMuteStatusForSystem = muteOrUnmute;
96 ret |= mAudioAlsa.SetDacMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv, CC_DAC_MUTE_TYPE_EXTERNAL | CC_DAC_MUTE_TYPE_INTERNAL);
97 ret |= SetAudioSPDIFMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv);
98 return ret;
99}
100
101int CTvAudio::GetAudioMuteForSystem()
102{
103 return mAudioMuteStatusForSystem;
104}
105
106int CTvAudio::SetAudioMuteForTv(int Mute)
107{
108 int ret = 0;
109 mAudioMuteStatusForTv = Mute;
110 LOGD("SetAudioMuteForTv sysMuteStats=%d, tvMuteStatus=%d, toMute=%d", mAudioMuteStatusForSystem, mAudioMuteStatusForTv, Mute);
111 ret |= mAudioAlsa.SetDacMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv, CC_DAC_MUTE_TYPE_EXTERNAL | CC_DAC_MUTE_TYPE_INTERNAL);
112 ret |= SetAudioSPDIFMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv);
113 return ret;
114}
115
116int CTvAudio::GetAudioMuteForTv()
117{
118 return mAudioMuteStatusForTv;
119}
120
121int CTvAudio::SetAudioAVOutMute(int muteStatus)
122{
123 return mAudioAlsa.SetDacMute(muteStatus, CC_DAC_MUTE_TYPE_INTERNAL);
124}
125
126int CTvAudio::GetAudioAVOutMute()
127{
128 return CC_AUDIO_UNMUTE;
129}
130
131int CTvAudio::handleAudioSPDIFMute(int muteStatus)
132{
133 int set_val = 0;
134
135 if (muteStatus == CC_AUDIO_MUTE) {
136 set_val = CC_SPDIF_MUTE_ON;
137 } else if (muteStatus == CC_AUDIO_UNMUTE) {
138 set_val = CC_SPDIF_MUTE_OFF;
139 } else {
140 return -1;
141 }
142
143 return mAudioAlsa.SetSPDIFMute(set_val);
144}
145
146int CTvAudio::SetAudioSPDIFMute(int muteStatus)
147{
148 if (GetCurAudioSPDIFSwitch() == CC_SWITCH_OFF) {
149 muteStatus = CC_AUDIO_MUTE;
150 }
151
152 return handleAudioSPDIFMute(muteStatus);
153}
154
155int CTvAudio::GetAudioSPDIFMute()
156{
157 return CC_AUDIO_UNMUTE;
158}
159
160//Audio SPDIF switch
161int CTvAudio::SetAudioSPDIFSwitch(int tmp_val)
162{
163 int muteStatus = CC_AUDIO_UNMUTE;
164
165 mCurAudioSPDIFSwitch = tmp_val;
166
167 if (tmp_val == CC_SWITCH_OFF || mAudioMuteStatusForSystem == CC_AUDIO_MUTE || mAudioMuteStatusForTv == CC_AUDIO_MUTE) {
168 muteStatus = CC_AUDIO_MUTE;
169 } else {
170 muteStatus = CC_AUDIO_UNMUTE;
171 }
172
173 handleAudioSPDIFMute(muteStatus);
174 return 0;
175}
176
177int CTvAudio::GetCurAudioSPDIFSwitch()
178{
179 return mCurAudioSPDIFSwitch;
180}
181
182int CTvAudio::SaveCurAudioSPDIFSwitch(int tmp_val)
183{
184 int8_t tmp_ch = 0;
185 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
186 tmp_val = CC_SWITCH_ON;
187 }
188
189 mCurAudioSPDIFSwitch = tmp_val;
190 tmp_ch = tmp_val;
191 SSMSaveAudioSPDIFSwitchVal(tmp_ch);
192
193 return mCurAudioSPDIFSwitch;
194}
195
196int CTvAudio::LoadCurAudioSPDIFSwitch()
197{
198 int8_t tmp_ch = 0;
199 SSMReadAudioSPDIFSwitchVal(&tmp_ch);
200 mCurAudioSPDIFSwitch = tmp_ch;
201 if (mCurAudioSPDIFSwitch != CC_SWITCH_ON
202 && mCurAudioSPDIFSwitch != CC_SWITCH_OFF) {
203 SaveCurAudioSPDIFSwitch (CC_SWITCH_ON);
204 }
205 return mCurAudioSPDIFSwitch;
206}
207
208//Audio SPDIF Mode
209int CTvAudio::SetAudioSPDIFMode(int tmp_val)
210{
211 LOGD("%s : tmp_val = %d\n", __FUNCTION__, tmp_val);
212 mCurAudioSPDIFMode = tmp_val;
213
214 SetSPDIFMode(mCurAudioSPDIFMode);
215
216 return 0;
217}
218
219int CTvAudio::GetCurAudioSPDIFMode()
220{
221 return mCurAudioSPDIFMode;
222}
223
224int CTvAudio::SaveCurAudioSPDIFMode(int tmp_val)
225{
226 int8_t tmp_ch = 0;
227 if (tmp_val != CC_SPDIF_MODE_PCM && tmp_val != CC_SPDIF_MODE_RAW) {
228 tmp_val = CC_SPDIF_MODE_PCM;
229 }
230
231 mCurAudioSPDIFMode = tmp_val;
232 tmp_ch = tmp_val;
233 SSMSaveAudioSPDIFModeVal(tmp_ch);
234
235 return mCurAudioSPDIFMode;
236}
237
238int CTvAudio::LoadCurAudioSPDIFMode()
239{
240 int8_t tmp_ch = 0;
241 SSMReadAudioSPDIFModeVal(&tmp_ch);
242 mCurAudioSPDIFMode = tmp_ch;
243 if (mCurAudioSPDIFMode != CC_SPDIF_MODE_PCM
244 && mCurAudioSPDIFMode != CC_SPDIF_MODE_RAW) {
245 SaveCurAudioSPDIFMode (CC_SPDIF_MODE_PCM);
246 }
247 return mCurAudioSPDIFMode;
248}
249
250//Audio Master Volume
251int CTvAudio::SetAudioMasterVolume(int tmp_vol)
252{
253 const char *value;
254 if (tmp_vol < CC_MIN_SOUND_VOL || tmp_vol > CC_MAX_SOUND_VOL) {
255 tmp_vol = CC_DEF_SOUND_VOL;
256 }
257
258 mCustomAudioMasterVolume = tmp_vol;
259
260 //Volume Compensation
261 if (tmp_vol != CC_MIN_SOUND_VOL) {
262 tmp_vol += GetAudioVolumeCompensationVal();
263 }
264
265 if (tmp_vol > CC_MAX_SOUND_VOL) {
266 tmp_vol = CC_MAX_SOUND_VOL;
267 }
268
269 if (tmp_vol < CC_MIN_SOUND_VOL) {
270 tmp_vol = CC_MIN_SOUND_VOL;
271 }
272
273 mAudioAlsa.SetDacMainVolume(tmp_vol);
274 value = config_get_str ( "TV", "tvin.2d4G.headset.en", "null" );
275 if ( strcmp ( value, "enable" ) == 0 ) {
276 setAudioPcmPlaybackVolume(tmp_vol);
277 }
278 return 0;
279}
280
281int CTvAudio::GetAudioMasterVolume()
282{
283 return mCustomAudioMasterVolume;
284}
285
286int CTvAudio::GetCurAudioMasterVolume()
287{
288 return mCurAudioMasterVolume;
289}
290
291int CTvAudio::SaveCurAudioMasterVolume(int tmp_vol)
292{
293 int8_t tmp_ch = 0;
294
295 if (tmp_vol < CC_MIN_SOUND_VOL || tmp_vol > CC_MAX_SOUND_VOL) {
296 tmp_vol = CC_DEF_SOUND_VOL;
297 }
298
299 mCurAudioMasterVolume = tmp_vol;
300 tmp_ch = tmp_vol;
301 SSMSaveAudioMasterVolume(tmp_ch);
302
303 return mCurAudioMasterVolume;
304}
305
306int CTvAudio::LoadCurAudioMasterVolume()
307{
308 int8_t tmp_ch = 0;
309 SSMReadAudioMasterVolume(&tmp_ch);
310 mCurAudioMasterVolume = tmp_ch;
311 if (mCurAudioMasterVolume < CC_MIN_SOUND_VOL
312 || mCurAudioMasterVolume > CC_MAX_SOUND_VOL) {
313 SaveCurAudioMasterVolume (CC_DEF_SOUND_VOL);
314 }
315
316 mCustomAudioMasterVolume = mCurAudioMasterVolume;
317
318 return mCurAudioMasterVolume;
319}
320
321//Audio Balance
322int CTvAudio::SetAudioBalance(int tmp_val)
323{
324 if (tmp_val < CC_MIN_SOUND_BALANCE_VAL
325 || tmp_val > CC_MAX_SOUND_BALANCE_VAL) {
326 tmp_val = CC_DEF_SOUND_BALANCE_VAL;
327 }
328
329 mCustomAudioBalance = tmp_val;
330
331 if (mAudioAlsa.SetBalanceValue(mCustomAudioBalance) < 0) {
332 return SetAudioMasterVolume(GetAudioMasterVolume());
333 }
334
335 return 0;
336}
337
338int CTvAudio::GetAudioBalance()
339{
340 return mCustomAudioBalance;
341}
342
343int CTvAudio::GetCurAudioBalance()
344{
345 return mCurAudioBalance;
346}
347
348int CTvAudio::SaveCurAudioBalance(int tmp_val)
349{
350 int8_t tmp_ch = 0;
351
352 if (tmp_val < CC_MIN_SOUND_BALANCE_VAL
353 || tmp_val > CC_MAX_SOUND_BALANCE_VAL) {
354 tmp_val = CC_DEF_SOUND_BALANCE_VAL;
355 }
356
357 mCurAudioBalance = tmp_val;
358 tmp_ch = tmp_val;
359 SSMSaveAudioBalanceVal(tmp_ch);
360
361 return mCurAudioBalance;
362}
363
364int CTvAudio::LoadCurAudioBalance()
365{
366 int8_t tmp_ch = 0;
367 SSMReadAudioBalanceVal(&tmp_ch);
368 mCurAudioBalance = tmp_ch;
369 if (mCurAudioBalance < CC_MIN_SOUND_BALANCE_VAL
370 || mCurAudioBalance > CC_MAX_SOUND_BALANCE_VAL) {
371 SaveCurAudioBalance (CC_DEF_SOUND_BALANCE_VAL);
372 }
373
374 mCustomAudioBalance = mCurAudioBalance;
375
376 return mCurAudioBalance;
377}
378
379int CTvAudio::SetAudioVolumeCompensationVal(int tmp_vol_comp_val)
380{
381 int tmp_val = 0;
382 tmp_val = mVolumeCompensationVal;
383 mVolumeCompensationVal = tmp_vol_comp_val;
384 LOGD("%s, old vol comp value = %d, new vol comp value = %d.\n",
385 __FUNCTION__, tmp_val, tmp_vol_comp_val);
386 return tmp_val;
387}
388
389int CTvAudio::GetAudioVolumeCompensationVal()
390{
391 int tmp_vol_comp_val = 0;
392 tmp_vol_comp_val = mVolumeCompensationVal;
393 if (tmp_vol_comp_val < CC_VOLUME_COMPENSATION_MIN_VAL
394 || tmp_vol_comp_val > CC_VOLUME_COMPENSATION_MAX_VAL) {
395 tmp_vol_comp_val = CC_VOLUME_COMPENSATION_DEF_VAL;
396 }
397 LOGD("%s, vol comp value = %d, return value = %d.\n", __FUNCTION__,
398 mVolumeCompensationVal, tmp_vol_comp_val);
399
400 return tmp_vol_comp_val;
401}
402
403//Audio SupperBass Volume
404int CTvAudio::SetAudioSupperBassVolume(int tmp_vol)
405{
406 if (tmp_vol < CC_MIN_SUPPERBASS_VOL || tmp_vol > CC_MAX_SUPPERBASS_VOL) {
407 tmp_vol = CC_DEF_SUPPERBASS_VOL;
408 }
409
410 mCustomAudioSupperBassVolume = tmp_vol;
411
412 return mAudioAlsa.SetDacSupperBassVolume(mCustomAudioSupperBassVolume);
413}
414
415int CTvAudio::GetAudioSupperBassVolume()
416{
417 return mCustomAudioSupperBassVolume;
418}
419
420int CTvAudio::GetCurAudioSupperBassVolume()
421{
422 return mCurAudioSupperBassVolume;
423}
424
425int CTvAudio::SaveCurAudioSupperBassVolume(int tmp_vol)
426{
427 int8_t tmp_ch = 0;
428 if (tmp_vol < CC_MIN_SUPPERBASS_VOL || tmp_vol > CC_MAX_SUPPERBASS_VOL) {
429 tmp_vol = CC_DEF_SUPPERBASS_VOL;
430 }
431
432 mCurAudioSupperBassVolume = tmp_vol;
433 tmp_ch = tmp_vol;
434 SSMSaveAudioSupperBassVolume(tmp_ch);
435
436 return mCurAudioSupperBassVolume;
437}
438
439int CTvAudio::LoadCurAudioSupperBassVolume()
440{
441 int8_t tmp_ch = 0;
442 SSMReadAudioSupperBassVolume(&tmp_ch);
443 mCurAudioSupperBassVolume = tmp_ch;
444 if (mCurAudioSupperBassVolume < CC_MIN_SUPPERBASS_VOL
445 || mCurAudioSupperBassVolume > CC_MAX_SUPPERBASS_VOL) {
446 SaveCurAudioSupperBassVolume (CC_DEF_SUPPERBASS_VOL);
447 }
448
449 mCustomAudioSupperBassVolume = mCurAudioSupperBassVolume;
450
451 return mCurAudioSupperBassVolume;
452}
453
454//Audio SupperBass Switch
455int CTvAudio::SetAudioSupperBassSwitch(int tmp_val)
456{
457 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
458 tmp_val = CC_SWITCH_OFF;
459 }
460
461 mCustomAudioSupperBassSwitch = tmp_val;
462
463 if (GetAudioSupperBassSwitch() == CC_SWITCH_OFF) {
464 return mAudioAlsa.SetDacSupperBassVolume(CC_MIN_SUPPERBASS_VOL);
465 }
466
467 return mAudioAlsa.SetDacSupperBassVolume(GetAudioSupperBassVolume());
468}
469
470int CTvAudio::GetAudioSupperBassSwitch()
471{
472 if (GetAudioSupperBassSwitchDisableCFG() != 0) {
473 return CC_SWITCH_ON;
474 }
475
476 return mCustomAudioSupperBassSwitch;
477}
478
479int CTvAudio::GetCurAudioSupperBassSwitch()
480{
481 if (GetAudioSupperBassSwitchDisableCFG() != 0) {
482 return CC_SWITCH_ON;
483 }
484
485 return mCurAudioSupperBassSwitch;
486}
487
488int CTvAudio::SaveCurAudioSupperBassSwitch(int tmp_val)
489{
490 int8_t tmp_ch = 0;
491 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
492 tmp_val = CC_SWITCH_OFF;
493 }
494
495 mCurAudioSupperBassSwitch = tmp_val;
496 tmp_ch = tmp_val;
497 SSMSaveAudioSupperBassSwitch(tmp_ch);
498
499 HandleSupperBassSwicth();
500
501 return mCurAudioSupperBassSwitch;
502}
503
504int CTvAudio::LoadCurAudioSupperBassSwitch()
505{
506 int8_t tmp_ch = 0;
507 SSMReadAudioSupperBassSwitch(&tmp_ch);
508 mCurAudioSupperBassSwitch = tmp_ch;
509 if (mCurAudioSupperBassSwitch != CC_SWITCH_ON
510 && mCurAudioSupperBassSwitch != CC_SWITCH_OFF) {
511 SaveCurAudioSupperBassSwitch (CC_SWITCH_OFF);
512 }
513
514 mCustomAudioSupperBassSwitch = mCurAudioSupperBassSwitch;
515
516 HandleSupperBassSwicth();
517
518 return mCurAudioSupperBassSwitch;
519}
520
521void CTvAudio::HanldeSupperBassSRSSpeakerSize()
522{
523 int tmp_speakersize = -1;
524
525 if (GetAudioSrsTruBass() == CC_SWITCH_ON) {
526 if (GetAudioSupperBassSwitch() == CC_SWITCH_ON) {
527 tmp_speakersize = GetAudioSRSSupperBassTrubassSpeakerSizeCfg(1);
528 } else {
529 tmp_speakersize = GetAudioSRSSupperBassTrubassSpeakerSizeCfg(0);
530 }
531
532 if (tmp_speakersize >= 0) {
533 mAudioEffect.SetSrsTrubassSpeakerSize(tmp_speakersize);
534 }
535 }
536}
537
538void CTvAudio::HandleSupperBassSwicth()
539{
540 if (GetAudioSupperBassModuleDisableCFG() != 0) {
541 return;
542 }
543
544 HanldeSupperBassSRSSpeakerSize();
545}
546
547//Audio SRS Surround switch
548int CTvAudio::SetAudioSRSSurround(int tmp_val)
549{
550 if (GetAudioSRSModuleDisableCFG() == 1) {
551 return 0;
552 }
553
554 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
555 tmp_val = CC_SWITCH_OFF;
556 }
557
558 mCustomAudioSRSSurround = tmp_val;
559
560 RealSetSRS();
561 return 0;
562}
563
564int CTvAudio::GetAudioSRSSurround()
565{
566 if (GetAudioSRSModuleDisableCFG() == 1) {
567 return CC_SWITCH_OFF;
568 }
569
570 return mCustomAudioSRSSurround;
571}
572
573int CTvAudio::GetCurAudioSRSSurround()
574{
575 if (GetAudioSRSModuleDisableCFG() == 1) {
576 return CC_SWITCH_OFF;
577 }
578
579 return mCurAudioSRSSurround;
580}
581
582int CTvAudio::SaveCurAudioSrsSurround(int tmp_val)
583{
584 int8_t tmp_ch = 0;
585 if (GetAudioSRSModuleDisableCFG() == 1) {
586 return 0;
587 }
588
589 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
590 tmp_val = CC_SWITCH_OFF;
591 }
592
593 mCurAudioSRSSurround = tmp_val;
594 tmp_ch = tmp_val;
595 SSMSaveAudioSRSSurroundSwitch(tmp_ch);
596
597 return mCurAudioSRSSurround;
598}
599
600int CTvAudio::LoadCurAudioSrsSurround()
601{
602 int8_t tmp_ch = 0;
603 if (GetAudioSRSModuleDisableCFG() == 1) {
604 mCustomAudioSRSSurround = CC_SWITCH_OFF;
605 mCustomAudioSRSSurround = mCurAudioSRSSurround;
606 return mCurAudioSRSSurround;
607 }
608
609 SSMReadAudioSRSSurroundSwitch(&tmp_ch);
610 mCurAudioSRSSurround = tmp_ch;
611 if (mCurAudioSRSSurround != CC_SWITCH_ON
612 && mCurAudioSRSSurround != CC_SWITCH_OFF) {
613 SaveCurAudioSrsSurround (CC_SWITCH_OFF);
614 }
615
616 mCustomAudioSRSSurround = mCurAudioSRSSurround;
617
618 return mCurAudioSRSSurround;
619}
620
621//Audio SRS Dialog Clarity
622int CTvAudio::SetAudioSrsDialogClarity(int tmp_val)
623{
624 if (GetAudioSRSModuleDisableCFG() == 1) {
625 return 0;
626 }
627
628 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
629 tmp_val = CC_SWITCH_OFF;
630 }
631
632 mCustomAudioSrsDialogClarity = tmp_val;
633 RealSetSRS();
634
635 return 0;
636}
637
638int CTvAudio::GetAudioSrsDialogClarity()
639{
640 if (GetAudioSRSModuleDisableCFG() == 1) {
641 return CC_SWITCH_OFF;
642 }
643
644 return mCustomAudioSrsDialogClarity;
645}
646
647int CTvAudio::GetCurAudioSrsDialogClarity()
648{
649 if (GetAudioSRSModuleDisableCFG() == 1) {
650 return CC_SWITCH_OFF;
651 }
652
653 return mCurAudioSrsDialogClarity;
654}
655
656int CTvAudio::SaveCurAudioSrsDialogClarity(int tmp_val)
657{
658 int8_t tmp_ch = 0;
659 if (GetAudioSRSModuleDisableCFG() == 1) {
660 return 0;
661 }
662
663 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
664 tmp_val = CC_SWITCH_OFF;
665 }
666
667 mCurAudioSrsDialogClarity = tmp_val;
668 tmp_ch = tmp_val;
669 SSMSaveAudioSRSDialogClaritySwitch(tmp_ch);
670
671 return mCurAudioSrsDialogClarity;
672}
673
674int CTvAudio::LoadCurAudioSrsDialogClarity()
675{
676 int8_t tmp_ch = 0;
677 if (GetAudioSRSModuleDisableCFG() == 1) {
678 mCurAudioSrsDialogClarity = CC_SWITCH_OFF;
679 mCustomAudioSrsDialogClarity = mCurAudioSrsDialogClarity;
680 return mCurAudioSRSSurround;
681 }
682
683 SSMReadAudioSRSDialogClaritySwitch(&tmp_ch);
684 mCurAudioSrsDialogClarity = tmp_ch;
685 if (mCurAudioSrsDialogClarity != CC_SWITCH_ON
686 && mCurAudioSrsDialogClarity != CC_SWITCH_OFF) {
687 SaveCurAudioSrsDialogClarity (CC_SWITCH_OFF);
688 }
689
690 mCustomAudioSrsDialogClarity = mCurAudioSrsDialogClarity;
691
692 return mCurAudioSrsDialogClarity;
693}
694
695//Audio SRS Trubass
696int CTvAudio::SetAudioSrsTruBass(int tmp_val)
697{
698 if (GetAudioSRSModuleDisableCFG() == 1) {
699 return 0;
700 }
701
702 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
703 tmp_val = CC_SWITCH_OFF;
704 }
705
706 mCustomAudioSrsTruBass = tmp_val;
707 RealSetSRS();
708
709 return 0;
710}
711
712int CTvAudio::GetAudioSrsTruBass()
713{
714 if (GetAudioSRSModuleDisableCFG() == 1) {
715 return CC_SWITCH_OFF;
716 }
717
718 return mCustomAudioSrsTruBass;
719}
720
721int CTvAudio::GetCurAudioSrsTruBass()
722{
723 if (GetAudioSRSModuleDisableCFG() == 1) {
724 return CC_SWITCH_OFF;
725 }
726
727 return mCurAudioSrsTruBass;
728}
729
730int CTvAudio::SaveCurAudioSrsTruBass(int tmp_val)
731{
732 int8_t tmp_ch = 0;
733 if (GetAudioSRSModuleDisableCFG() == 1) {
734 return 0;
735 }
736
737 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
738 tmp_val = CC_SWITCH_OFF;
739 }
740
741 mCurAudioSrsTruBass = tmp_val;
742 tmp_ch = tmp_val;
743 SSMSaveAudioSRSTruBassSwitch(tmp_ch);
744
745 return mCurAudioSrsTruBass;
746}
747
748int CTvAudio::LoadCurAudioSrsTruBass()
749{
750 int8_t tmp_ch = 0;
751 if (GetAudioSRSModuleDisableCFG() == 1) {
752 mCurAudioSrsTruBass = CC_SWITCH_OFF;
753 mCustomAudioSrsTruBass = mCurAudioSrsTruBass;
754 return mCurAudioSRSSurround;
755 }
756
757 SSMReadAudioSRSTruBassSwitch(&tmp_ch);
758 mCurAudioSrsTruBass = tmp_ch;
759 if (mCurAudioSrsTruBass != CC_SWITCH_ON
760 && mCurAudioSrsTruBass != CC_SWITCH_OFF) {
761 SaveCurAudioSrsTruBass (CC_SWITCH_OFF);
762 }
763
764 mCustomAudioSrsTruBass = mCurAudioSrsTruBass;
765
766 return mCurAudioSrsTruBass;
767}
768
769void CTvAudio::RealSetSRS()
770{
771 int tmp_gain_val = 0;
772 int surround_switch = CC_SWITCH_OFF;
773 int trubass_switch = CC_SWITCH_OFF;
774 int dialogclarity_switch = CC_SWITCH_OFF;
775
776 surround_switch = GetAudioSRSSurround();
777 if (surround_switch == CC_SWITCH_ON) {
778 mAudioEffect.SetSrsSurroundSwitch(surround_switch);
779 tmp_gain_val = GetAudioSRSSourroundGainCfg();
780 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
781 mAudioEffect.SetSrsSurroundGain(tmp_gain_val);
782 }
783
784 trubass_switch = GetAudioSrsTruBass();
785 dialogclarity_switch = GetAudioSrsDialogClarity();
786 if (trubass_switch == CC_SWITCH_ON
787 && dialogclarity_switch == CC_SWITCH_OFF) {
788 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_ON);
789
790 tmp_gain_val = GetAudioSRSTrubassOnlyGainCfg();
791 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
792 mAudioEffect.SetSrsTruBassGain(tmp_gain_val);
793 }
794
795 mAudioEffect.SetSrsDialogClaritySwitch (CC_SWITCH_OFF);
796 } else if (trubass_switch == CC_SWITCH_OFF
797 && dialogclarity_switch == CC_SWITCH_ON) {
798 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_OFF);
799
800 mAudioEffect.SetSrsDialogClaritySwitch (CC_SWITCH_ON);
801
802 tmp_gain_val = GetAudioSRSDialogClarityOnlyDefinitionGainCfg();
803 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
804 mAudioEffect.SetSrsDefinitionGain(tmp_gain_val);
805 }
806
807 tmp_gain_val = GetAudioSRSDialogClarityOnlyGainCfg();
808 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
809 mAudioEffect.SetSrsDialogClarityGain(tmp_gain_val);
810 }
811 } else if (trubass_switch == CC_SWITCH_ON
812 && dialogclarity_switch == CC_SWITCH_ON) {
813 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_ON);
814
815 tmp_gain_val = GetAudioSRSTrubassAndDialogClarityTrubassGainCfg();
816 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
817 mAudioEffect.SetSrsTruBassGain(tmp_gain_val);
818 }
819
820 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_ON);
821
822 tmp_gain_val =
823 GetAudioSRSTrubassAndDialogClarityDefinitionGainCfg();
824 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
825 mAudioEffect.SetSrsDefinitionGain(tmp_gain_val);
826 }
827
828 tmp_gain_val =
829 GetAudioSRSTrubassAndDialogClarityDialogClarityGainCfg();
830 if (tmp_gain_val >= 0 && tmp_gain_val <= 100) {
831 mAudioEffect.SetSrsDialogClarityGain(tmp_gain_val);
832 }
833 } else if (trubass_switch == CC_SWITCH_OFF
834 && dialogclarity_switch == CC_SWITCH_OFF) {
835 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_OFF);
836 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_OFF);
837 }
838
839 HanldeSupperBassSRSSpeakerSize();
840 } else {
841 mAudioEffect.SetSrsSurroundSwitch (CC_SWITCH_OFF);
842 mAudioEffect.SetSrsTruBassSwitch(CC_SWITCH_OFF);
843 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_OFF);
844 }
845
846 SetDacGain();
847}
848
849int CTvAudio::SetDacGain()
850{
851 int main_gain_val = 0, sb_gain_val = 0;
852 int sourround_switch, trubass_switch, dialogclarity_switch;
853
854 sourround_switch = GetAudioSRSSurround();
855 trubass_switch = GetAudioSrsTruBass();
856 dialogclarity_switch = GetAudioSrsDialogClarity();
857
858 if (sourround_switch == CC_SWITCH_ON) {
859 main_gain_val = GetAudioSRSSourroundAmplifierMasterGainCfg();
860 sb_gain_val = GetAudioSRSSourroundAmplifierSupperBassGainCfg();
861
862 if (dialogclarity_switch == CC_SWITCH_ON
863 && trubass_switch == CC_SWITCH_OFF) {
864 main_gain_val = GetAudioSRSDialogClarityOnlyAmplifierMasterGainCfg();
865 sb_gain_val = GetAudioSRSDialogClarityOnlyAmplifierSupperBassGainCfg();
866 } else if (dialogclarity_switch == CC_SWITCH_OFF
867 && trubass_switch == CC_SWITCH_ON) {
868 main_gain_val = GetAudioSRSTrubassOnlyAmplifierMasterGainCfg();
869 sb_gain_val = GetAudioSRSTrubassOnlyAmplifierSupperBassGainCfg();
870 } else if (dialogclarity_switch == CC_SWITCH_ON
871 && trubass_switch == CC_SWITCH_ON) {
872 main_gain_val = GetAudioSRSTrubassAndDialogClarityAmplifierMasterGainCfg();
873 sb_gain_val = GetAudioSRSTrubassAndDialogClarityAmplifierSupperBassGainCfg();
874 }
875 }
876
877 mAudioAlsa.SetMainVolumeGain(main_gain_val);
878 mAudioAlsa.SetSupperBassVolumeGain(sb_gain_val);
879
880 return 0;
881}
882
883//Audio Bass
884int CTvAudio::SetAudioBassVolume(int tmp_vol)
885{
886 int nMinBassVol = 0, nMaxBassVol = 0;
887
888 nMinBassVol = GetBassUIMinGainVal();
889 nMaxBassVol = GetBassUIMaxGainVal();
890
891 if (tmp_vol < nMinBassVol || tmp_vol > nMaxBassVol) {
892 tmp_vol = (nMaxBassVol + nMinBassVol) / 2;
893 }
894
895 mCustomAudioBassVolume = tmp_vol;
896
897 tmp_vol = MappingTrebleBassAndEqualizer(GetAudioBassVolume(), 0,
898 nMinBassVol, nMaxBassVol);
899
900 return SetSpecialIndexEQGain(CC_EQ_BASS_IND, tmp_vol);
901}
902
903int CTvAudio::GetAudioBassVolume()
904{
905 return mCustomAudioBassVolume;
906}
907
908int CTvAudio::GetCurAudioBassVolume()
909{
910 return mCurAudioBassVolume;
911}
912
913int CTvAudio::SaveCurAudioBassVolume(int tmp_vol)
914{
915 int nMinBassVol = 0, nMaxBassVol = 0;
916
917 nMinBassVol = GetBassUIMinGainVal();
918 nMaxBassVol = GetBassUIMaxGainVal();
919
920 if (tmp_vol < nMinBassVol || tmp_vol > nMaxBassVol) {
921 tmp_vol = (nMaxBassVol + nMinBassVol) / 2;
922 }
923
924 RealSaveCurAudioBassVolume(tmp_vol, 1);
925
926 tmp_vol = MappingTrebleBassAndEqualizer(GetCurAudioBassVolume(), 0,
927 nMinBassVol, nMaxBassVol);
928
929 return SaveSpecialIndexEQGain(CC_EQ_BASS_IND, tmp_vol);
930}
931
932int CTvAudio::RealSaveCurAudioBassVolume(int tmp_vol, int sound_mode_judge)
933{
934 int8_t tmp_ch = 0;
935 mCurAudioBassVolume = tmp_vol;
936 tmp_ch = tmp_vol;
937 SSMSaveAudioBassVolume(tmp_ch);
938
939 if (sound_mode_judge == 1) {
940 if (GetAudioSoundMode() != CC_SOUND_MODE_USER) {
941 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
942 mCustomAudioSoundMode = mCurAudioSoundMode;
943 }
944 }
945
946 return mCurAudioBassVolume;
947}
948
949int CTvAudio::LoadCurAudioBassVolume()
950{
951 int nMinBassVol = 0, nMaxBassVol = 0;
952 int8_t tmp_ch = 0;
953
954 nMinBassVol = GetBassUIMinGainVal();
955 nMaxBassVol = GetBassUIMaxGainVal();
956
957 SSMReadAudioBassVolume(&tmp_ch);
958 mCurAudioBassVolume = tmp_ch;
959 if (mCurAudioBassVolume < nMinBassVol
960 || mCurAudioBassVolume > nMaxBassVol) {
961 RealSaveCurAudioBassVolume((nMaxBassVol + nMinBassVol) / 2, 0);
962 }
963
964 mCustomAudioBassVolume = mCurAudioBassVolume;
965
966 return mCurAudioBassVolume;
967}
968
969//Audio Treble
970int CTvAudio::SetAudioTrebleVolume(int tmp_vol)
971{
972 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
973
974 nMinTrebleVol = GetTrebleUIMinGainVal();
975 nMaxTrebleVol = GetTrebleUIMaxGainVal();
976
977 if (tmp_vol < nMinTrebleVol || tmp_vol > nMaxTrebleVol) {
978 tmp_vol = (nMaxTrebleVol + nMinTrebleVol) / 2;
979 }
980
981 mCustomAudioTrebleVolume = tmp_vol;
982
983 tmp_vol = MappingTrebleBassAndEqualizer(GetAudioTrebleVolume(), 0,
984 nMinTrebleVol, nMaxTrebleVol);
985
986 return SetSpecialIndexEQGain(CC_EQ_TREBLE_IND, tmp_vol);
987}
988
989int CTvAudio::GetAudioTrebleVolume()
990{
991 return mCustomAudioTrebleVolume;
992}
993
994int CTvAudio::GetCurAudioTrebleVolume()
995{
996 return mCurAudioTrebleVolume;
997}
998
999int CTvAudio::SaveCurAudioTrebleVolume(int tmp_vol)
1000{
1001 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
1002
1003 nMinTrebleVol = GetTrebleUIMinGainVal();
1004 nMaxTrebleVol = GetTrebleUIMaxGainVal();
1005
1006 if (tmp_vol < nMinTrebleVol || tmp_vol > nMaxTrebleVol) {
1007 tmp_vol = (nMaxTrebleVol + nMinTrebleVol) / 2;
1008 }
1009
1010 RealSaveCurAudioTrebleVolume(tmp_vol, 1);
1011
1012 tmp_vol = MappingTrebleBassAndEqualizer(GetCurAudioTrebleVolume(), 0,
1013 nMinTrebleVol, nMaxTrebleVol);
1014
1015 return SaveSpecialIndexEQGain(CC_EQ_TREBLE_IND, tmp_vol);
1016}
1017
1018int CTvAudio::RealSaveCurAudioTrebleVolume(int tmp_vol, int sound_mode_judge)
1019{
1020 int8_t tmp_ch = 0;
1021 mCurAudioTrebleVolume = tmp_vol;
1022 tmp_ch = tmp_vol;
1023 SSMSaveAudioTrebleVolume(tmp_ch);
1024
1025 if (sound_mode_judge == 1) {
1026 if (GetAudioSoundMode() != CC_SOUND_MODE_USER) {
1027 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
1028 mCustomAudioSoundMode = mCurAudioSoundMode;
1029 }
1030 }
1031
1032 return mCurAudioTrebleVolume;
1033}
1034
1035int CTvAudio::LoadCurAudioTrebleVolume()
1036{
1037 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
1038 int8_t tmp_ch = 0;
1039
1040 nMinTrebleVol = GetTrebleUIMinGainVal();
1041 nMaxTrebleVol = GetTrebleUIMaxGainVal();
1042
1043 SSMReadAudioTrebleVolume(&tmp_ch);
1044 mCurAudioTrebleVolume = tmp_ch;
1045 if (mCurAudioTrebleVolume < nMinTrebleVol
1046 || mCurAudioTrebleVolume > nMaxTrebleVol) {
1047 RealSaveCurAudioTrebleVolume((nMaxTrebleVol + nMinTrebleVol) / 2, 0);
1048 }
1049
1050 mCustomAudioTrebleVolume = mCurAudioTrebleVolume;
1051
1052 return mCurAudioTrebleVolume;
1053}
1054
1055//Audio Sound Mode
1056int CTvAudio::SetAudioSoundMode(int tmp_val)
1057{
1058 if (tmp_val < CC_SOUND_MODE_START || tmp_val > CC_SOUND_MODE_END) {
1059 tmp_val = CC_SOUND_MODE_STD;
1060 }
1061
1062 LOGD("%s : sound mode = %d\n", __FUNCTION__, tmp_val);
1063
1064 mCustomAudioSoundMode = tmp_val;
1065 SetSpecialModeEQGain(mCustomAudioSoundMode);
1066
1067 HandleTrebleBassVolume();
1068
1069 return 0;
1070}
1071
1072int CTvAudio::GetAudioSoundMode()
1073{
1074 return mCustomAudioSoundMode;
1075}
1076
1077int CTvAudio::GetCurAudioSoundMode()
1078{
1079 return mCurAudioSoundMode;
1080}
1081
1082int CTvAudio::SaveCurAudioSoundMode(int tmp_val)
1083{
1084 int8_t tmp_ch = 0;
1085 if (tmp_val < CC_SOUND_MODE_START || tmp_val > CC_SOUND_MODE_END) {
1086 tmp_val = CC_SOUND_MODE_STD;
1087 }
1088
1089 mCurAudioSoundMode = tmp_val;
1090 tmp_ch = tmp_val;
1091 SSMSaveAudioSoundModeVal(tmp_ch);
1092
1093 return mCurAudioSoundMode;
1094}
1095
1096int CTvAudio::LoadCurAudioSoundMode()
1097{
1098 int8_t tmp_ch = 0;
1099 SSMReadAudioSoundModeVal(&tmp_ch);
1100 mCurAudioSoundMode = tmp_ch;
1101 if (mCurAudioSoundMode < CC_SOUND_MODE_START
1102 || mCurAudioSoundMode > CC_SOUND_MODE_END) {
1103 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
1104 }
1105
1106 mCustomAudioSoundMode = mCurAudioSoundMode;
1107
1108 return mCurAudioSoundMode;
1109}
1110
1111int CTvAudio::HandleTrebleBassVolume()
1112{
1113 int tmp_vol = 0;
1114 int tmpEQGainBuf[128] = { 0 };
1115 int8_t tmp_ch = 0;
1116
1117 GetCustomEQGain(tmpEQGainBuf);
1118
1119 tmp_vol = MappingTrebleBassAndEqualizer(tmpEQGainBuf[CC_EQ_TREBLE_IND], 1,
1120 GetTrebleUIMinGainVal(), GetTrebleUIMaxGainVal());
1121 mCustomAudioTrebleVolume = tmp_vol;
1122 mCurAudioTrebleVolume = mCustomAudioTrebleVolume;
1123 tmp_ch = mCustomAudioTrebleVolume;
1124 SSMSaveAudioTrebleVolume(tmp_ch);
1125
1126 tmp_vol = MappingTrebleBassAndEqualizer(tmpEQGainBuf[CC_EQ_BASS_IND], 1,
1127 GetBassUIMinGainVal(), GetBassUIMaxGainVal());
1128 mCustomAudioBassVolume = tmp_vol;
1129 mCurAudioBassVolume = mCustomAudioBassVolume;
1130 tmp_ch = mCustomAudioBassVolume;
1131 SSMSaveAudioBassVolume(tmp_ch);
1132
1133 return 0;
1134}
1135
1136//Audio Wall Effect
1137int CTvAudio::SetAudioWallEffect(int tmp_val)
1138{
1139 int tmp_treble_val;
1140 int tmp_type = 0;
1141
1142 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
1143 tmp_val = CC_SWITCH_OFF;
1144 }
1145
1146 mCustomAudioWallEffect = tmp_val;
1147
1148 tmp_type = GetAudioWallEffectTypeCfg();
1149 if (tmp_type == 0) {
1150 SetCustomEQGain();
1151 } else if (tmp_type == 1) {
1152 mAudioAlsa.SetDacEQMode(tmp_val);
1153 }
1154
1155 return 0;
1156}
1157
1158int CTvAudio::GetAudioWallEffect()
1159{
1160 return mCustomAudioWallEffect;
1161}
1162
1163int CTvAudio::GetCurAudioWallEffect()
1164{
1165 return mCurAudioWallEffect;
1166}
1167
1168int CTvAudio::SaveCurAudioWallEffect(int tmp_val)
1169{
1170 int8_t tmp_ch = 0;
1171 if (tmp_val != CC_SWITCH_ON && tmp_val != CC_SWITCH_OFF) {
1172 tmp_val = CC_SWITCH_OFF;
1173 }
1174
1175 mCurAudioWallEffect = tmp_val;
1176 tmp_ch = tmp_val;
1177 SSMSaveAudioWallEffectSwitch(tmp_ch);
1178
1179 return mCurAudioWallEffect;
1180}
1181
1182int CTvAudio::LoadCurAudioWallEffect()
1183{
1184 int8_t tmp_ch = 0;
1185 SSMReadAudioWallEffectSwitch(&tmp_ch);
1186 mCurAudioWallEffect = tmp_ch;
1187 if (mCurAudioWallEffect != CC_SWITCH_ON
1188 && mCurAudioWallEffect != CC_SWITCH_OFF) {
1189 SaveCurAudioWallEffect (CC_SWITCH_OFF);
1190 }
1191
1192 mCustomAudioWallEffect = mCurAudioWallEffect;
1193
1194 return mCurAudioWallEffect;
1195}
1196
1197//Audio EQ Mode
1198int CTvAudio::SetAudioEQMode(int tmp_val)
1199{
1200 if (tmp_val < CC_EQ_MODE_START || tmp_val > CC_EQ_MODE_END) {
1201 tmp_val = CC_EQ_MODE_START;
1202 }
1203
1204 mCustomAudioEQMode = tmp_val;
1205
1206 return 0;
1207}
1208
1209int CTvAudio::GetAudioEQMode()
1210{
1211 return mCustomAudioEQMode;
1212}
1213
1214int CTvAudio::GetCurAudioEQMode()
1215{
1216 return mCurAudioEQMode;
1217}
1218
1219int CTvAudio::SaveCurAudioEQMode(int tmp_val)
1220{
1221 int8_t tmp_ch = 0;
1222 if (tmp_val < CC_EQ_MODE_START || tmp_val > CC_EQ_MODE_END) {
1223 tmp_val = CC_EQ_MODE_START;
1224 }
1225
1226 mCurAudioEQMode = tmp_val;
1227 tmp_ch = tmp_val;
1228 SSMSaveAudioEQModeVal(tmp_ch);
1229
1230 return tmp_val;
1231}
1232
1233int CTvAudio::LoadCurAudioEQMode()
1234{
1235 int8_t tmp_ch = 0;
1236 SSMReadAudioEQModeVal(&tmp_ch);
1237 mCurAudioEQMode = tmp_ch;
1238 if (mCurAudioEQMode < CC_EQ_MODE_START
1239 || mCurAudioEQMode > CC_EQ_MODE_END) {
1240 SaveCurAudioEQMode (CC_EQ_MODE_START);
1241 }
1242
1243 mCustomAudioEQMode = mCurAudioEQMode;
1244
1245 return mCurAudioEQMode;
1246}
1247
1248//Audio EQ Gain
1249int CTvAudio::GetAudioEQRange(int range_buf[])
1250{
1251 range_buf[0] = GetEQMinGainVal();
1252 range_buf[1] = GetEQMaxGainVal();
1253 return 0;
1254}
1255
1256int CTvAudio::GetAudioEQBandCount()
1257{
1258 return mAudioEffect.GetEQBandCount();
1259}
1260
1261int CTvAudio::SetAudioEQGain(int gain_buf[])
1262{
1263 return AudioSetEQGain(gain_buf);
1264}
1265
1266int CTvAudio::GetAudioEQGain(int gain_buf[])
1267{
1268 return GetCustomEQGain(gain_buf);
1269}
1270
1271int CTvAudio::GetCurAudioEQGain(int gain_buf[])
1272{
1273 RealReadCurAudioEQGain(gain_buf);
1274 return 0;
1275}
1276
1277int CTvAudio::SaveCurAudioEQGain(int gain_buf[])
1278{
1279 return RealSaveCurAudioEQGain(gain_buf, 1);
1280}
1281
1282int CTvAudio::RealReadCurAudioEQGain(int gain_buf[])
1283{
1284 if (CheckAudioEQGain(mCurEQGainBuf, 0) < 0) {
1285 RestoreToAudioDefEQGain(mCurEQGainBuf);
1286 }
1287
1288 AudioArrayCopy(gain_buf, mCurEQGainBuf, GetAudioEQBandCount());
1289
1290 return 0;
1291}
1292
1293int CTvAudio::RealSaveCurAudioEQGain(int gain_buf[], int sound_mode_judge)
1294{
1295 if (CheckAudioEQGain(gain_buf, 0) < 0) {
1296 RestoreToAudioDefEQGain(gain_buf);
1297 SetAudioEQGain(gain_buf);
1298 return -1;
1299 }
1300
1301 AudioArrayCopy(mCurEQGainBuf, gain_buf, GetAudioEQBandCount());
1302 AudioArrayCopy(mCurEQGainChBuf, gain_buf, GetAudioEQBandCount());
1303 SSMSaveAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
1304
1305 if (sound_mode_judge == 1) {
1306 HandleTrebleBassVolume();
1307 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
1308 mCustomAudioSoundMode = mCurAudioSoundMode;
1309 }
1310
1311 return 0;
1312}
1313
1314int CTvAudio::LoadCurAudioEQGain()
1315{
1316 int i = 0;
1317
1318 SSMReadAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
1319 AudioArrayCopy(mCurEQGainBuf, mCurEQGainChBuf, GetAudioEQBandCount());
1320
1321 for (i = 0; i < GetAudioEQBandCount(); i++) {
1322 if (mCurEQGainBuf[i] & 0x80) {
1323 mCurEQGainBuf[i] = mCurEQGainBuf[i] - 256;
1324 }
1325 }
1326
1327 if (CheckAudioEQGain(mCurEQGainBuf, 0) < 0) {
1328 RestoreToAudioDefEQGain(mCurEQGainBuf);
1329 SetAudioEQGain(mCurEQGainBuf);
1330 return -1;
1331 }
1332
1333 return 0;
1334}
1335
1336int CTvAudio::SetAudioEQSwitch(int switch_val)
1337{
1338 return mAudioEffect.SetEQSwitch(switch_val);
1339}
1340
1341int CTvAudio::GetEQMinGainVal()
1342{
1343 int min_val = 0, max_val = 0;
1344
1345 if (GetAudioEQGainRangeCFG(&min_val, &max_val) < 0) {
1346 return mAudioEffect.GetEQMinGain();
1347 }
1348
1349 return min_val;
1350}
1351
1352int CTvAudio::GetEQMaxGainVal()
1353{
1354 int min_val = 0, max_val = 0;
1355
1356 if (GetAudioEQGainRangeCFG(&min_val, &max_val) < 0) {
1357 return mAudioEffect.GetEQMaxGain();
1358 }
1359
1360 return max_val;
1361}
1362
1363int CTvAudio::GetEQUIMinGainVal()
1364{
1365 int min_val = 0, max_val = 0;
1366
1367 if (GetAudioEQUIGainRangeCFG(&min_val, &max_val) < 0) {
1368 return CC_EQ_DEF_UI_MIN_GAIN;
1369 }
1370
1371 return min_val;
1372}
1373
1374int CTvAudio::GetEQUIMaxGainVal()
1375{
1376 int min_val = 0, max_val = 0;
1377
1378 if (GetAudioEQUIGainRangeCFG(&min_val, &max_val) < 0) {
1379 return CC_EQ_DEF_UI_MAX_GAIN;
1380 }
1381
1382 return max_val;
1383}
1384
1385int CTvAudio::GetBassUIMinGainVal()
1386{
1387 return 0;
1388}
1389
1390int CTvAudio::GetBassUIMaxGainVal()
1391{
1392 return 100;
1393}
1394
1395int CTvAudio::GetTrebleUIMinGainVal()
1396{
1397 return 0;
1398}
1399
1400int CTvAudio::GetTrebleUIMaxGainVal()
1401{
1402 return 100;
1403}
1404
1405int CTvAudio::MappingLine(int map_val, int src_min, int src_max, int dst_min,
1406 int dst_max)
1407{
1408 if (dst_min < 0) {
1409 return (map_val - (src_max + src_min) / 2) * (dst_max - dst_min)
1410 / (src_max - src_min);
1411 } else {
1412 return (map_val - src_min) * (dst_max - dst_min) / (src_max - src_min);
1413 }
1414}
1415
1416int CTvAudio::MappingTrebleBassAndEqualizer(int tmp_vol, int direct, int tb_min,
1417 int tb_max)
1418{
1419 int tmp_ret = 0;
1420
1421 if (direct == 0) {
1422 tmp_ret = MappingLine(tmp_vol, tb_min, tb_max, GetEQUIMinGainVal(),
1423 GetEQUIMaxGainVal());
1424 } else {
1425 tmp_ret = MappingLine(tmp_vol, GetEQUIMinGainVal(), GetEQUIMaxGainVal(),
1426 tb_min, tb_max);
1427 }
1428
1429 LOGD("%s, tmp_vol = %d, direct = %d, tmp_ret = %d\n", __FUNCTION__, tmp_vol,
1430 direct, tmp_ret);
1431
1432 return tmp_ret;
1433}
1434
1435int CTvAudio::MappingEQGain(int src_gain_buf[], int dst_gain_buf[], int direct)
1436{
1437 int i = 0;
1438 int nMinUIVal = 0, nMaxUIVal = 0, nMinVal = 0, nMaxVal = 0;
1439
1440 nMinUIVal = GetEQUIMinGainVal();
1441 nMaxUIVal = GetEQUIMaxGainVal();
1442 nMinVal = GetEQMinGainVal();
1443 nMaxVal = GetEQMaxGainVal();
1444
1445 if (CheckAudioEQGain(src_gain_buf, direct) < 0) {
1446 return -1;
1447 }
1448
1449 if (nMinUIVal >= nMinVal && nMaxUIVal <= nMaxVal) {
1450 for (i = 0; i < GetAudioEQBandCount(); i++) {
1451 dst_gain_buf[i] = src_gain_buf[i];
1452 }
1453 } else {
1454 for (i = 0; i < GetAudioEQBandCount(); i++) {
1455 if (direct == 0) {
1456 dst_gain_buf[i] = MappingLine(src_gain_buf[i], nMinUIVal,
1457 nMaxUIVal, nMinVal, nMaxVal);
1458 } else {
1459 dst_gain_buf[i] = MappingLine(src_gain_buf[i], nMinVal, nMaxVal,
1460 nMinUIVal, nMaxUIVal);
1461 }
1462 }
1463 }
1464
1465 return 0;
1466}
1467
1468int CTvAudio::RestoreToAudioDefEQGain(int gain_buf[])
1469{
1470 int i = 0;
1471 int *tmpEQPresetBufPtr = GetAudioEQPresetBufferPtr();
1472
1473 for (i = 0; i < GetAudioEQBandCount(); i++) {
1474 gain_buf[i] = (GetEQUIMaxGainVal() + GetEQUIMinGainVal()) / 2;
1475 }
1476
1477 AudioArrayCopy(mCurEQGainBuf, gain_buf, GetAudioEQBandCount());
1478 AudioArrayCopy(mCurEQGainChBuf, gain_buf, GetAudioEQBandCount());
1479 SSMSaveAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
1480
1481 HandleTrebleBassVolume();
1482 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
1483 mCustomAudioSoundMode = mCurAudioSoundMode;
1484
1485 return 0;
1486}
1487
1488int CTvAudio::CheckAudioEQGain(int gain_buf[], int direct)
1489{
1490 int i;
1491
1492 if (direct == 0) {
1493 for (i = 0; i < GetAudioEQBandCount(); i++) {
1494 if (gain_buf[i] < GetEQUIMinGainVal()
1495 || gain_buf[i] > GetEQUIMaxGainVal()) {
1496 return -1;
1497 }
1498 }
1499 } else {
1500 for (i = 0; i < GetAudioEQBandCount(); i++) {
1501 if (gain_buf[i] < GetEQMinGainVal()
1502 || gain_buf[i] > GetEQMaxGainVal()) {
1503 return -1;
1504 }
1505 }
1506 }
1507
1508 return 0;
1509}
1510
1511int CTvAudio::GetCustomEQGain(int gain_buf[])
1512{
1513 AudioArrayCopy(gain_buf, mCustomEQGainBuf, GetAudioEQBandCount());
1514 return 0;
1515}
1516
1517int CTvAudio::SetCustomEQGain()
1518{
1519 int tmpEQGainBuf[128] = { 0 };
1520
1521 if (MappingEQGain(mCustomEQGainBuf, tmpEQGainBuf, 0) < 0) {
1522 return -1;
1523 }
1524
1525 return RealSetEQGain(tmpEQGainBuf);
1526}
1527
1528int CTvAudio::AudioSetEQGain(int gain_buf[])
1529{
1530 int tmpEQGainBuf[128] = { 0 };
1531
1532 AudioArrayCopy(mCustomEQGainBuf, gain_buf, GetAudioEQBandCount());
1533
1534 if (MappingEQGain(mCustomEQGainBuf, tmpEQGainBuf, 0) < 0) {
1535 return -1;
1536 }
1537
1538 return RealSetEQGain(tmpEQGainBuf);
1539}
1540
1541int CTvAudio::handleEQGainBeforeSet(int src_buf[], int dst_buf[])
1542{
1543 int i = 0, nMinGain, nMaxGain, handle_wall_effect_flag;
1544
1545 nMinGain = GetEQMinGainVal();
1546 nMaxGain = GetEQMaxGainVal();
1547
1548 handle_wall_effect_flag = 0;
1549
1550 if (GetAudioWallEffect() == CC_SWITCH_ON) {
1551 if (GetAudioWallEffectTypeCfg() == 0) {
1552 handle_wall_effect_flag = 1;
1553 }
1554 }
1555
1556 if (handle_wall_effect_flag) {
1557 for (i = 0; i < GetAudioEQBandCount(); i++) {
1558 dst_buf[i] = mWallEffectValueBuf[i] + src_buf[i];
1559 }
1560 } else {
1561 for (i = 0; i < GetAudioEQBandCount(); i++) {
1562 dst_buf[i] = src_buf[i];
1563 }
1564 }
1565
1566 for (i = 0; i < GetAudioEQBandCount(); i++) {
1567 if (dst_buf[i] < nMinGain) {
1568 dst_buf[i] = nMinGain;
1569 }
1570
1571 if (dst_buf[i] > nMaxGain) {
1572 dst_buf[i] = nMaxGain;
1573 }
1574
1575 LOGD("%s, dst_buf[%d] = %d\n", __FUNCTION__, i, dst_buf[i]);
1576 }
1577
1578 return 0;
1579}
1580
1581int CTvAudio::RealSetEQGain(int gain_buf[])
1582{
1583 int tmpEQGainBuf[128] = { 0 };
1584
1585 if (CheckAudioEQGain(gain_buf, 1) < 0) {
1586 return -1;
1587 }
1588
1589 handleEQGainBeforeSet(gain_buf, tmpEQGainBuf);
1590
1591 mAudioEffect.SetEQValue(tmpEQGainBuf);
1592
1593 return 0;
1594}
1595
1596int CTvAudio::SetSpecialModeEQGain(int tmp_val)
1597{
1598 int i = 0;
1599 int *tmpEQPresetBufPtr = GetAudioEQPresetBufferPtr();
1600 int tmpEQGainBuf[128] = { 0 };
1601
1602 if (tmp_val < CC_SOUND_MODE_START || tmp_val > CC_SOUND_MODE_END) {
1603 tmp_val = CC_SOUND_MODE_STD;
1604 }
1605
1606 if (tmp_val == CC_SOUND_MODE_USER) {
1607 RealReadCurAudioEQGain(tmpEQGainBuf);
1608 } else {
1609 AudioArrayCopy(tmpEQGainBuf,
1610 tmpEQPresetBufPtr + tmp_val * GetAudioEQBandCount(),
1611 GetAudioEQBandCount());
1612
1613 for (i = 0; i < GetAudioEQBandCount(); i++) {
1614 if (GetEQUIMinGainVal() != CC_EQ_DEF_UI_MIN_GAIN
1615 || GetEQUIMaxGainVal() != CC_EQ_DEF_UI_MAX_GAIN) {
1616 tmpEQGainBuf[i] = MappingLine(tmpEQGainBuf[i],
1617 CC_EQ_DEF_UI_MIN_GAIN, CC_EQ_DEF_UI_MAX_GAIN,
1618 GetEQUIMinGainVal(), GetEQUIMaxGainVal());
1619 }
1620 }
1621 }
1622
1623 AudioSetEQGain(tmpEQGainBuf);
1624
1625 return tmp_val;
1626}
1627
1628int CTvAudio::SetSpecialIndexEQGain(int buf_index, int w_val)
1629{
1630 int tmpEQGainBuf[128] = { 0 };
1631
1632 if (buf_index >= 0 && buf_index < GetAudioEQBandCount()) {
1633 RealReadCurAudioEQGain(tmpEQGainBuf);
1634 tmpEQGainBuf[buf_index] = w_val;
1635
1636 return AudioSetEQGain(tmpEQGainBuf);
1637 }
1638
1639 return -1;
1640}
1641
1642int CTvAudio::SaveSpecialIndexEQGain(int buf_index, int w_val)
1643{
1644 int tmpEQGainBuf[128] = { 0 };
1645
1646 if (buf_index >= 0 && buf_index < GetAudioEQBandCount()) {
1647 RealReadCurAudioEQGain(tmpEQGainBuf);
1648 tmpEQGainBuf[buf_index] = w_val;
1649
1650 return RealSaveCurAudioEQGain(tmpEQGainBuf, 0);
1651 }
1652
1653 return 0;
1654}
1655
1656// amAudio
1657int CTvAudio::OpenAmAudio(unsigned int sr, int output_device)
1658{
1659 if (GetamAudioDisableFlagCFG() == 1) {
1660 return 0;
1661 }
1662
1663 return amAudioOpen(sr, CC_IN_USE_I2S_DEVICE, output_device);
1664}
1665
1666int CTvAudio::CloseAmAudio(void)
1667{
1668 if (GetamAudioDisableFlagCFG() == 1) {
1669 return 0;
1670 }
1671
1672 return amAudioClose();
1673}
1674
1675int CTvAudio::SetAmAudioInputSr(unsigned int sr, int output_device)
1676{
1677 return amAudioSetInputSr(sr, CC_IN_USE_I2S_DEVICE, output_device);
1678}
1679
1680int CTvAudio::SetAmAudioOutputMode(int mode)
1681{
1682 if (mode != CC_AMAUDIO_OUT_MODE_MIX && mode != CC_AMAUDIO_OUT_MODE_DIRECT) {
1683 LOGE("%s, mode error, it should be mix or direct!\n", __FUNCTION__);
1684 return -1;
1685 }
1686
1687 return amAudioSetOutputMode(mode);
1688}
1689
1690int CTvAudio::SetAmAudioMusicGain(int gain)
1691{
1692 return amAudioSetMusicGain(gain);
1693}
1694
1695int CTvAudio::SetAmAudioLeftGain(int gain)
1696{
1697 return amAudioSetLeftGain(gain);
1698}
1699
1700int CTvAudio::SetAmAudioRightGain(int gain)
1701{
1702 return amAudioSetRightGain(gain);
1703}
1704
1705//dump data
1706int CTvAudio::SetAudioDumpDataFlag(int tmp_flag)
1707{
1708#if CC_TV_AUDIO_TYPE_ANDROID == 1
1709 return amAndroidSetDumpDataFlag(tmp_flag);
1710#endif
1711
1712#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
1713 return amAudioSetDumpDataFlag(tmp_flag);
1714#endif
1715}
1716
1717int GetAudioDumpDataFlag()
1718{
1719#if CC_TV_AUDIO_TYPE_ANDROID == 1
1720 return amAndroidGetDumpDataFlag();
1721#endif
1722
1723#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
1724 return amAudioGetDumpDataFlag();
1725#endif
1726}
1727
1728//LUT buffer
1729static int RealCalVolDigitLUTBuf(int start_ind, int end_ind, int start_val,
1730 int end_val, int lut_buf[])
1731{
1732 int i = 0;
1733 float tmp_step = 0;
1734
1735 if (end_ind < start_ind) {
1736 return 0;
1737 }
1738
1739 tmp_step = (float) (end_val - start_val) / (float) (end_ind - start_ind);
1740
1741 for (i = start_ind; i < end_ind; i++) {
1742 lut_buf[i] = start_val + (int) (tmp_step * (i - start_ind));
1743 }
1744
1745 lut_buf[end_ind] = end_val;
1746
1747 return 1;
1748}
1749
1750static int CalVolumeDigitLUTBuf(int lut_buf_type, int lut_sel_flag, int lut_buf[])
1751{
1752 int i = 0, point_cnt = 0;
1753 int *tmpNoLinePointsDataBuffer = NULL;
1754 int *tmpNoLinePointsIndexBuffer = NULL;
1755
1756 if (lut_sel_flag == CC_LUT_SEL_TV) {
1757 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1758 lut_buf_type, CC_GET_LUT_TV);
1759 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1760 lut_buf_type, CC_GET_LUT_TV);
1761 } else if (lut_sel_flag == CC_LUT_SEL_AV) {
1762 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1763 lut_buf_type, CC_GET_LUT_AV);
1764 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1765 lut_buf_type, CC_GET_LUT_AV);
1766 } else if (lut_sel_flag == CC_LUT_SEL_COMP) {
1767 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1768 lut_buf_type, CC_GET_LUT_COMP);
1769 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1770 lut_buf_type, CC_GET_LUT_COMP);
1771 } else if (lut_sel_flag == CC_LUT_SEL_HDMI) {
1772 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1773 lut_buf_type, CC_GET_LUT_HDMI);
1774 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1775 lut_buf_type, CC_GET_LUT_HDMI);
1776 } else if (lut_sel_flag == CC_LUT_SEL_VGA) {
1777 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1778 lut_buf_type, CC_GET_LUT_VGA);
1779 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1780 lut_buf_type, CC_GET_LUT_VGA);
1781 } else if (lut_sel_flag == CC_LUT_SEL_MPEG) {
1782 tmpNoLinePointsIndexBuffer = GetAudioAmplifierNoLinePointsIndexBuffer(
1783 lut_buf_type, CC_GET_LUT_MPEG);
1784 tmpNoLinePointsDataBuffer = GetAudioAmplifierNoLinePointsDataBuffer(
1785 lut_buf_type, CC_GET_LUT_MPEG);
1786 }
1787
1788 lut_buf[0] = CC_MIN_DAC_VOLUME;
1789 point_cnt = GetAudioAmplifierMasterNoLinePointsCount();
1790
1791 if (tmpNoLinePointsIndexBuffer != NULL
1792 && tmpNoLinePointsDataBuffer != NULL) {
1793 for (i = 0; i < (point_cnt - 1); i++) {
1794 RealCalVolDigitLUTBuf(tmpNoLinePointsIndexBuffer[i],
1795 tmpNoLinePointsIndexBuffer[i + 1],
1796 tmpNoLinePointsDataBuffer[i],
1797 tmpNoLinePointsDataBuffer[i + 1], lut_buf);
1798 }
1799 }
1800
1801 return 1;
1802}
1803
1804void CTvAudio::RealHandleVolumeDigitLUTBuf(int lut_buf_type, int lut_sel_flag,
1805 int vol_buf[], int add_srs_gain_flag, int add_eq_gain_flag)
1806{
1807 int i;
1808 int TempVolumeDigitLutBuf[CC_LUT_BUF_SIZE] = { 0 };
1809
1810 if (vol_buf == NULL) {
1811 CalVolumeDigitLUTBuf(lut_buf_type, lut_sel_flag, TempVolumeDigitLutBuf);
1812 } else {
1813 for (i = 0; i < CC_LUT_BUF_SIZE; i++) {
1814 TempVolumeDigitLutBuf[i] = vol_buf[i];
1815 }
1816 }
1817
1818 if (lut_buf_type == CC_LUT_BUF_MASTER) {
1819 mAudioAlsa.SetMainVolDigitLutBuf(TempVolumeDigitLutBuf);
1820 } else if (lut_buf_type == CC_LUT_BUF_SUPPERBASS) {
1821 mAudioAlsa.SetSupperBassVolDigitLutBuf(TempVolumeDigitLutBuf);
1822 }
1823}
1824
1825void CTvAudio::AudioSetVolumeDigitLUTBuf(int lut_sel_flag, int add_srs_gain_flag,
1826 int add_eq_gain_flag, int audio_std)
1827{
1828 int cfg_get_index = CC_LUT_SEL_MPEG;
1829 int *tmpDefDigitLutBuf = NULL;
1830
1831 if (lut_sel_flag == CC_LUT_SEL_TV) {
1832 cfg_get_index = CC_GET_LUT_TV;
1833 } else if (lut_sel_flag == CC_LUT_SEL_AV) {
1834 cfg_get_index = CC_GET_LUT_AV;
1835 } else if (lut_sel_flag == CC_LUT_SEL_COMP) {
1836 cfg_get_index = CC_GET_LUT_COMP;
1837 } else if (lut_sel_flag == CC_LUT_SEL_HDMI) {
1838 cfg_get_index = CC_GET_LUT_HDMI;
1839 } else if (lut_sel_flag == CC_LUT_SEL_VGA) {
1840 cfg_get_index = CC_GET_LUT_VGA;
1841 } else if (lut_sel_flag == CC_LUT_SEL_MPEG) {
1842 cfg_get_index = CC_GET_LUT_MPEG;
1843 }
1844
1845 if (GetAudioAmplifierMasterNoLineSwitchFlag() == 0) {
1846 tmpDefDigitLutBuf = GetAudioAmplifierMasterVolumeLUTBufferPtr(
1847 cfg_get_index, audio_std);
1848 if (tmpDefDigitLutBuf != NULL) {
1849 RealHandleVolumeDigitLUTBuf(CC_LUT_BUF_MASTER, lut_sel_flag,
1850 tmpDefDigitLutBuf, add_srs_gain_flag, add_eq_gain_flag);
1851 }
1852 } else {
1853 RealHandleVolumeDigitLUTBuf(CC_LUT_BUF_MASTER, lut_sel_flag, NULL,
1854 add_srs_gain_flag, add_eq_gain_flag);
1855 }
1856
1857 if (GetAudioSupperBassModuleDisableCFG() == 0) {
1858 if (GetAudioAmplifierSupperBassNoLineSwitchFlag() == 0) {
1859 tmpDefDigitLutBuf = GetAudioAmplifierSupperBassVolumeLUTBufferPtr(
1860 cfg_get_index, audio_std);
1861 if (tmpDefDigitLutBuf != NULL) {
1862 RealHandleVolumeDigitLUTBuf(CC_LUT_BUF_SUPPERBASS, lut_sel_flag,
1863 tmpDefDigitLutBuf, add_srs_gain_flag, add_eq_gain_flag);
1864 }
1865 } else {
1866 RealHandleVolumeDigitLUTBuf(CC_LUT_BUF_SUPPERBASS, lut_sel_flag,
1867 NULL, add_srs_gain_flag, add_eq_gain_flag);
1868 }
1869 }
1870}
1871
1872int CTvAudio::openTvAudio(int sr)
1873{
1874
1875 char prop1[256];
1876 char prop2[256];
1877 property_get("audio.headset_plug.enable", prop1, "null");
1878 property_get("audio.output.double_output", prop2, "null");
1879 if(strcmp(prop1, "1") == 0) {
1880 if(strcmp(prop2, "1") == 0) {
1881 amAudioSetTvDoubleOutput(1, sr, CC_IN_USE_I2S_DEVICE, CC_OUT_USE_AMAUDIO);
1882 audio_device_switch = 1;
1883 } else {
1884 amAudioSetTvDoubleOutput(0, sr, CC_IN_USE_I2S_DEVICE, CC_OUT_USE_ANDROID);
1885 audio_device_switch = 0;
1886 }
1887 } else {
1888 amAudioSetTvDoubleOutput(1, sr, CC_IN_USE_I2S_DEVICE, CC_OUT_USE_AMAUDIO);
1889 audio_device_switch = 1;
1890 }
1891 return 0;
1892}
1893
1894// audio data init & uninit
1895int CTvAudio::AudioDataInitForDtv()
1896{
1897 RealSetSRS();
1898 SetCustomEQGain();
1899
1900 return 0;
1901}
1902
1903int CTvAudio::AudioDataInit(int sr, bool enableNoiseGate)
1904{
1905 const char *value;
1906 sr = HanldeAudioInputSr(sr);
1907#if CC_TV_AUDIO_TYPE_ANDROID == 1
1908 if (GetDisableResetSystemFrameSize() == 0) {
1909 if (GetDisableReset_System_framesizeCFG() != 0x55)
1910 reset_system_framesize(48000, sr);
1911 }
1912
1913 amAndroidInit(0, CC_FLAG_CREATE_RECORD | CC_FLAG_CREATE_TRACK, 48000, sr, enableNoiseGate);
1914#endif
1915
1916#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
1917 value = config_get_str ( "TV", "tvin.2d4G.headset.en", "null" );
1918 if ( strcmp ( value, "enable" ) == 0 )
1919 openTvAudio(sr);
1920 else
1921 OpenAmAudio(sr, CC_OUT_USE_AMAUDIO);
1922#endif
1923
1924 RealSetSRS();
1925 SetCustomEQGain();
1926
1927 return 0;
1928}
1929
1930int CTvAudio::AudioDataUnInit()
1931{
1932#if CC_TV_AUDIO_TYPE_ANDROID == 1
1933 return amAndroidUninit(0);
1934#endif
1935
1936#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
1937 return CloseAmAudio();
1938#endif
1939}
1940
1941int CTvAudio::AudioChangeSampleRate(int sr)
1942{
1943 sr = HanldeAudioInputSr(sr);
1944
1945#if CC_TV_AUDIO_TYPE_ANDROID == 1
1946 if (amAndroidSetTrackerSr(sr) != 0) {
1947 return -1;
1948 }
1949#endif
1950
1951#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
1952 if (SetAmAudioInputSr(sr, CC_OUT_USE_AMAUDIO) != 0) {
1953 return -1;
1954 }
1955#endif
1956
1957 RealSetSRS();
1958 SetCustomEQGain();
1959
1960 return 0;
1961}
1962
1963int CTvAudio::AudioNewAudioEffects(void)
1964{
1965 return mAudioEffect.amAndroidNewAudioEffects();
1966}
1967
1968void CTvAudio::AudioFreeAudioEffects(void)
1969{
1970 return mAudioEffect.amAndroidFreeAudioEffects();
1971}
1972
1973int CTvAudio::AudioSetAudioInSource(int audio_src_in_type)
1974{
1975 return mAudioAlsa.SetAudioInSource(audio_src_in_type);
1976}
1977
1978int CTvAudio::AudioSetAudioSourceType(int source_type)
1979{
1980 return mAudioAlsa.SetDacAudioSourceType(source_type);
1981}
1982
1983int CTvAudio::AudioLineInSelectChannel(int audio_channel)
1984{
1985 LOGD ("%s, audio_channel = %d", __FUNCTION__, audio_channel);
1986 mAudioAlsa.SetInternalDacLineInSelectChannel(audio_channel);
1987 return 0;
1988}
1989int CTvAudio::SetKalaokIO(int level)
1990{
1991 LOGD ("%s, SetKalaokIO = %d", __FUNCTION__, level);
1992 {
1993 const char *config_value;
1994 config_value = config_get_str("TV", "audio.switch.karaok.av.enable", "null");
1995
1996 if (strtoul(config_value, NULL, 10) == 1) {
1997 mAudioAlsa.SetAudioSwitchIO(level);
1998 }
1999 }
2000 return 0;
2001}
2002
2003int CTvAudio::AudioSetLineInCaptureVolume(int l_vol, int r_vol)
2004{
2005 mAudioAlsa.SetInternalDacLineInCaptureVolume(l_vol, r_vol);
2006 return 0;
2007}
2008
2009// Audio Ctl Init
2010void CTvAudio::AudioCtlInitializeLoad()
2011{
2012 int tmp_val = 0;
2013 int init_mute_type = 0;
2014
2015 LOGD("%s, entering...\n", __FUNCTION__);
2016
2017 createMonitorUsbHostBusThread();
2018
2019 init_mute_type = GetAudioAVOutInitMuteStatusCFG();
2020
2021 UnInitSetTvAudioCard();
2022
2023 if (init_mute_type == 1) {
2024 SetAudioAVOutMute (CC_AUDIO_MUTE);
2025 } else {
2026 SetAudioAVOutMute (CC_AUDIO_UNMUTE);
2027 }
2028
2029 SetAudioSPDIFMute (CC_AUDIO_UNMUTE);
2030
2031 tmp_val = GetAudioDumpDataEnableFlagCfg();
2032 SetAudioDumpDataFlag(tmp_val);
2033
2034 mAudioAlsa.SetMixerBypassSwitch (CC_SWITCH_OFF);
2035 mAudioAlsa.SetMixerDacSwitch (CC_SWITCH_ON);
2036
2037 LoadAudioCtl();
2038
2039 AudioSetVolumeDigitLUTBuf(CC_LUT_SEL_MPEG, 1, 1, -1);
2040
2041 AudioCtlInitializeSet();
2042}
2043
2044void CTvAudio::LoadAudioCtl()
2045{
2046 // Get Current Audio Volume
2047 LoadCurAudioMasterVolume();
2048
2049 // Get Current Audio Balance
2050 LoadCurAudioBalance();
2051
2052 // Get Current Supper Bass Switch
2053 LoadCurAudioSupperBassSwitch();
2054
2055 // Get Current Supper Bass Volume
2056 LoadCurAudioSupperBassVolume();
2057
2058 // Get Current SRSSurround
2059 LoadCurAudioSrsSurround();
2060
2061 // Get Current SRS DialogClarity
2062 LoadCurAudioSrsDialogClarity();
2063
2064 // Get Current SRS TruBass
2065 LoadCurAudioSrsTruBass();
2066
2067 // Get Current Audio Sound Mode
2068 LoadCurAudioSoundMode();
2069
2070 // Get Current Audio Bass and Treble
2071 LoadCurAudioBassVolume();
2072 LoadCurAudioTrebleVolume();
2073
2074 // Get Current Wall Effect
2075 LoadCurAudioWallEffect();
2076
2077 // Get Current spdif switch
2078 LoadCurAudioSPDIFSwitch();
2079
2080 // Get Current spdif mode
2081 LoadCurAudioSPDIFMode();
2082
2083 // Get Current EQ mode
2084 LoadCurAudioEQMode();
2085
2086 // Get Current EQ Gain
2087 LoadCurAudioEQGain();
2088}
2089
2090void CTvAudio::InitSetAudioCtl()
2091{
2092 // Set Current Audio balance value
2093 SetAudioBalance(GetAudioBalance());
2094
2095 // Set Current Audio Volume
2096 SetAudioMasterVolume(GetAudioMasterVolume());
2097
2098 // Set Current Supper Bass Volume
2099 SetAudioSupperBassVolume(GetAudioSupperBassVolume());
2100
2101 // Set Current Audio Sound Mode
2102 SetAudioSoundMode(GetAudioSoundMode());
2103
2104 // Set Current Audio SPDIF Switch
2105 SetAudioSPDIFSwitch(GetCurAudioSPDIFSwitch());
2106
2107 // Set Current Audio SPDIF mode
2108 SetAudioSPDIFMode(GetCurAudioSPDIFMode());
2109}
2110
2111static int gAudioFirstInitSetFlag = 0;
2112static pthread_mutex_t first_init_set_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
2113
2114int CTvAudio::GetAudioFirstInitSetFlag()
2115{
2116 int tmp_val = 0;
2117
2118 pthread_mutex_lock(&first_init_set_flag_mutex);
2119 tmp_val = gAudioFirstInitSetFlag;
2120 pthread_mutex_unlock(&first_init_set_flag_mutex);
2121
2122 return tmp_val;
2123}
2124
2125void *CTvAudio::AudioCtlInitSetMain(void *data)
2126{
2127 char prop_value[PROPERTY_VALUE_MAX];
2128
2129 LOGD("%s, entering...\n", __FUNCTION__);
2130 pthread_mutex_lock(&first_init_set_flag_mutex);
2131
2132 if (gAudioFirstInitSetFlag == 0) {
2133 AudioNewAudioEffects();
2134 RealSetSRS();
2135 AudioSetVolumeDigitLUTBuf(CC_LUT_SEL_MPEG, 1, 1, -1);
2136 InitSetAudioCtl();
2137 gAudioFirstInitSetFlag = 1;
2138 }
2139
2140 pthread_mutex_unlock(&first_init_set_flag_mutex);
2141
2142 LOGD("%s, exiting...\n", __FUNCTION__);
2143
2144 return NULL;
2145}
2146
2147void CTvAudio::AudioCtlInitializeSet()
2148{
2149 AudioCtlInitSetMain (NULL);
2150 return;
2151}
2152
2153void CTvAudio::AudioCtlInit()
2154{
2155 InitSetTvAudioCard();
2156}
2157
2158void CTvAudio::AudioCtlUninit()
2159{
2160 int l_vol = 0, r_vol = 0;
2161 int audio_channel = -1;
2162 int oldMuteStatus;
2163
2164 oldMuteStatus = GetAudioMuteForTv();
2165 SetAudioMuteForTv (CC_AUDIO_MUTE);
2166
2167 AudioSetAudioInSource (CC_AUDIO_IN_SOURCE_LINEIN);
2168 AudioSetAudioSourceType (AUDIO_MPEG_SOURCE);
2169
2170 AudioDataUnInit();
2171
2172 SetAudioVolumeCompensationVal(0);
2173
2174 AudioSetVolumeDigitLUTBuf(CC_LUT_SEL_MPEG, 1, 1, -1);
2175 SetAudioMasterVolume(GetAudioMasterVolume());
2176
2177 SetAudioMuteForTv(oldMuteStatus);
2178
2179 UnInitSetTvAudioCard();
2180}
2181
2182int CTvAudio::AudioSetRecordDataZero(bool flag)
2183{
2184 return 0;
2185}
2186
2187int CTvAudio::AudioHandleHeadsetPlugIn()
2188{
2189 return 0;
2190}
2191
2192int CTvAudio::AudioHandleHeadsetPullOut()
2193{
2194 return 0;
2195}
2196
2197int CTvAudio::amAudioSetDoubleOutputSwitch(int en_val)
2198{
2199 if(en_val == 1) {
2200 property_set("audio.output.enable", "1");
2201 property_set("audio.output.double_output", "1");
2202 }
2203 if(en_val == 0) {
2204 property_set("audio.output.enable", "0");
2205 property_set("audio.output.double_output", "0");
2206 }
2207 return 0;
2208}
2209
2210int CTvAudio::setAudioPcmPlaybackVolume(int val)
2211{
2212 int pcm_volume = 0;
2213 pcm_volume = val / 2;
2214 if(pcm_volume > 24) pcm_volume = 24;
2215 //return SetAudioPcmPlaybackVolume(pcm_volume);
2216 return 0;
2217}
2218
2219int CTvAudio::UsbAudioOuputModuleSwitch(int sw)
2220{
2221 if(sw == 1)
2222 property_set("persist.tv.audio_output_enable", "1");
2223 if(sw == 0)
2224 property_set("persist.tv.audio_output_enable", "0");
2225 return 0;
2226}
2227
2228int CTvAudio::GetAmAudioSetDoubleOutputSwitch()
2229{
2230 char prop2[256];
2231 property_get("audio.output.double_output", prop2, "null");
2232 if (strcmp(prop2, "0") == 0 || strcmp(prop2, "null") == 0) {
2233 return 0;
2234 } else if (strcmp(prop2, "1") == 0) {
2235 return 1;
2236 }
2237 return 0;
2238}
2239
2240int CTvAudio::GetCurUsbAudioOuputModuleSwitch()
2241{
2242 char prop1[256];
2243 property_get("audio.output.enable", prop1, "null");
2244 if (strcmp(prop1, "0") == 0 || strcmp(prop1, "null") == 0) {
2245 return 0;
2246 } else if (strcmp(prop1, "1") == 0) {
2247 return 1;
2248 }
2249 return 0;
2250}
2251
2252int CTvAudio::amAudioSetTvDoubleOutput(int en_val, unsigned int sr, int input_device,
2253 int output_device)
2254{
2255 return amAudioSetDoubleOutput(en_val, sr, input_device, output_device);
2256}
2257int CTvAudio::HanldeAudioInputSr(unsigned int sr)
2258{
2259 int tmp_cfg = 0;
2260
2261 tmp_cfg = GetAudioResampleTypeCFG();
2262 if (tmp_cfg & CC_AUD_RESAMPLE_TYPE_HW) {
2263 mAudioAlsa.SetHardwareResample(sr);
2264 } else {
2265 mAudioAlsa.SetHardwareResample(-1);
2266 }
2267
2268 if (!(tmp_cfg & CC_AUD_RESAMPLE_TYPE_SW)) {
2269 sr = 48000;
2270 }
2271
2272 return sr;
2273}
2274
2275void CTvAudio::AudioSetNoiseGateThreshold(int thresh)
2276{
2277#if CC_TV_AUDIO_TYPE_ANDROID == 1
2278 amAndroidSetNoiseGateThreshold(thresh);
2279#endif
2280
2281#ifdef CC_TV_AUDIO_TYPE_AMAUDIO == 1
2282 return;
2283#endif
2284}
2285
2286int CTvAudio::AudioSSMRestoreDefaultSetting()
2287{
2288 int i = 0, tmp_val = 0;
2289 int nMinUIVol = 0, nMaxUIVol = 0;
2290 int *tmp_ptr = NULL;
2291 int tmpEQGainBuf[128] = { 0 };
2292 unsigned char tmp_buf[CC_NO_LINE_POINTS_MAX_CNT] = { 0 };
2293
2294 // Save noline points
2295 tmp_val = GetAudioAmplifierMasterNoLinePointsCount();
2296
2297 for (i = 0; i < CC_LUT_SEL_COUNT; i++) {
2298 tmp_ptr = GetAudioAmplifierMasterNoLinePointsDefDataBuffer(i);
2299 AudioArrayCopy(tmp_buf, tmp_ptr, CC_NO_LINE_POINTS_MAX_CNT);
2300 SSMSaveAudioNoLinePoints(i * tmp_val, tmp_val, tmp_buf);
2301 }
2302
2303 // Save Current Audio Volume
2304 SaveCurAudioMasterVolume (CC_DEF_SOUND_VOL);
2305
2306 // Save Current Audio Balance
2307 SaveCurAudioBalance (CC_DEF_SOUND_BALANCE_VAL);
2308
2309 // Save Current Supper Bass Switch
2310 SaveCurAudioSupperBassSwitch (CC_SWITCH_OFF);
2311
2312 // Save Current Supper Bass Volume
2313 SaveCurAudioSupperBassVolume (CC_DEF_SUPPERBASS_VOL);
2314
2315 // Save Current SRSSurround
2316 SaveCurAudioSrsSurround(CC_SWITCH_OFF);
2317
2318 // Save Current SRS DialogClarity
2319 SaveCurAudioSrsDialogClarity(CC_SWITCH_OFF);
2320
2321 // Save Current SRS TruBass
2322 SaveCurAudioSrsTruBass(CC_SWITCH_OFF);
2323
2324 // Save Current Audio Sound Mode
2325 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
2326
2327 // Save Current Wall Effect
2328 SaveCurAudioWallEffect(CC_SWITCH_OFF);
2329
2330 // Save Current spdif switch
2331 SaveCurAudioSPDIFSwitch (CC_SWITCH_ON);
2332
2333 // Save Current spdif mode
2334 SaveCurAudioSPDIFMode (CC_SPDIF_MODE_PCM);
2335
2336 // Save Current EQ mode
2337 SaveCurAudioEQMode (CC_EQ_MODE_NOMAL);
2338
2339 // Save Current EQ Gain
2340 RestoreToAudioDefEQGain(tmpEQGainBuf);
2341
2342 // Save Current Audio Bass and Treble
2343 nMinUIVol = GetBassUIMinGainVal();
2344 nMaxUIVol = GetBassUIMaxGainVal();
2345 RealSaveCurAudioBassVolume((nMinUIVol + nMaxUIVol) / 2, 0);
2346
2347 nMinUIVol = GetTrebleUIMinGainVal();
2348 nMaxUIVol = GetTrebleUIMaxGainVal();
2349 RealSaveCurAudioTrebleVolume((nMinUIVol + nMaxUIVol) / 2, 0);
2350
2351 return 0;
2352}
2353
2354
2355static const char *gDefCapturePropName = "snd.card.default.card.capture";
2356
2357int CTvAudio::InitSetTvAudioCard()
2358{
2359 int i = 0, totle_num = 0, capture_ind = 0;
2360 char tmp_buf[32] = { 0 };
2361 char tv_card_name[64] = { 0 };
2362 char prop_value[PROPERTY_VALUE_MAX];
2363
2364#ifdef BOARD_ALSA_AUDIO_TINY
2365#else // legacy alsa lib
2366 snd_card_refresh_info();
2367#endif
2368
2369 if (GetTvAudioCardNeedSet()) {
2370 memset(prop_value, '\0', PROPERTY_VALUE_MAX);
2371 property_get("snd.card.totle.num", prop_value, "0");
2372
2373 totle_num = strtoul(prop_value, NULL, 10);
2374 LOGD("%s, totle number = %d\n", __FUNCTION__, totle_num);
2375 totle_num = 8;
2376
2377 GetTvAudioCardName(tv_card_name);
2378
2379 for (i = 0; i < totle_num; i++) {
2380 sprintf(tmp_buf, "snd.card.%d.name", i);
2381 memset(prop_value, '\0', PROPERTY_VALUE_MAX);
2382 property_get(tmp_buf, prop_value, "null");
2383
2384 LOGD("%s, key string \"%s\", value string \"%s\".\n", __FUNCTION__,
2385 tmp_buf, prop_value);
2386
2387 if (strcmp(prop_value, tv_card_name) == 0) {
2388 break;
2389 }
2390 }
2391
2392 capture_ind = i;
2393
2394 if (capture_ind == totle_num) {
2395 capture_ind = -1;
2396 LOGE("%s, can't find tv card \"%s\".\n", __FUNCTION__,
2397 tv_card_name);
2398 }
2399 } else {
2400 capture_ind = -1;
2401 }
2402
2403 sprintf(tmp_buf, "%d", capture_ind);
2404 property_set(gDefCapturePropName, tmp_buf);
2405 LOGD("%s, set \"%s\" as \"%s\".\n", __FUNCTION__, gDefCapturePropName,
2406 tmp_buf);
2407
2408 return 0;
2409}
2410
2411int CTvAudio::UnInitSetTvAudioCard()
2412{
2413 char tmp_buf[32] = { 0 };
2414
2415#ifdef BOARD_ALSA_AUDIO_TINY
2416#else // legacy alsa lib
2417 snd_card_refresh_info();
2418#endif // BOARD_ALSA_AUDIO_TINY
2419 sprintf(tmp_buf, "%d", -1);
2420 property_set(gDefCapturePropName, tmp_buf);
2421 LOGD("%s, set \"%s\" as \"%s\".\n", __FUNCTION__, gDefCapturePropName,
2422 tmp_buf);
2423
2424 return 0;
2425}
2426
2427#define CS_SPDIF_MODE_DEV_PATH "/sys/class/audiodsp/digital_raw"
2428
2429int CTvAudio::SetSPDIFMode(int mode_val)
2430{
2431 FILE *spdif_mode_fp = NULL;
2432
2433 spdif_mode_fp = fopen(CS_SPDIF_MODE_DEV_PATH, "w");
2434 if (spdif_mode_fp == NULL) {
2435 LOGE("%s, Open file %s error(%s)!\n", __FUNCTION__, CS_SPDIF_MODE_DEV_PATH, strerror(errno));
2436 return -1;
2437 }
2438
2439 if (mode_val == CC_SPDIF_MODE_PCM) {
2440 fprintf(spdif_mode_fp, "%d", 0);
2441 } else if(mode_val == CC_SPDIF_MODE_RAW ) {
2442 fprintf(spdif_mode_fp, "%d", 1);
2443 }
2444
2445 fclose(spdif_mode_fp);
2446 spdif_mode_fp = NULL;
2447
2448 return 0;
2449}
2450//0 is ??? 1 is ????????
2451int CTvAudio::SwitchAVOutBypass(int sw)
2452{
2453 if (sw == 0 ) {
2454 mAudioAlsa.SetMixerBypassSwitch ( CC_SWITCH_OFF );
2455 mAudioAlsa.SetMixerDacSwitch ( CC_SWITCH_ON );
2456 } else {
2457 mAudioAlsa.SetMixerBypassSwitch ( CC_SWITCH_ON );
2458 mAudioAlsa.SetMixerDacSwitch ( CC_SWITCH_OFF );
2459 }
2460 return 0;
2461}
2462
2463int CTvAudio::SetAudioSwitchIO(int value)
2464{
2465 return mAudioAlsa.SetAudioSwitchIO( value);
2466}
2467int CTvAudio::SetOutput_Swap(int value)
2468{
2469 return mAudioAlsa.SetOutput_Swap( value);
2470}
2471