| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * PCM output |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: $ |
|---|
| 21 | * |
|---|
| 22 | * |
|---|
| 23 | *******************************************************************************/ |
|---|
| 24 | #include "bsettop_decode_audio.h" |
|---|
| 25 | #include "bsettop_p_stream.h" |
|---|
| 26 | #include "bsettop_hdmi.h" |
|---|
| 27 | #include "bhdm.h" |
|---|
| 28 | #include "gist.h" |
|---|
| 29 | #include "bape.h" |
|---|
| 30 | #include "bdsp.h" |
|---|
| 31 | #include "bdsp_raaga.h" |
|---|
| 32 | #include "bape_types.h" |
|---|
| 33 | #include "bos_task_priorities.h" |
|---|
| 34 | #include "bkni_event_group.h" |
|---|
| 35 | #include "bchp_hifidac_ctrl0.h" |
|---|
| 36 | #include "ts_psi.h" /* Included for PMT stream type definitions */ |
|---|
| 37 | |
|---|
| 38 | #ifdef BCM_DEBUG |
|---|
| 39 | #define INIT_CHECK(a) \ |
|---|
| 40 | { \ |
|---|
| 41 | BDBG_MSG((#a " - Enter\n")); \ |
|---|
| 42 | if (a != BERR_SUCCESS) \ |
|---|
| 43 | { \ |
|---|
| 44 | BDBG_ERR((#a " #### failed in %s:%d\n",__FUNCTION__,__LINE__)); \ |
|---|
| 45 | goto failed; \ |
|---|
| 46 | } \ |
|---|
| 47 | BDBG_MSG((#a " - Exit\n")); \ |
|---|
| 48 | } |
|---|
| 49 | #else /* BCM_DEBUG */ |
|---|
| 50 | #define INIT_CHECK(x) if (x != BERR_SUCCESS) goto failed |
|---|
| 51 | #endif |
|---|
| 52 | |
|---|
| 53 | BDBG_MODULE(decode_audio); |
|---|
| 54 | typedef enum ConnectorType |
|---|
| 55 | { |
|---|
| 56 | ConnectorType_eStereo, |
|---|
| 57 | ConnectorType_eMultichannel, |
|---|
| 58 | ConnectorType_eCompressed, |
|---|
| 59 | ConnectorType_eAvl, |
|---|
| 60 | ConnectorType_eMax |
|---|
| 61 | } ConnectorType; |
|---|
| 62 | |
|---|
| 63 | #define CONFIG_COMPRESS_HDMI |
|---|
| 64 | #define RAAGA_TASK_STACK 0x100 /* changed from 0x400 */ |
|---|
| 65 | #define MAX_EBUFFER 200 /* for 500 msec */ |
|---|
| 66 | struct baudio_decode |
|---|
| 67 | { |
|---|
| 68 | bool initialized; |
|---|
| 69 | baudio_decode_config config; |
|---|
| 70 | bool audio_decode; |
|---|
| 71 | bool compressed_decode; |
|---|
| 72 | bool locked; |
|---|
| 73 | int first_pts_cnt; |
|---|
| 74 | int sample_rate_change_cnt; |
|---|
| 75 | int tsm_failed_cnt; |
|---|
| 76 | BXPT_RaveCx_Handle hAudioDecodeRaveCx; /* Rave context associated with the stream */ |
|---|
| 77 | BXPT_RaveCx_Handle hAudioCompressedRaveCx; /* Rave context associated with the stream */ |
|---|
| 78 | b_mutex_t mutex; |
|---|
| 79 | bstream_t stream; |
|---|
| 80 | BDSP_Handle dspHandle; |
|---|
| 81 | BAPE_Handle apeHandle; |
|---|
| 82 | BAPE_DecoderHandle hApeDecodeCh; |
|---|
| 83 | BAPE_DecoderHandle hApeCompressedDecodeCh; |
|---|
| 84 | int index; |
|---|
| 85 | BAPE_InterruptHandlers interruptHandlers; |
|---|
| 86 | BAPE_DecoderInterruptHandlers decoderInterruptHandlers; |
|---|
| 87 | BAPE_Connector connectors[ConnectorType_eMax]; |
|---|
| 88 | BAPE_Settings apeSettings; |
|---|
| 89 | BDSP_RaagaSettings raagaSettings; |
|---|
| 90 | BAPE_DecoderOpenSettings decoderOpenSettings; |
|---|
| 91 | BAPE_DecoderStartSettings apeStartSettings; |
|---|
| 92 | BAPE_DecoderTsmSettings tsmSettings; |
|---|
| 93 | BAPE_RfModHandle hRfmHandle; |
|---|
| 94 | |
|---|
| 95 | BAPE_MixerHandle hDacMixer; |
|---|
| 96 | #if HAS_HDMI |
|---|
| 97 | BAPE_MixerHandle hMaiMixer; |
|---|
| 98 | #endif |
|---|
| 99 | BAPE_DacHandle hDacOutput; |
|---|
| 100 | #if HAS_HDMI |
|---|
| 101 | BAPE_MaiOutputHandle hMaiOutput; |
|---|
| 102 | #endif |
|---|
| 103 | BAVC_XptContextMap sContextMap; |
|---|
| 104 | BAVC_XptContextMap sCompressedContextMap; |
|---|
| 105 | BAPE_AutoVolumeLevelHandle hAvl; |
|---|
| 106 | |
|---|
| 107 | BAPE_DecoderSettings decoderSettings; /* decoder settings */ |
|---|
| 108 | //BAPE_DolbyDigitalReencodeSettings dolbySettings; |
|---|
| 109 | BAPE_DecoderCodecSettings decoderCodecSettings; |
|---|
| 110 | BKNI_EventHandle wdEvent; |
|---|
| 111 | |
|---|
| 112 | BAPE_OutputCaptureHandle hCapture; |
|---|
| 113 | BAPE_OutputCaptureInterruptHandlers captureInterruptHandlers; |
|---|
| 114 | |
|---|
| 115 | BKNI_EventGroupHandle raagaEvent; |
|---|
| 116 | BKNI_EventHandle captureEvent; |
|---|
| 117 | b_task_t raaga_task; |
|---|
| 118 | unsigned int raaga_stack[RAAGA_TASK_STACK]; |
|---|
| 119 | bool is_capture; |
|---|
| 120 | int ewptr; /* power write ptr */ |
|---|
| 121 | long energy[MAX_EBUFFER]; |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | struct baudio_decode s_audio = |
|---|
| 125 | { |
|---|
| 126 | false, |
|---|
| 127 | { NULL,NULL,0,0,false }, |
|---|
| 128 | false, |
|---|
| 129 | false, |
|---|
| 130 | false, |
|---|
| 131 | 0, |
|---|
| 132 | 0, |
|---|
| 133 | 0, |
|---|
| 134 | NULL, |
|---|
| 135 | NULL, |
|---|
| 136 | { 0, 0, 0 }, |
|---|
| 137 | NULL, /* stream */ |
|---|
| 138 | NULL, /* dspHandle */ |
|---|
| 139 | NULL, /* apeHandle */ |
|---|
| 140 | NULL, |
|---|
| 141 | 0, /* index */ |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | const bsettop_av_stream_type_t s_audio_stream_types[] = |
|---|
| 145 | { |
|---|
| 146 | #if (BCHP_CHIP!=7552) |
|---|
| 147 | { TS_PSI_ST_11172_3_Audio, BRAP_DSPCHN_AudioType_eMpeg, 0,"MPEG"}, |
|---|
| 148 | { TS_PSI_ST_13818_3_Audio, BRAP_DSPCHN_AudioType_eMpeg, 0,"MPEG"}, |
|---|
| 149 | { TS_PSI_ST_ATSC_AC3, BRAP_DSPCHN_AudioType_eAc3, 0,"AC3"}, |
|---|
| 150 | { TS_PSI_ST_ATSC_EAC3, BRAP_DSPCHN_AudioType_eAc3Plus, 0,"AC3+"} |
|---|
| 151 | #else |
|---|
| 152 | |
|---|
| 153 | #if 1 //mpeg remove |
|---|
| 154 | { TS_PSI_ST_ATSC_AC3, BAVC_AudioCompressionStd_eAc3, 0,"AC3"}, |
|---|
| 155 | { TS_PSI_ST_ATSC_EAC3, BAVC_AudioCompressionStd_eAc3Plus, 0,"AC3+"}, |
|---|
| 156 | { TS_PSI_ST_13818_1_PrivatePES, BAVC_AudioCompressionStd_eAc3, 0,"AC3"} |
|---|
| 157 | #else |
|---|
| 158 | { TS_PSI_ST_11172_3_Audio, BAVC_AudioCompressionStd_eMpegL1, 0, "MPEG"}, |
|---|
| 159 | { TS_PSI_ST_13818_3_Audio, BAVC_AudioCompressionStd_eMpegL1, 0,"MPEG"}, |
|---|
| 160 | { TS_PSI_ST_ATSC_AC3, BAVC_AudioCompressionStd_eAc3, 0,"AC3"}, |
|---|
| 161 | { TS_PSI_ST_ATSC_EAC3, BAVC_AudioCompressionStd_eAc3Plus, 0,"AC3+"}, |
|---|
| 162 | { TS_PSI_ST_13818_1_PrivatePES, BAVC_AudioCompressionStd_eAc3, 0,"AC3"} |
|---|
| 163 | #endif |
|---|
| 164 | |
|---|
| 165 | #endif |
|---|
| 166 | }; |
|---|
| 167 | const int s_audio_stream_types_num = sizeof(s_audio_stream_types)/sizeof(s_audio_stream_types[0]); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | static void baudio_decode_switch_mai_output(baudio_decode_t audio, bool compressed); |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | Summary: |
|---|
| 174 | Supported audio format. Returns NULL if stream_type (from PMT) not supported. |
|---|
| 175 | **/ |
|---|
| 176 | |
|---|
| 177 | bsettop_av_stream_type_t *bdecode_supported_audio(unsigned char stream_type) |
|---|
| 178 | { |
|---|
| 179 | int i; |
|---|
| 180 | for (i = 0; i < s_audio_stream_types_num; ++i) |
|---|
| 181 | { |
|---|
| 182 | BDBG_MSG(("Table Entry[%d]: 0x%02x,0x%02x %s\n",i,s_audio_stream_types[i].format,s_audio_stream_types[i].codec_id,s_audio_stream_types[i].format_name)); |
|---|
| 183 | if (stream_type == s_audio_stream_types[i].format) |
|---|
| 184 | { |
|---|
| 185 | BDBG_MSG(("Audio format[0x%02x]: %s\n",s_audio_stream_types[i].format,s_audio_stream_types[i].format_name)); |
|---|
| 186 | return(bsettop_av_stream_type_t*)&s_audio_stream_types[i]; |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | BDBG_MSG(("Unsupported Audio format[0x%02x]\n",stream_type)); |
|---|
| 190 | return NULL; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | static void |
|---|
| 194 | b_lock(baudio_decode_t codec) |
|---|
| 195 | { |
|---|
| 196 | bresult rc; |
|---|
| 197 | rc = bos_acquire_mutex(&s_audio.mutex, 10 * 1000); |
|---|
| 198 | BDBG_ASSERT(rc==b_ok); |
|---|
| 199 | return; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | static void |
|---|
| 203 | b_unlock(baudio_decode_t codec) |
|---|
| 204 | { |
|---|
| 205 | bresult rc; |
|---|
| 206 | rc = bos_release_mutex(&s_audio.mutex); |
|---|
| 207 | BDBG_ASSERT(rc==b_ok); |
|---|
| 208 | return; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | static void baudio_decode_lock_cb(void *pParam1, int param2) |
|---|
| 212 | { |
|---|
| 213 | baudio_decode_t audio = (baudio_decode_t)pParam1; |
|---|
| 214 | |
|---|
| 215 | audio->locked = param2; |
|---|
| 216 | BDBG_MSG(("Decoder %u %s", audio->index, param2?"lock":"unlock")); |
|---|
| 217 | } |
|---|
| 218 | void baudio_decode_rate_change_cb (void *pParm1, int parm2, unsigned sampleRate) |
|---|
| 219 | { |
|---|
| 220 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 221 | /* hdmi rate change is moved to BAPE_Mai's interrupt */ |
|---|
| 222 | #if 0 |
|---|
| 223 | if (audio->config.rate_change_cb) |
|---|
| 224 | { |
|---|
| 225 | audio->config.rate_change_cb(audio,audio->config.rate_change_data,sampleRate); |
|---|
| 226 | } |
|---|
| 227 | #endif |
|---|
| 228 | #if 0 |
|---|
| 229 | BAPE_DecoderTsmSettings tsmSettings; |
|---|
| 230 | BAPE_Decoder_GetTsmSettings(audio->hApeDecodeCh,&tsmSettings); |
|---|
| 231 | tsmSettings.ptsOffset = 4000; |
|---|
| 232 | BAPE_Decoder_SetTsmSettings(audio->hApeDecodeCh,&tsmSettings); |
|---|
| 233 | #endif |
|---|
| 234 | audio->sample_rate_change_cnt++; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | #ifdef HAS_HDMI |
|---|
| 238 | void baudio_hdmi_rate_change_cb(void *pParam1, int param2, unsigned sampleRate) |
|---|
| 239 | { |
|---|
| 240 | baudio_decode_t audio = (baudio_decode_t)pParam1; |
|---|
| 241 | BSTD_UNUSED(param2); |
|---|
| 242 | if (audio->config.rate_change_cb) |
|---|
| 243 | { |
|---|
| 244 | audio->config.rate_change_cb(audio, audio->config.rate_change_data, (void *)sampleRate); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | #endif |
|---|
| 248 | |
|---|
| 249 | void baudio_decode_first_pts_cb (void *pParm1, int parm, const BAPE_DecoderTsmStatus *pTsmStatus) |
|---|
| 250 | { |
|---|
| 251 | |
|---|
| 252 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 253 | unsigned int stc,pts; |
|---|
| 254 | BDBG_ASSERT(audio); |
|---|
| 255 | BDBG_ASSERT(audio->stream); |
|---|
| 256 | BDBG_ASSERT(audio->stream->hPcrOffset); |
|---|
| 257 | |
|---|
| 258 | stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 259 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 260 | |
|---|
| 261 | pts = pTsmStatus->ptsInfo.ui32CurrentPTS; |
|---|
| 262 | BDBG_MSG(("baudio_decode_first_pts_cb pts = %x, stc = %x", pts,stc)); |
|---|
| 263 | |
|---|
| 264 | bstream_p_pcroffset_update(audio->stream); |
|---|
| 265 | BAPE_Decoder_SetStcValid_isr(audio->hApeDecodeCh); |
|---|
| 266 | audio->first_pts_cnt++; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | void baudio_decode_tsm_failed_cb (void *pParm1, int parm2, const BAPE_DecoderTsmStatus *pTsmStatus) |
|---|
| 270 | { |
|---|
| 271 | #define MAX_LARGE_PTS_COUNT 20 |
|---|
| 272 | |
|---|
| 273 | static int last_pts_count = 0; /* track large current PTS value */ |
|---|
| 274 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 275 | unsigned int stc; |
|---|
| 276 | BDBG_ASSERT(audio); |
|---|
| 277 | BDBG_ASSERT(audio->stream); |
|---|
| 278 | BDBG_ASSERT(audio->stream->hPcrOffset); |
|---|
| 279 | |
|---|
| 280 | stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 281 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 282 | |
|---|
| 283 | BDBG_MSG(("%s pts = %u, stc = %u", __func__, pTsmStatus->ptsInfo.ui32CurrentPTS,stc)); |
|---|
| 284 | BDBG_MSG(("%s ptsStcDifference = %u, lastFrameLength (ms) = %u", __func__, pTsmStatus->ptsStcDifference, pTsmStatus->lastFrameLength)); |
|---|
| 285 | /* RLQ, some stream has static video, but encoded the PCR to sync with video instead of audio, and causes no audio problem in audio TSM mode, here is the workaround with detecting logic and if it is the case, then switch to non TSM mode */ |
|---|
| 286 | if ((pTsmStatus->ptsInfo.ui32CurrentPTS > 200000000) && (pTsmStatus->ptsInfo.ui32CurrentPTS > stc)) { |
|---|
| 287 | last_pts_count++; |
|---|
| 288 | /* if the count exceeds maximum allowed count, then switch to non TSM mode instead */ |
|---|
| 289 | if (last_pts_count > MAX_LARGE_PTS_COUNT) { |
|---|
| 290 | BAPE_Decoder_GetTsmSettings(audio->hApeDecodeCh, &audio->tsmSettings); |
|---|
| 291 | audio->tsmSettings.tsmEnabled = false; |
|---|
| 292 | BAPE_Decoder_SetTsmSettings(audio->hApeDecodeCh, &audio->tsmSettings); |
|---|
| 293 | last_pts_count = 0; |
|---|
| 294 | return; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | else { |
|---|
| 298 | /* reset count */ |
|---|
| 299 | last_pts_count = 0; |
|---|
| 300 | } |
|---|
| 301 | bstream_p_pcroffset_update(audio->stream); |
|---|
| 302 | /*RLQ, we need to call the function below to set valid stc if tsm error happened */ |
|---|
| 303 | BAPE_Decoder_SetStcValid_isr(audio->hApeDecodeCh); |
|---|
| 304 | audio->tsm_failed_cnt++; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | static void baudio_decode_raaga_task(void *arg); |
|---|
| 308 | static void baudio_capture_getbuffer(baudio_decode_t audio); |
|---|
| 309 | /* this function for watchdog recovery and be called from within Raptor's watchdogISR */ |
|---|
| 310 | void baudio_decode_watchdog_isr(void *pParam1, int param2) |
|---|
| 311 | { |
|---|
| 312 | BSTD_UNUSED(param2); |
|---|
| 313 | BDBG_ERR(("%s: watchdog timer fired, perform recovery process", __func__)); |
|---|
| 314 | baudio_decode_t audio = (baudio_decode_t)pParam1; |
|---|
| 315 | BKNI_SetEvent(audio->wdEvent); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | void baudio_decode_capture_isr(void *pParam1, int param2) |
|---|
| 319 | { |
|---|
| 320 | BSTD_UNUSED(param2); |
|---|
| 321 | baudio_decode_t audio = (baudio_decode_t)pParam1; |
|---|
| 322 | if (audio->is_capture) { |
|---|
| 323 | BKNI_SetEvent(audio->captureEvent); |
|---|
| 324 | } |
|---|
| 325 | else { |
|---|
| 326 | BAPE_OutputCapture_Flush_isr(audio->hCapture); |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | /* |
|---|
| 331 | * Mapping DrcMode |
|---|
| 332 | * |
|---|
| 333 | */ |
|---|
| 334 | BAPE_Ac3DrcMode baudio_p_map_drc_mode(baudio_dolby_drc_mode mode) |
|---|
| 335 | { |
|---|
| 336 | switch (mode) |
|---|
| 337 | { |
|---|
| 338 | case baudio_dolby_drc_mode_line: |
|---|
| 339 | return BAPE_Ac3DrcMode_eLine; |
|---|
| 340 | |
|---|
| 341 | default: |
|---|
| 342 | break; |
|---|
| 343 | } |
|---|
| 344 | return BAPE_Ac3DrcMode_eRf; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | /* |
|---|
| 348 | * Mapping stereo downmix mode |
|---|
| 349 | * |
|---|
| 350 | */ |
|---|
| 351 | BAPE_Ac3StereoMode baudio_p_map_stereo_downmix_mode(baudio_dolby_stereo_downmix_mode mode) |
|---|
| 352 | { |
|---|
| 353 | switch (mode) |
|---|
| 354 | { |
|---|
| 355 | case baudio_dolby_stereo_downmix_mode_dolby_surround_compatible: |
|---|
| 356 | return BAPE_Ac3StereoMode_eLtRt; |
|---|
| 357 | |
|---|
| 358 | case baudio_dolby_stereo_downmix_mode_standard: |
|---|
| 359 | return BAPE_Ac3StereoMode_eLoRo; |
|---|
| 360 | |
|---|
| 361 | default: |
|---|
| 362 | break; |
|---|
| 363 | } |
|---|
| 364 | return BAPE_Ac3StereoMode_eAuto; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | void baudio_decode_get_avl_level(baudio_decode_t audio, int num_energy, long *level) |
|---|
| 368 | { |
|---|
| 369 | int start_idx, remain; |
|---|
| 370 | BDBG_ASSERT(level); |
|---|
| 371 | if (num_energy>MAX_EBUFFER) return; |
|---|
| 372 | |
|---|
| 373 | start_idx = audio->ewptr-num_energy; |
|---|
| 374 | |
|---|
| 375 | if (start_idx >= 0) { |
|---|
| 376 | BKNI_Memcpy(level, &audio->energy[start_idx], num_energy*sizeof(long)); |
|---|
| 377 | } |
|---|
| 378 | else { |
|---|
| 379 | remain = -1*start_idx; |
|---|
| 380 | BKNI_Memcpy(level, &audio->energy[MAX_EBUFFER+start_idx], remain*sizeof(long)); |
|---|
| 381 | BKNI_Memcpy(level+remain, &audio->energy[0], audio->ewptr*sizeof(long)); |
|---|
| 382 | } |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | baudio_decode_t |
|---|
| 387 | baudio_decode_open(bobject_t id) |
|---|
| 388 | { |
|---|
| 389 | BAVC_CdbItbConfig cdb_itb_config; |
|---|
| 390 | BAPE_OutputPort outputPort; |
|---|
| 391 | BAPE_RfModSettings apeRfmSettings; |
|---|
| 392 | BAPE_AutoVolumeLevelSettings avlSettings; |
|---|
| 393 | b_task_params task_params; |
|---|
| 394 | #if HAS_HDMI |
|---|
| 395 | BAPE_MaiOutputInterruptHandlers interrupts; |
|---|
| 396 | #endif |
|---|
| 397 | BAPE_MixerAddInputSettings addInputSettings; |
|---|
| 398 | |
|---|
| 399 | baudio_decode_t audio; |
|---|
| 400 | |
|---|
| 401 | if (s_audio.initialized) |
|---|
| 402 | { |
|---|
| 403 | return (baudio_decode_t)0; |
|---|
| 404 | } |
|---|
| 405 | /* |
|---|
| 406 | BDBG_SetModuleLevel("rap_int", BDBG_eMsg) ; |
|---|
| 407 | BDBG_SetModuleLevel("rap_cit", BDBG_eMsg) ; |
|---|
| 408 | */ |
|---|
| 409 | if (bos_create_mutex(&(s_audio.mutex)) != b_ok) |
|---|
| 410 | { |
|---|
| 411 | return (baudio_decode_t)0; |
|---|
| 412 | } |
|---|
| 413 | audio = &s_audio; |
|---|
| 414 | |
|---|
| 415 | /* TODO: Open DSP handle */ |
|---|
| 416 | BDSP_Raaga_GetDefaultSettings(&audio->raagaSettings); |
|---|
| 417 | INIT_CHECK(BDSP_Raaga_Open(&audio->dspHandle, |
|---|
| 418 | GetCHP(), GetREG(), GetHEAP(), GetINT(), GetTMR(), &audio->raagaSettings)); |
|---|
| 419 | BAPE_GetDefaultSettings(&audio->apeSettings); |
|---|
| 420 | #if 0 |
|---|
| 421 | audio->apeSettings.maxDspTasks = pSettings->maxAudioDspTasks; |
|---|
| 422 | audio->apeSettings.maxIndependentDelay = pSettings->independentDelay ? pSettings->maxIndependentDelay : 0; |
|---|
| 423 | audio->apeSettings.maxPcmSampleRate = pSettings->maxPcmSampleRate; |
|---|
| 424 | audio->apeSettings.highBitRateEnabled = pSettings->hbrEnabled; |
|---|
| 425 | audio->apeSettings.numCompressedBuffers = pSettings->numCompressedBuffers; |
|---|
| 426 | audio->apeSettings.numPcmBuffers = pSettings->numPcmBuffers; |
|---|
| 427 | audio->apeSettings.rampPcmSamples = true; /* false if audio RAMP disabled */ |
|---|
| 428 | #endif |
|---|
| 429 | INIT_CHECK(BAPE_Open(&audio->apeHandle,GetCHP(), GetREG(), GetHEAP(), GetINT(), GetTMR(), |
|---|
| 430 | audio->dspHandle, &audio->apeSettings)); |
|---|
| 431 | |
|---|
| 432 | BAPE_GetInterruptHandlers(audio->apeHandle, &audio->interruptHandlers); |
|---|
| 433 | audio->interruptHandlers.watchdog.pParam1 = audio; |
|---|
| 434 | audio->interruptHandlers.watchdog.pCallback_isr = baudio_decode_watchdog_isr; |
|---|
| 435 | INIT_CHECK(BAPE_SetInterruptHandlers(audio->apeHandle, &audio->interruptHandlers)); |
|---|
| 436 | /* Open APE decoder */ |
|---|
| 437 | BAPE_Decoder_GetDefaultOpenSettings(&audio->decoderOpenSettings); |
|---|
| 438 | |
|---|
| 439 | audio->index = 0; /* channel index */ |
|---|
| 440 | INIT_CHECK(BAPE_Decoder_Open(audio->apeHandle, audio->index, &audio->decoderOpenSettings, &audio->hApeDecodeCh)); |
|---|
| 441 | INIT_CHECK(BAPE_Decoder_Open(audio->apeHandle, 1, &audio->decoderOpenSettings, &audio->hApeCompressedDecodeCh)); |
|---|
| 442 | |
|---|
| 443 | /* Init connectors */ |
|---|
| 444 | BAPE_Decoder_GetConnector(audio->hApeDecodeCh, BAPE_ConnectorFormat_eStereo, &audio->connectors[ConnectorType_eStereo]); |
|---|
| 445 | BAPE_Decoder_GetConnector(audio->hApeDecodeCh, BAPE_ConnectorFormat_eMultichannel, &audio->connectors[ConnectorType_eMultichannel]); |
|---|
| 446 | BAPE_Decoder_GetConnector(audio->hApeCompressedDecodeCh, BAPE_ConnectorFormat_eCompressed, &audio->connectors[ConnectorType_eCompressed]); |
|---|
| 447 | |
|---|
| 448 | /* RLQ */ |
|---|
| 449 | BAPE_DacSettings settings; |
|---|
| 450 | BAPE_Dac_GetDefaultSettings(&settings); |
|---|
| 451 | |
|---|
| 452 | BAPE_Dac_Open(audio->apeHandle, 0, &settings, &audio->hDacOutput); |
|---|
| 453 | #if HAS_HDMI |
|---|
| 454 | BAPE_MaiOutput_Open(audio->apeHandle, 0, NULL, &audio->hMaiOutput); |
|---|
| 455 | |
|---|
| 456 | BAPE_MaiOutput_GetInterruptHandlers(audio->hMaiOutput, &interrupts); |
|---|
| 457 | interrupts.sampleRate.pCallback_isr = baudio_hdmi_rate_change_cb; |
|---|
| 458 | interrupts.sampleRate.pParam1 = audio; |
|---|
| 459 | BAPE_MaiOutput_SetInterruptHandlers(audio->hMaiOutput, &interrupts); |
|---|
| 460 | #endif |
|---|
| 461 | |
|---|
| 462 | BAPE_RfMod_Open(audio->apeHandle, 0, NULL, &audio->hRfmHandle); |
|---|
| 463 | BAPE_Mixer_Create(audio->apeHandle, NULL, &audio->hDacMixer); |
|---|
| 464 | #if HAS_HDMI |
|---|
| 465 | BAPE_Mixer_Create(audio->apeHandle, NULL, &audio->hMaiMixer); |
|---|
| 466 | #endif |
|---|
| 467 | |
|---|
| 468 | BAPE_AutoVolumeLevel_GetDefaultSettings(&avlSettings); |
|---|
| 469 | avlSettings.enabled = false; /* disable as default */ |
|---|
| 470 | BAPE_AutoVolumeLevel_Create(audio->apeHandle, &avlSettings, &audio->hAvl); |
|---|
| 471 | BAPE_AutoVolumeLevel_GetConnector(audio->hAvl, &audio->connectors[ConnectorType_eAvl]); |
|---|
| 472 | BAPE_AutoVolumeLevel_AddInput(audio->hAvl, audio->connectors[ConnectorType_eStereo]); |
|---|
| 473 | |
|---|
| 474 | BAPE_Mixer_GetDefaultAddInputSettings(&addInputSettings); |
|---|
| 475 | addInputSettings.sampleRateMaster = true; |
|---|
| 476 | BAPE_Mixer_AddInput(audio->hDacMixer, audio->connectors[ConnectorType_eAvl], &addInputSettings); |
|---|
| 477 | #if HAS_HDMI |
|---|
| 478 | BAPE_Mixer_AddInput(audio->hMaiMixer, audio->connectors[ConnectorType_eAvl], &addInputSettings); |
|---|
| 479 | #endif |
|---|
| 480 | |
|---|
| 481 | //RLQ |
|---|
| 482 | #if 0 |
|---|
| 483 | BAPE_Mixer_AddInput(audio->hDacMixer, audio->connectors[ConnectorType_eStereo], &addInputSettings); |
|---|
| 484 | #if HAS_HDMI |
|---|
| 485 | BAPE_Mixer_AddInput(audio->hMaiMixer, audio->connectors[ConnectorType_eStereo], false); |
|---|
| 486 | #endif |
|---|
| 487 | #endif |
|---|
| 488 | BAPE_Dac_GetOutputPort(audio->hDacOutput, &outputPort); |
|---|
| 489 | BAPE_RfMod_GetSettings(audio->hRfmHandle, &apeRfmSettings); |
|---|
| 490 | apeRfmSettings.master = outputPort; |
|---|
| 491 | apeRfmSettings.muted = false; |
|---|
| 492 | BAPE_RfMod_SetSettings(audio->hRfmHandle, &apeRfmSettings); |
|---|
| 493 | |
|---|
| 494 | BAPE_Mixer_AddOutput(audio->hDacMixer, outputPort); |
|---|
| 495 | #if HAS_HDMI |
|---|
| 496 | BAPE_MaiOutput_GetOutputPort(audio->hMaiOutput, &outputPort); |
|---|
| 497 | BAPE_Mixer_AddOutput(audio->hMaiMixer, outputPort); |
|---|
| 498 | #endif |
|---|
| 499 | |
|---|
| 500 | /* Hook up decoder interrupts */ |
|---|
| 501 | BAPE_Decoder_GetInterruptHandlers(audio->hApeDecodeCh, &audio->decoderInterruptHandlers); |
|---|
| 502 | audio->decoderInterruptHandlers.firstPts.pCallback_isr = baudio_decode_first_pts_cb; |
|---|
| 503 | audio->decoderInterruptHandlers.firstPts.pParam1 = (void*)audio; |
|---|
| 504 | audio->decoderInterruptHandlers.tsmFail.pCallback_isr = baudio_decode_tsm_failed_cb; |
|---|
| 505 | audio->decoderInterruptHandlers.tsmFail.pParam1 = (void*)audio; |
|---|
| 506 | #if NEXUS_HAS_ASTM |
|---|
| 507 | audio->decoderInterruptHandlers.tsmPass.pCallback_isr = NEXUS_AudioDecoder_P_AudioTsmPass_isr; |
|---|
| 508 | audio->decoderInterruptHandlers.tsmPass.pParam1 = (void*)audio; |
|---|
| 509 | #endif |
|---|
| 510 | audio->decoderInterruptHandlers.sampleRateChange.pCallback_isr = baudio_decode_rate_change_cb; |
|---|
| 511 | audio->decoderInterruptHandlers.sampleRateChange.pParam1 = audio; |
|---|
| 512 | audio->decoderInterruptHandlers.lock.pCallback_isr = baudio_decode_lock_cb; |
|---|
| 513 | audio->decoderInterruptHandlers.lock.pParam1 = (void*)audio; |
|---|
| 514 | audio->decoderInterruptHandlers.lock.param2 = true; |
|---|
| 515 | audio->decoderInterruptHandlers.unlock.pCallback_isr = baudio_decode_lock_cb; |
|---|
| 516 | audio->decoderInterruptHandlers.unlock.pParam1 = (void*)audio; |
|---|
| 517 | audio->decoderInterruptHandlers.unlock.param2 = false; |
|---|
| 518 | BAPE_Decoder_SetInterruptHandlers(audio->hApeDecodeCh, &audio->decoderInterruptHandlers); |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | BAPE_Decoder_GetDefaultCdbItbConfig(audio->hApeDecodeCh, &cdb_itb_config); |
|---|
| 522 | INIT_CHECK(BXPT_Rave_AllocContext(GetRAVE(), BXPT_RaveCx_eAv, &cdb_itb_config, &(audio->hAudioDecodeRaveCx))); |
|---|
| 523 | INIT_CHECK(BXPT_Rave_AllocContext(GetRAVE(), BXPT_RaveCx_eAv, &cdb_itb_config, &(audio->hAudioCompressedRaveCx))); |
|---|
| 524 | s_audio.initialized = true; |
|---|
| 525 | |
|---|
| 526 | BKNI_Memset(&audio->config, 0, sizeof(audio->config)); |
|---|
| 527 | /* sync the value between settop api and magnum PI */ |
|---|
| 528 | audio->config.left_volume = audio->config.right_volume = 32; |
|---|
| 529 | audio->config.downmix = baudio_downmix_stereo; |
|---|
| 530 | audio->config.dolby.drc_mode = baudio_dolby_drc_mode_rf; |
|---|
| 531 | audio->config.dolby.cut = 100; |
|---|
| 532 | audio->config.dolby.boost = 100; |
|---|
| 533 | audio->config.dolby.dialog_norm = true; |
|---|
| 534 | audio->config.dolby.stereo_downmix_mode = baudio_dolby_stereo_downmix_mode_automatic; |
|---|
| 535 | audio->config.dualmono = baudio_dualmono_stereo; |
|---|
| 536 | |
|---|
| 537 | audio->config.avl = false; |
|---|
| 538 | audio->config.avl_target = avlSettings.target; |
|---|
| 539 | audio->config.avl_lowerbound = avlSettings.lowerBound; |
|---|
| 540 | audio->config.avl_fixedboost = avlSettings.fixedBoost; |
|---|
| 541 | BAPE_Decoder_GetSettings(audio->hApeDecodeCh, &audio->decoderSettings); |
|---|
| 542 | audio->decoderSettings.dualMonoMode = BAPE_DualMonoMode_eStereo; |
|---|
| 543 | audio->decoderSettings.multichannelFormat = BAPE_MultichannelFormat_e5_1; |
|---|
| 544 | audio->decoderSettings.outputMode = BAPE_ChannelMode_e2_0; |
|---|
| 545 | audio->decoderSettings.outputLfe = true; |
|---|
| 546 | BAPE_Decoder_SetSettings(audio->hApeDecodeCh, &audio->decoderSettings); |
|---|
| 547 | |
|---|
| 548 | BAPE_Decoder_GetCodecSettings(audio->hApeDecodeCh, BAVC_AudioCompressionStd_eAc3, &audio->decoderCodecSettings); |
|---|
| 549 | audio->decoderCodecSettings.codecSettings.ac3.drcMode = baudio_p_map_drc_mode(audio->config.dolby.drc_mode); |
|---|
| 550 | audio->decoderCodecSettings.codecSettings.ac3.drcModeDownmix = baudio_p_map_drc_mode(audio->config.dolby.drc_mode); |
|---|
| 551 | audio->decoderCodecSettings.codecSettings.ac3.stereoMode = baudio_p_map_stereo_downmix_mode(audio->config.dolby.stereo_downmix_mode); /* Stereo Downmix Mode */ |
|---|
| 552 | audio->decoderCodecSettings.codecSettings.ac3.drcScaleHi = 100; /* In %, ranges from 0..100 */ |
|---|
| 553 | audio->decoderCodecSettings.codecSettings.ac3.drcScaleLow = 100; /* In %, ranges from 0..100 */ |
|---|
| 554 | audio->decoderCodecSettings.codecSettings.ac3.drcScaleHiDownmix = 100; /* In %, ranges from 0..100 */ |
|---|
| 555 | audio->decoderCodecSettings.codecSettings.ac3.drcScaleLowDownmix = 100; /* In %, ranges from 0..100 */ |
|---|
| 556 | |
|---|
| 557 | //audio->decoderCodecSettings.codecSettings.ac3.scale; /* PCM Scale factor */ |
|---|
| 558 | //audio->decoderCodecSettings.codecSettings.ac3.scaleDownmix; /* PCM Scale factor for stereo downmixed data only. Applicable to MS11 licensed decoder only. */ |
|---|
| 559 | |
|---|
| 560 | audio->decoderCodecSettings.codecSettings.ac3.dialogNormalization = true; /* Use dialog normalization values from the stream. This should be true for normal operation. */ |
|---|
| 561 | //audio->decoderCodecSettings.codecSettings.ac3.dialogNormalizationValue; /* User-specified dialog normalization value. Used only if dialogNormalization = false. Specified in dB, 0..31 */ |
|---|
| 562 | //audio->decoderCodecSettings.codecSettings.ac3.substreamId = ? |
|---|
| 563 | BAPE_Decoder_SetCodecSettings(audio->hApeDecodeCh, &audio->decoderCodecSettings); |
|---|
| 564 | |
|---|
| 565 | #ifdef CONFIG_AUD_PWR |
|---|
| 566 | BAPE_OutputCapture_Open(audio->apeHandle, 0, NULL, &audio->hCapture); |
|---|
| 567 | BAPE_OutputCapture_GetInterruptHandlers(audio->hCapture, &audio->captureInterruptHandlers); |
|---|
| 568 | audio->captureInterruptHandlers.watermark.pCallback_isr = baudio_decode_capture_isr; |
|---|
| 569 | audio->captureInterruptHandlers.watermark.pParam1 = (void *)audio; |
|---|
| 570 | BAPE_OutputCapture_SetInterruptHandlers(audio->hCapture, &audio->captureInterruptHandlers); |
|---|
| 571 | |
|---|
| 572 | BAPE_OutputCapture_GetOutputPort(audio->hCapture, &outputPort); |
|---|
| 573 | BAPE_Mixer_AddOutput(audio->hDacMixer, outputPort); |
|---|
| 574 | #endif |
|---|
| 575 | BKNI_CreateEventGroup(&audio->raagaEvent); |
|---|
| 576 | BKNI_CreateEvent(&(audio->wdEvent)); |
|---|
| 577 | BKNI_CreateEvent(&(audio->captureEvent)); |
|---|
| 578 | BKNI_AddEventGroup(audio->raagaEvent, audio->wdEvent); |
|---|
| 579 | BKNI_AddEventGroup(audio->raagaEvent, audio->captureEvent); |
|---|
| 580 | task_params.name = "raaga_task"; |
|---|
| 581 | task_params.priority = RAAGA_PRIORITY; |
|---|
| 582 | task_params.stack_size = RAAGA_TASK_STACK; |
|---|
| 583 | task_params.stack = audio->raaga_stack; |
|---|
| 584 | bos_start_task(&(audio->raaga_task), &task_params, baudio_decode_raaga_task, audio); |
|---|
| 585 | |
|---|
| 586 | return audio; |
|---|
| 587 | failed: |
|---|
| 588 | baudio_decode_close(audio); |
|---|
| 589 | return (baudio_decode_t)0; |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | void |
|---|
| 593 | baudio_decode_close(baudio_decode_t audio) |
|---|
| 594 | { |
|---|
| 595 | if (!s_audio.initialized) |
|---|
| 596 | return; |
|---|
| 597 | |
|---|
| 598 | if (audio->hApeDecodeCh) |
|---|
| 599 | BAPE_Decoder_Close(audio->hApeDecodeCh); |
|---|
| 600 | if (audio->apeHandle) |
|---|
| 601 | BAPE_Close(audio->apeHandle); |
|---|
| 602 | if (audio->dspHandle) |
|---|
| 603 | BDSP_Close(audio->dspHandle); |
|---|
| 604 | |
|---|
| 605 | if (audio->hAudioDecodeRaveCx) |
|---|
| 606 | { |
|---|
| 607 | BXPT_Rave_FreeContext(audio->hAudioDecodeRaveCx); |
|---|
| 608 | audio->hAudioDecodeRaveCx = NULL; |
|---|
| 609 | } |
|---|
| 610 | if (audio->hAudioCompressedRaveCx) |
|---|
| 611 | { |
|---|
| 612 | BXPT_Rave_FreeContext(audio->hAudioCompressedRaveCx); |
|---|
| 613 | audio->hAudioDecodeRaveCx = NULL; |
|---|
| 614 | } |
|---|
| 615 | if (s_audio.mutex.queue) |
|---|
| 616 | { |
|---|
| 617 | bos_delete_mutex(&(s_audio.mutex)); |
|---|
| 618 | } |
|---|
| 619 | if (s_audio.wdEvent) |
|---|
| 620 | { |
|---|
| 621 | BKNI_DestroyEvent(s_audio.wdEvent); |
|---|
| 622 | } |
|---|
| 623 | if (s_audio.captureEvent) |
|---|
| 624 | { |
|---|
| 625 | BKNI_DestroyEvent(s_audio.captureEvent); |
|---|
| 626 | } |
|---|
| 627 | if (s_audio.raagaEvent) |
|---|
| 628 | { |
|---|
| 629 | BKNI_DestroyEventGroup(s_audio.raagaEvent); |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | void |
|---|
| 635 | baudio_decode_stop(baudio_decode_t audio) |
|---|
| 636 | { |
|---|
| 637 | BERR_Code rc; |
|---|
| 638 | BDBG_ASSERT(audio); |
|---|
| 639 | b_lock(audio); |
|---|
| 640 | |
|---|
| 641 | if (!audio->audio_decode) |
|---|
| 642 | { |
|---|
| 643 | BDBG_ERR(("baudio_decode_stop - not decoding")); |
|---|
| 644 | b_unlock(audio); |
|---|
| 645 | return; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | if (audio->compressed_decode) |
|---|
| 649 | { |
|---|
| 650 | rc = BXPT_Rave_DisableContext(audio->hAudioCompressedRaveCx); |
|---|
| 651 | if (BERR_SUCCESS != rc) |
|---|
| 652 | { |
|---|
| 653 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d (compressed)", rc)); |
|---|
| 654 | } |
|---|
| 655 | rc = BXPT_Rave_RemovePidChannel(audio->hAudioCompressedRaveCx,B_AUDIO_PIDCH); |
|---|
| 656 | if (BERR_SUCCESS != rc) |
|---|
| 657 | { |
|---|
| 658 | BDBG_ERR(("BXPT_Rave_RemovePidChannel failed %d (compressed)", rc)); |
|---|
| 659 | } |
|---|
| 660 | BAPE_Decoder_Stop(audio->hApeCompressedDecodeCh); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | rc = BXPT_Rave_DisableContext(audio->hAudioDecodeRaveCx); |
|---|
| 664 | if (BERR_SUCCESS != rc) |
|---|
| 665 | { |
|---|
| 666 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d", rc)); |
|---|
| 667 | } |
|---|
| 668 | BAPE_Decoder_Stop(audio->hApeDecodeCh); |
|---|
| 669 | |
|---|
| 670 | rc = BXPT_Rave_RemovePidChannel(audio->hAudioDecodeRaveCx,B_AUDIO_PIDCH); |
|---|
| 671 | if (BERR_SUCCESS != rc) |
|---|
| 672 | { |
|---|
| 673 | BDBG_ERR(("BXPT_Rave_RemovePidChannel failed %d", rc)); |
|---|
| 674 | } |
|---|
| 675 | BXPT_DisablePidChannel(GetXPT(), B_AUDIO_PIDCH); |
|---|
| 676 | // Don't ever free the PID channels !!!!! BXPT_FreePidChannel(GetXPT(), B_AUDIO_PIDCH); |
|---|
| 677 | audio->audio_decode = false; |
|---|
| 678 | if (audio->compressed_decode) { |
|---|
| 679 | baudio_decode_switch_mai_output(audio, false); |
|---|
| 680 | } |
|---|
| 681 | audio->compressed_decode = false; |
|---|
| 682 | audio->is_capture = false; |
|---|
| 683 | b_unlock(audio); |
|---|
| 684 | return; |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | static BERR_Code b_set_context(baudio_decode_t audio, |
|---|
| 688 | BXPT_RaveCx_Handle context, |
|---|
| 689 | bool compressed) |
|---|
| 690 | { |
|---|
| 691 | BERR_Code err; |
|---|
| 692 | BXPT_Rave_AvSettings AvCtxCfg; |
|---|
| 693 | BXPT_Rave_ContextSettings CtxConfig; |
|---|
| 694 | BXPT_Rave_GetContextConfig(context, &CtxConfig); |
|---|
| 695 | |
|---|
| 696 | /* this is the default */ |
|---|
| 697 | CtxConfig.EnablePrivateHdrItbEntry = false; |
|---|
| 698 | CtxConfig.AudFrameInfo = 0; |
|---|
| 699 | |
|---|
| 700 | err = BXPT_Rave_SetContextConfig(context, &CtxConfig); |
|---|
| 701 | if (err != BERR_SUCCESS) |
|---|
| 702 | { |
|---|
| 703 | BDBG_ERR(("BXPT_Rave_SetContextConfig failed %d", err)); |
|---|
| 704 | goto failed; |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | BXPT_Rave_GetAvConfig(context, &AvCtxCfg); |
|---|
| 708 | AvCtxCfg.InputFormat = BAVC_StreamType_eTsMpeg; |
|---|
| 709 | AvCtxCfg.OutputFormat = BAVC_StreamType_eEs; |
|---|
| 710 | BKNI_Memset(AvCtxCfg.EsRanges, 0, sizeof(AvCtxCfg.EsRanges)); /* all disabled */ |
|---|
| 711 | switch (audio->stream->mpeg.audio[0].format) |
|---|
| 712 | { |
|---|
| 713 | case BAVC_AudioCompressionStd_eMpegL1: |
|---|
| 714 | AvCtxCfg.ItbFormat = BAVC_ItbEsType_eMpegAudio; |
|---|
| 715 | AvCtxCfg.StreamIdHi = 0xEF; |
|---|
| 716 | AvCtxCfg.StreamIdLo = 0xC0; |
|---|
| 717 | break; |
|---|
| 718 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 719 | case BAVC_AudioCompressionStd_eAc3Plus: |
|---|
| 720 | AvCtxCfg.ItbFormat = BAVC_ItbEsType_eAc3Plus; /* Use AC3+ ITB type for AC3 */ |
|---|
| 721 | AvCtxCfg.StreamIdHi = 0xEF; |
|---|
| 722 | AvCtxCfg.StreamIdLo = 0xBD; |
|---|
| 723 | break; |
|---|
| 724 | default: |
|---|
| 725 | BDBG_ERR(("Unsupported audio format.")); |
|---|
| 726 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 727 | } |
|---|
| 728 | AvCtxCfg.BandHoldEn = false; |
|---|
| 729 | AvCtxCfg.DisableContinuityCheck = false; |
|---|
| 730 | |
|---|
| 731 | err = BXPT_Rave_SetAvConfig(context, &AvCtxCfg); |
|---|
| 732 | if (err != BERR_SUCCESS) |
|---|
| 733 | { |
|---|
| 734 | BDBG_ERR(("BXPT_Rave_SetContextConfig failed %d", err)); |
|---|
| 735 | goto failed; |
|---|
| 736 | } |
|---|
| 737 | failed: |
|---|
| 738 | return err; |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | bresult |
|---|
| 743 | baudio_decode_start(baudio_decode_t audio, bdisplay_t display, bstream_t stream) |
|---|
| 744 | { |
|---|
| 745 | BERR_Code err; |
|---|
| 746 | bool start_compressed = false; |
|---|
| 747 | /* |
|---|
| 748 | BDBG_SetModuleLevel("rap",BDBG_eMsg); |
|---|
| 749 | BDBG_SetModuleLevel("rap_dec",BDBG_eMsg); |
|---|
| 750 | BDBG_SetModuleLevel("rap_dspchn",BDBG_eMsg); |
|---|
| 751 | BDBG_SetModuleLevel("rap_dsp",BDBG_eMsg); |
|---|
| 752 | BDBG_SetModuleLevel("rap_hifidac",BDBG_eMsg); |
|---|
| 753 | BDBG_SetModuleLevel("rap_fmm",BDBG_eMsg); |
|---|
| 754 | BDBG_SetModuleLevel("rap_spdiffmm",BDBG_eMsg); |
|---|
| 755 | BDBG_SetModuleLevel("rap_srcch",BDBG_eMsg); |
|---|
| 756 | BDBG_SetModuleLevel("rap_mixer",BDBG_eMsg); |
|---|
| 757 | BDBG_SetModuleLevel("BHDM",BDBG_eMsg); |
|---|
| 758 | BDBG_SetModuleLevel("BHDM_HDCP",BDBG_eMsg); |
|---|
| 759 | BDBG_SetModuleLevel("BHDM_EDID",BDBG_eMsg); |
|---|
| 760 | BDBG_SetModuleLevel("BHDM_CEC",BDBG_eMsg); |
|---|
| 761 | BDBG_SetModuleLevel("BHDM_CEC_PRIV",BDBG_eMsg); |
|---|
| 762 | BDBG_SetModuleLevel("BHDM_DVO",BDBG_eMsg); |
|---|
| 763 | */ |
|---|
| 764 | BDBG_ASSERT(audio); |
|---|
| 765 | BDBG_ASSERT(stream); |
|---|
| 766 | b_lock(audio); |
|---|
| 767 | |
|---|
| 768 | if (audio->audio_decode) |
|---|
| 769 | { |
|---|
| 770 | BDBG_ERR(("baudio_decode_start - already decoding")); |
|---|
| 771 | b_unlock(audio); |
|---|
| 772 | baudio_decode_stop(audio); |
|---|
| 773 | b_lock(audio); |
|---|
| 774 | } |
|---|
| 775 | audio->stream = stream; |
|---|
| 776 | |
|---|
| 777 | if (audio->stream->mpeg.audio[0].pid == 0) |
|---|
| 778 | { |
|---|
| 779 | return BERR_INVALID_PARAMETER; |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | err = b_set_context(audio,audio->hAudioDecodeRaveCx,false); |
|---|
| 783 | if (BERR_SUCCESS != err) |
|---|
| 784 | { |
|---|
| 785 | BDBG_ERR(("b_set_context failed %d", err)); |
|---|
| 786 | goto failed; |
|---|
| 787 | } |
|---|
| 788 | err = bstream_p_config_xpt_pid_ch(B_AUDIO_PIDCH, audio->stream->mpeg.audio[0].pid, audio->stream->band); |
|---|
| 789 | if (BERR_SUCCESS != err) |
|---|
| 790 | { |
|---|
| 791 | BDBG_ERR(("bstream_p_config_xpt_pid_ch failed %d", err)); |
|---|
| 792 | goto failed; |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | err = BXPT_Rave_AddPidChannel(audio->hAudioDecodeRaveCx, B_AUDIO_PIDCH, false); |
|---|
| 796 | if (BERR_SUCCESS != err) |
|---|
| 797 | { |
|---|
| 798 | BDBG_ERR(("BXPT_Rave_AddPidChannel failed %d", err)); |
|---|
| 799 | goto failed; |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | if ((audio->stream->mpeg.audio[0].format == BAVC_AudioCompressionStd_eAc3) || |
|---|
| 803 | (audio->stream->mpeg.audio[0].format == BAVC_AudioCompressionStd_eAc3Plus)) |
|---|
| 804 | { |
|---|
| 805 | start_compressed = true; |
|---|
| 806 | } |
|---|
| 807 | #if HAS_HDMI |
|---|
| 808 | if (start_compressed && audio->config.hdmi_compress) { |
|---|
| 809 | baudio_decode_switch_mai_output(audio, true); |
|---|
| 810 | } |
|---|
| 811 | #endif |
|---|
| 812 | BAPE_Decoder_GetDefaultStartSettings(&audio->apeStartSettings); |
|---|
| 813 | audio->apeStartSettings.streamType = BAVC_StreamType_eTsMpeg; |
|---|
| 814 | audio->apeStartSettings.codec = audio->stream->mpeg.audio[0].format; |
|---|
| 815 | audio->apeStartSettings.stcIndex = 0; |
|---|
| 816 | audio->apeStartSettings.targetSyncEnabled = true; |
|---|
| 817 | audio->apeStartSettings.inputPort = NULL; |
|---|
| 818 | |
|---|
| 819 | err = BXPT_Rave_GetContextRegisters(audio->hAudioDecodeRaveCx, (BAVC_XptContextMap*)&audio->sContextMap); |
|---|
| 820 | audio->apeStartSettings.pContextMap = &audio->sContextMap; |
|---|
| 821 | if (BERR_SUCCESS != err) |
|---|
| 822 | { |
|---|
| 823 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 824 | goto failed; |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | err = BXPT_Rave_EnableContext( audio->hAudioDecodeRaveCx ); |
|---|
| 828 | if (BERR_SUCCESS != err) |
|---|
| 829 | { |
|---|
| 830 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 831 | goto failed; |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | #if 0 |
|---|
| 835 | bstream_pcroffset_config_context(audio->stream); |
|---|
| 836 | #endif |
|---|
| 837 | |
|---|
| 838 | bstream_p_pcroffset_pid_ch_config(audio->stream, B_AUDIO_PIDCH); |
|---|
| 839 | /* Compute TSM details */ |
|---|
| 840 | BAPE_Decoder_GetTsmSettings(audio->hApeDecodeCh, &audio->tsmSettings); |
|---|
| 841 | audio->tsmSettings.playback = false; |
|---|
| 842 | audio->tsmSettings.ptsOffset = 0; /* ms, changed from 2000 ms to 0 per audio team's comment */ |
|---|
| 843 | audio->tsmSettings.thresholds.discard = 3000; /* ms */ |
|---|
| 844 | audio->tsmSettings.thresholds.grossAdjustment = 0x8; |
|---|
| 845 | /* RLQ, enable audio TSM, enable audio TSM if there is video as well */ |
|---|
| 846 | audio->tsmSettings.tsmEnabled = audio->stream->mpeg.video[0].pid ? true : false; |
|---|
| 847 | BAPE_Decoder_SetTsmSettings(audio->hApeDecodeCh, &audio->tsmSettings); |
|---|
| 848 | if (BERR_SUCCESS != err) |
|---|
| 849 | { |
|---|
| 850 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 851 | goto failed; |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | err = BAPE_Decoder_Start(audio->hApeDecodeCh, &audio->apeStartSettings); |
|---|
| 856 | if (BERR_SUCCESS != err) |
|---|
| 857 | { |
|---|
| 858 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 859 | goto failed; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | err = BXPT_Rave_EnableContext( audio->hAudioDecodeRaveCx ); |
|---|
| 863 | if (BERR_SUCCESS != err) |
|---|
| 864 | { |
|---|
| 865 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 866 | goto failed; |
|---|
| 867 | } |
|---|
| 868 | #if 0 |
|---|
| 869 | err = BRAP_SetPTSOffset(audio->hRapDecodeCh, 2000); |
|---|
| 870 | if (BERR_SUCCESS != err) |
|---|
| 871 | { |
|---|
| 872 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 873 | goto failed; |
|---|
| 874 | } |
|---|
| 875 | #endif |
|---|
| 876 | audio->audio_decode = true; |
|---|
| 877 | |
|---|
| 878 | /* AC3/AC3 plug and user set the compressed output mode on HDMI */ |
|---|
| 879 | if (start_compressed && audio->config.hdmi_compress) |
|---|
| 880 | { |
|---|
| 881 | audio->compressed_decode = true; |
|---|
| 882 | BDBG_WRN(("HDMI compressed : %s ", audio->stream->mpeg.audio[0].format == BAVC_AudioCompressionStd_eAc3?"AC3":"AC3 Plus")); |
|---|
| 883 | err = b_set_context(audio,audio->hAudioCompressedRaveCx,true); |
|---|
| 884 | if (BERR_SUCCESS != err) |
|---|
| 885 | { |
|---|
| 886 | BDBG_ERR(("b_set_context failed %d", err)); |
|---|
| 887 | goto failed; |
|---|
| 888 | } |
|---|
| 889 | err = BXPT_Rave_AddPidChannel(audio->hAudioCompressedRaveCx, B_AUDIO_PIDCH, false); |
|---|
| 890 | if (BERR_SUCCESS != err) |
|---|
| 891 | { |
|---|
| 892 | BDBG_ERR(("BXPT_Rave_AddPidChannel for compressed failed %d", err)); |
|---|
| 893 | goto failed; |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | err = BXPT_Rave_EnableContext( audio->hAudioCompressedRaveCx ); |
|---|
| 897 | if (BERR_SUCCESS != err) |
|---|
| 898 | { |
|---|
| 899 | BDBG_ERR(("BXPT_Rave_EnableContext for compressed failed %d", err)); |
|---|
| 900 | goto failed; |
|---|
| 901 | } |
|---|
| 902 | BXPT_Rave_GetContextRegisters(audio->hAudioCompressedRaveCx, (BAVC_XptContextMap*)&audio->sCompressedContextMap); |
|---|
| 903 | audio->apeStartSettings.pContextMap = &audio->sCompressedContextMap; |
|---|
| 904 | err = BAPE_Decoder_Start(audio->hApeCompressedDecodeCh, &audio->apeStartSettings); |
|---|
| 905 | if (BERR_SUCCESS != err) |
|---|
| 906 | { |
|---|
| 907 | BDBG_ERR(("BAPE_Decoder_Start for compressed failed %d", err)); |
|---|
| 908 | goto failed; |
|---|
| 909 | } |
|---|
| 910 | } |
|---|
| 911 | audio->is_capture = true; |
|---|
| 912 | b_unlock(audio); |
|---|
| 913 | return b_ok; |
|---|
| 914 | failed: |
|---|
| 915 | b_unlock(audio); |
|---|
| 916 | baudio_decode_stop(audio); |
|---|
| 917 | return err; |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | void baudio_decode_get_config(baudio_decode_t audio, baudio_decode_config *config) |
|---|
| 921 | { |
|---|
| 922 | b_lock(audio); |
|---|
| 923 | *config = audio->config; |
|---|
| 924 | b_unlock(audio); |
|---|
| 925 | |
|---|
| 926 | } |
|---|
| 927 | extern void boutput_set_postprocessing_volume(int volume); |
|---|
| 928 | extern void boutput_set_postprocessing_deemphasized(bool enable); |
|---|
| 929 | |
|---|
| 930 | static BERR_Code baudio_decode_p_set_dualmono(baudio_decode_t audio, baudio_dualmono dualmono) |
|---|
| 931 | { |
|---|
| 932 | BAPE_DecoderSettings settings; |
|---|
| 933 | BERR_Code err = BERR_SUCCESS; |
|---|
| 934 | BAPE_DualMonoMode mode; |
|---|
| 935 | |
|---|
| 936 | BAPE_Decoder_GetSettings(audio->hApeDecodeCh, &settings); |
|---|
| 937 | switch (dualmono) |
|---|
| 938 | { |
|---|
| 939 | case baudio_dualmono_left: |
|---|
| 940 | mode = BAPE_DualMonoMode_eLeft; |
|---|
| 941 | break; |
|---|
| 942 | case baudio_dualmono_right: |
|---|
| 943 | mode = BAPE_DualMonoMode_eRight; |
|---|
| 944 | break; |
|---|
| 945 | case baudio_dualmono_monomix: |
|---|
| 946 | mode = BAPE_DualMonoMode_eMix; |
|---|
| 947 | break; |
|---|
| 948 | case baudio_dualmono_stereo: |
|---|
| 949 | default: |
|---|
| 950 | mode = BAPE_DualMonoMode_eStereo; |
|---|
| 951 | break; |
|---|
| 952 | } |
|---|
| 953 | if (settings.dualMonoMode != mode) { |
|---|
| 954 | settings.dualMonoMode = mode; |
|---|
| 955 | BDBG_WRN(("set dualmono from %d to %d", settings.dualMonoMode, mode)); |
|---|
| 956 | err = BAPE_Decoder_SetSettings(audio->hApeDecodeCh, &settings); |
|---|
| 957 | if (BERR_SUCCESS != err) { |
|---|
| 958 | BDBG_ERR(("BAPE_Decoder_SetSettings failed %d", __LINE__)); |
|---|
| 959 | } |
|---|
| 960 | audio->config.dualmono = dualmono; |
|---|
| 961 | } |
|---|
| 962 | return err; |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | static BERR_Code baudio_decode_p_set_monomix(baudio_decode_t audio, bool bMono) |
|---|
| 966 | { |
|---|
| 967 | BERR_Code err = BERR_SUCCESS; |
|---|
| 968 | BAPE_ChannelMode mode; |
|---|
| 969 | BAPE_DecoderSettings settings; |
|---|
| 970 | |
|---|
| 971 | BAPE_Decoder_GetSettings(audio->hApeDecodeCh, &settings); |
|---|
| 972 | if (bMono) { |
|---|
| 973 | mode = BAPE_ChannelMode_e1_0; |
|---|
| 974 | } |
|---|
| 975 | else { |
|---|
| 976 | mode = BAPE_ChannelMode_e2_0; |
|---|
| 977 | } |
|---|
| 978 | if (settings.outputMode != mode) { |
|---|
| 979 | settings.outputMode = mode; |
|---|
| 980 | settings.outputLfe = true; |
|---|
| 981 | err = BAPE_Decoder_SetSettings(audio->hApeDecodeCh, &settings); |
|---|
| 982 | if (0 == err) { |
|---|
| 983 | audio->config.mono_mix = bMono; |
|---|
| 984 | } |
|---|
| 985 | } |
|---|
| 986 | return err; |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | static BERR_Code baudio_decode_p_set_dolby(baudio_decode_t audio, baudio_dolby_settings dolby, baudio_aac_downmix aac_downmix) |
|---|
| 990 | { |
|---|
| 991 | BERR_Code err = BERR_SUCCESS; |
|---|
| 992 | BAPE_Ac3Settings *pAc3Config; /* currently Ac3 and Ac3 plus only */ |
|---|
| 993 | BAVC_AudioCompressionStd std = BAVC_AudioCompressionStd_eAc3; |
|---|
| 994 | |
|---|
| 995 | /* if there is audio format, use it, otherwise use default */ |
|---|
| 996 | if (audio->stream) |
|---|
| 997 | std = audio->stream->mpeg.audio[0].format; |
|---|
| 998 | |
|---|
| 999 | /* just for AC3 and AC3 plus? */ |
|---|
| 1000 | if (BAVC_AudioCompressionStd_eAc3 != std && BAVC_AudioCompressionStd_eAc3Plus != std) |
|---|
| 1001 | return err; |
|---|
| 1002 | |
|---|
| 1003 | BAPE_Decoder_GetCodecSettings(audio->hApeDecodeCh, std, &audio->decoderCodecSettings); |
|---|
| 1004 | switch (std) |
|---|
| 1005 | { |
|---|
| 1006 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 1007 | case BAVC_AudioCompressionStd_eAc3Plus: |
|---|
| 1008 | if (BAVC_AudioCompressionStd_eAc3 == std) { |
|---|
| 1009 | pAc3Config = &audio->decoderCodecSettings.codecSettings.ac3; |
|---|
| 1010 | } else { |
|---|
| 1011 | pAc3Config = &audio->decoderCodecSettings.codecSettings.ac3Plus; |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | if ( (pAc3Config->stereoMode != baudio_p_map_stereo_downmix_mode(dolby.stereo_downmix_mode)) || |
|---|
| 1015 | (pAc3Config->drcMode != baudio_p_map_drc_mode(dolby.drc_mode)) || |
|---|
| 1016 | (pAc3Config->drcScaleHi != dolby.cut) || |
|---|
| 1017 | (pAc3Config->drcScaleLow != dolby.boost) || |
|---|
| 1018 | (pAc3Config->dialogNormalization != dolby.dialog_norm)) |
|---|
| 1019 | { |
|---|
| 1020 | BDBG_WRN(("Dolby setting for AC3 (drc:%d, cut:%d, boost:%d, dialog:%d)", |
|---|
| 1021 | dolby.drc_mode, dolby.cut, dolby.boost, dolby.dialog_norm)); |
|---|
| 1022 | |
|---|
| 1023 | pAc3Config->stereoMode = baudio_p_map_stereo_downmix_mode(dolby.stereo_downmix_mode); |
|---|
| 1024 | pAc3Config->drcMode = baudio_p_map_drc_mode(dolby.drc_mode); |
|---|
| 1025 | pAc3Config->drcModeDownmix = pAc3Config->drcMode; |
|---|
| 1026 | pAc3Config->drcScaleHi = dolby.cut; |
|---|
| 1027 | pAc3Config->drcScaleHiDownmix = dolby.cut; |
|---|
| 1028 | pAc3Config->drcScaleLow = dolby.boost; |
|---|
| 1029 | pAc3Config->drcScaleLowDownmix = dolby.boost; |
|---|
| 1030 | pAc3Config->dialogNormalization = dolby.dialog_norm; |
|---|
| 1031 | err = BAPE_Decoder_SetCodecSettings(audio->hApeDecodeCh, &audio->decoderCodecSettings); |
|---|
| 1032 | if (0 == err) { |
|---|
| 1033 | audio->config.dolby.drc_mode = dolby.drc_mode; |
|---|
| 1034 | audio->config.dolby.cut = dolby.cut; |
|---|
| 1035 | audio->config.dolby.boost = dolby.boost; |
|---|
| 1036 | audio->config.dolby.dialog_norm = dolby.dialog_norm; |
|---|
| 1037 | audio->config.dolby.stereo_downmix_mode = dolby.stereo_downmix_mode; |
|---|
| 1038 | } |
|---|
| 1039 | } |
|---|
| 1040 | break; |
|---|
| 1041 | default: |
|---|
| 1042 | break; |
|---|
| 1043 | } |
|---|
| 1044 | |
|---|
| 1045 | if (BERR_SUCCESS != err) |
|---|
| 1046 | { |
|---|
| 1047 | BDBG_ERR(("BRAP_SetChannelConfig in %s failed %d", __FUNCTION__, err)); |
|---|
| 1048 | } |
|---|
| 1049 | return err; |
|---|
| 1050 | } |
|---|
| 1051 | |
|---|
| 1052 | /****************************************************************************** |
|---|
| 1053 | The array to represent the value of volume in hex corresponding to the value |
|---|
| 1054 | in DB. The application inputs the volume in terms of DB and the Corresponding |
|---|
| 1055 | HEX value is mentioned here. The formula used for the same is: |
|---|
| 1056 | |
|---|
| 1057 | HEX = (2^23) * 10^(DB/20) |
|---|
| 1058 | |
|---|
| 1059 | Note: 23 is the number of bits in the volume control field. |
|---|
| 1060 | |
|---|
| 1061 | The volume can range from 0-1. 0 in hex corresponds to the 139 DB from the above |
|---|
| 1062 | Formula. If application enters more than this value, it is forced to 0. |
|---|
| 1063 | ******************************************************************************/ |
|---|
| 1064 | static const unsigned int Vol_DB[] = |
|---|
| 1065 | { |
|---|
| 1066 | 0x800000, /* volume 1.000000 <- 0.000000 db */ |
|---|
| 1067 | 0x7a3d32, /* volume 0.954993 <- -0.400000 db */ |
|---|
| 1068 | 0x74bcc5, /* volume 0.912011 <- -0.800000 db */ |
|---|
| 1069 | 0x6f7bbc, /* volume 0.870964 <- -1.200000 db */ |
|---|
| 1070 | 0x6a773c, /* volume 0.831764 <- -1.600000 db */ |
|---|
| 1071 | 0x65ac8c, /* volume 0.776247 <- -2.000000 db */ |
|---|
| 1072 | 0x5ffc88, /* volume 0.683912 <- -2.500000 db */ |
|---|
| 1073 | 0x5a9df7, /* volume 0.616595 <- -3.000000 db */ |
|---|
| 1074 | 0x558c4b, /* volume 0.543250 <- -3.500000 db */ |
|---|
| 1075 | 0x50c335, /* volume 0.478630 <- -4.000000 db */ |
|---|
| 1076 | 0x4b5f3a, /* volume 0.421697 <- -4.600000 db */ |
|---|
| 1077 | 0x46575a, /* volume 0.367282 <- -5.200000 db */ |
|---|
| 1078 | 0x41a571, /* volume 0.575440 <- -5.800000 db */ |
|---|
| 1079 | 0x3c9038, /* volume 0.530884 <- -6.500000 db */ |
|---|
| 1080 | 0x37dfc0, /* volume 0.489779 <- -7.200000 db */ |
|---|
| 1081 | 0x338c3b, /* volume 0.451856 <- -7.900000 db */ |
|---|
| 1082 | 0x2f8e77, /* volume 0.416869 <- -8.600000 db */ |
|---|
| 1083 | 0x2ae025, /* volume 0.375837 <- -9.500000 db */ |
|---|
| 1084 | 0x26a7c7, /* volume 0.338844 <- -10.400000 db */ |
|---|
| 1085 | 0x22d9bf, /* volume 0.305492 <- -11.300000 db */ |
|---|
| 1086 | 0x1f0f84, /* volume 0.272270 <- -12.300000 db */ |
|---|
| 1087 | 0x1baecb, /* volume 0.242661 <- -13.300000 db */ |
|---|
| 1088 | 0x181c57, /* volume 0.211349 <- -14.500000 db */ |
|---|
| 1089 | 0x140dee, /* volume 0.177828 <- -16.000000 db */ |
|---|
| 1090 | 0x10ae37, /* volume 0.154882 <- -17.700000 db */ |
|---|
| 1091 | 0x0d8ef6, /* volume 0.125893 <- -19.500000 db */ |
|---|
| 1092 | 0x0aa586, /* volume 0.104713 <- -21.600000 db */ |
|---|
| 1093 | 0x081385, /* volume 0.079433 <- -24.000000 db */ |
|---|
| 1094 | 0x05b7b1, /* volume 0.063096 <- -27.000000 db */ |
|---|
| 1095 | 0x039b87, /* volume 0.050119 <- -31.000000 db */ |
|---|
| 1096 | 0x01cedc, /* volume 0.035481 <- -37.000000 db */ |
|---|
| 1097 | 0x00a43a, /* volume 0.011220 <- -46.000000 db */ |
|---|
| 1098 | 0x00126d, /* volume 0.000708 <- -65.000000 db */ |
|---|
| 1099 | }; |
|---|
| 1100 | |
|---|
| 1101 | #define max_volume ((sizeof(Vol_DB)/sizeof(Vol_DB[0])) - 1) |
|---|
| 1102 | |
|---|
| 1103 | bresult baudio_decode_set_config(baudio_decode_t audio, const baudio_decode_config *config) |
|---|
| 1104 | { |
|---|
| 1105 | BAPE_OutputVolume volume; |
|---|
| 1106 | BAPE_OutputPort outputPort; |
|---|
| 1107 | BAPE_RfModSettings rfmSettings; |
|---|
| 1108 | BAPE_AutoVolumeLevelSettings avlSettings; |
|---|
| 1109 | BERR_Code rc; |
|---|
| 1110 | int i; |
|---|
| 1111 | b_lock(audio); |
|---|
| 1112 | if ((audio->config.left_volume != config->left_volume) || |
|---|
| 1113 | (audio->config.right_volume != config->right_volume) || |
|---|
| 1114 | (audio->config.mute != config->mute)) |
|---|
| 1115 | { |
|---|
| 1116 | BAPE_Dac_GetOutputPort(audio->hDacOutput, &outputPort); |
|---|
| 1117 | |
|---|
| 1118 | BAPE_GetOutputVolume(outputPort, &volume); |
|---|
| 1119 | volume.muted = config->mute; |
|---|
| 1120 | for (i=0; i<BAPE_ChannelPair_eMax; i++) |
|---|
| 1121 | { |
|---|
| 1122 | volume.volume[i*2] = Vol_DB[max_volume-config->left_volume]; |
|---|
| 1123 | volume.volume[(i*2)+1] = Vol_DB[max_volume-config->right_volume]; |
|---|
| 1124 | } |
|---|
| 1125 | BAPE_SetOutputVolume(outputPort, &volume); |
|---|
| 1126 | #if HAS_HMDI |
|---|
| 1127 | BAPE_MaiOutput_GetOutputPort(audio->hMaiOutput, &outputPort); |
|---|
| 1128 | BAPE_GetOutputVolume(outputPort, &volume); |
|---|
| 1129 | volume.muted = config->mute; |
|---|
| 1130 | for (i=0; i<BAPE_ChannelPair_eMax; i++) |
|---|
| 1131 | { |
|---|
| 1132 | volume.volume[i*2] = Vol_DB[max_volume-config->left_volume]; |
|---|
| 1133 | volume.volume[(i*2)+1] = Vol_DB[max_volume-config->right_volume]; |
|---|
| 1134 | } |
|---|
| 1135 | BAPE_SetOutputVolume(outputPort, &volume); |
|---|
| 1136 | #endif |
|---|
| 1137 | /* RFM output setting */ |
|---|
| 1138 | BAPE_RfMod_GetSettings(audio->hRfmHandle, &rfmSettings); |
|---|
| 1139 | rfmSettings.muted = config->mute; |
|---|
| 1140 | BAPE_RfMod_SetSettings(audio->hRfmHandle, &rfmSettings); |
|---|
| 1141 | } |
|---|
| 1142 | |
|---|
| 1143 | if (audio->config.mono_mix != config->mono_mix) |
|---|
| 1144 | { |
|---|
| 1145 | baudio_decode_p_set_monomix(audio, config->mono_mix); |
|---|
| 1146 | } |
|---|
| 1147 | |
|---|
| 1148 | rc = baudio_decode_p_set_dualmono(audio, config->dualmono); |
|---|
| 1149 | if (rc != BERR_SUCCESS) goto failed; |
|---|
| 1150 | |
|---|
| 1151 | /* dolby setting */ |
|---|
| 1152 | rc = baudio_decode_p_set_dolby(audio, config->dolby, config->aac_downmix); |
|---|
| 1153 | if (rc != BERR_SUCCESS) goto failed; |
|---|
| 1154 | |
|---|
| 1155 | if ((audio->config.avl != config->avl) || (audio->config.avl_target != config->avl_target) || |
|---|
| 1156 | (audio->config.avl_lowerbound != config->avl_lowerbound) || |
|---|
| 1157 | (audio->config.avl_fixedboost != config->avl_fixedboost)) { |
|---|
| 1158 | BDBG_WRN(("AVL %s (T:%d, L:%d, F:%d)", config->avl?"Enabled":"Disabled", |
|---|
| 1159 | config->avl_target/100, config->avl_lowerbound/100, config->avl_fixedboost/100)); |
|---|
| 1160 | BAPE_AutoVolumeLevel_GetSettings(audio->hAvl, &avlSettings); |
|---|
| 1161 | avlSettings.enabled = config->avl; |
|---|
| 1162 | avlSettings.target = config->avl_target; |
|---|
| 1163 | avlSettings.lowerBound = config->avl_lowerbound; |
|---|
| 1164 | avlSettings.fixedBoost = config->avl_fixedboost; |
|---|
| 1165 | rc = BAPE_AutoVolumeLevel_SetSettings(audio->hAvl, &avlSettings); |
|---|
| 1166 | if (rc) { |
|---|
| 1167 | BDBG_WRN(("Fail to %s AVL : %d", config->avl?"enable":"disable", rc)); |
|---|
| 1168 | } |
|---|
| 1169 | } |
|---|
| 1170 | audio->config = *config; |
|---|
| 1171 | |
|---|
| 1172 | failed: |
|---|
| 1173 | b_unlock(audio); |
|---|
| 1174 | |
|---|
| 1175 | return rc; |
|---|
| 1176 | } |
|---|
| 1177 | |
|---|
| 1178 | |
|---|
| 1179 | bresult |
|---|
| 1180 | baudio_decode_get_status(baudio_decode_t audio, baudio_decode_status *status) |
|---|
| 1181 | { |
|---|
| 1182 | BAPE_DecoderStatus decoderStatus; |
|---|
| 1183 | BXPT_Rave_BufferInfo bufInfo; |
|---|
| 1184 | BDBG_ASSERT(audio); |
|---|
| 1185 | BDBG_ASSERT(status); |
|---|
| 1186 | BDBG_ASSERT(audio->apeHandle); |
|---|
| 1187 | |
|---|
| 1188 | BKNI_Memset(status, 0, sizeof(*status)); |
|---|
| 1189 | b_lock(audio); |
|---|
| 1190 | |
|---|
| 1191 | if (audio->stream && audio->hAudioDecodeRaveCx && audio->hApeDecodeCh) |
|---|
| 1192 | { |
|---|
| 1193 | BAPE_Decoder_GetStatus(audio->hApeDecodeCh,&decoderStatus); |
|---|
| 1194 | status->pts = decoderStatus.tsmStatus.ptsInfo.ui32CurrentPTS; |
|---|
| 1195 | |
|---|
| 1196 | if (BXPT_Rave_GetBufferInfo(audio->hAudioDecodeRaveCx, &bufInfo) == BERR_SUCCESS) |
|---|
| 1197 | { |
|---|
| 1198 | status->fifo_depth = bufInfo.CdbDepth; |
|---|
| 1199 | status->fifo_size = bufInfo.CdbSize; |
|---|
| 1200 | } |
|---|
| 1201 | |
|---|
| 1202 | status->pid = audio->stream->mpeg.audio[0].pid; |
|---|
| 1203 | status->stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 1204 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 1205 | } |
|---|
| 1206 | |
|---|
| 1207 | b_unlock(audio); |
|---|
| 1208 | |
|---|
| 1209 | return b_ok; |
|---|
| 1210 | } |
|---|
| 1211 | |
|---|
| 1212 | /* |
|---|
| 1213 | * Summary: |
|---|
| 1214 | * power management for RAAGA block |
|---|
| 1215 | */ |
|---|
| 1216 | void baudio_decode_standby(baudio_decode_t audio, bool standby) |
|---|
| 1217 | { |
|---|
| 1218 | if (standby) { |
|---|
| 1219 | BAPE_Standby(audio->apeHandle, NULL); |
|---|
| 1220 | } |
|---|
| 1221 | else { |
|---|
| 1222 | BAPE_Resume(audio->apeHandle); |
|---|
| 1223 | } |
|---|
| 1224 | } |
|---|
| 1225 | |
|---|
| 1226 | static void baudio_decode_raaga_task(void *arg) |
|---|
| 1227 | { |
|---|
| 1228 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 1229 | baudio_decode_t audio = (baudio_decode_t)arg; |
|---|
| 1230 | BDBG_ASSERT(audio); |
|---|
| 1231 | BKNI_EventHandle events[3]; |
|---|
| 1232 | unsigned nevents,i; |
|---|
| 1233 | |
|---|
| 1234 | while (1) |
|---|
| 1235 | { |
|---|
| 1236 | BKNI_WaitForGroup(audio->raagaEvent, -1, events, sizeof(events)/sizeof(*events), &nevents); |
|---|
| 1237 | |
|---|
| 1238 | for (i=0; i<nevents; i++) { |
|---|
| 1239 | if (events[i] == audio->wdEvent) { |
|---|
| 1240 | b_lock(audio); |
|---|
| 1241 | BDBG_WRN(("Process Raaga watchdog event ")); |
|---|
| 1242 | if (audio->compressed_decode) |
|---|
| 1243 | { |
|---|
| 1244 | rc = BXPT_Rave_DisableContext(audio->hAudioCompressedRaveCx); |
|---|
| 1245 | if (BERR_SUCCESS != rc) |
|---|
| 1246 | { |
|---|
| 1247 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d (compressed)", rc)); |
|---|
| 1248 | } |
|---|
| 1249 | } |
|---|
| 1250 | rc = BXPT_Rave_DisableContext(audio->hAudioDecodeRaveCx); |
|---|
| 1251 | if (BERR_SUCCESS != rc) |
|---|
| 1252 | { |
|---|
| 1253 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d", rc)); |
|---|
| 1254 | } |
|---|
| 1255 | b_unlock(audio); |
|---|
| 1256 | |
|---|
| 1257 | BAPE_ProcessWatchdogInterrupt(audio->apeHandle); |
|---|
| 1258 | |
|---|
| 1259 | b_lock(audio); |
|---|
| 1260 | if (audio->compressed_decode) |
|---|
| 1261 | { |
|---|
| 1262 | rc = BXPT_Rave_EnableContext( audio->hAudioCompressedRaveCx ); |
|---|
| 1263 | if (BERR_SUCCESS != rc) |
|---|
| 1264 | { |
|---|
| 1265 | BDBG_ERR(("BXPT_Rave_EnableContext failed %d (compressed)", rc)); |
|---|
| 1266 | } |
|---|
| 1267 | } |
|---|
| 1268 | rc = BXPT_Rave_EnableContext( audio->hAudioDecodeRaveCx ); |
|---|
| 1269 | if (BERR_SUCCESS != rc) |
|---|
| 1270 | { |
|---|
| 1271 | BDBG_ERR(("BXPT_Rave_EnableContext failed %d", rc)); |
|---|
| 1272 | } |
|---|
| 1273 | b_unlock(audio); |
|---|
| 1274 | } |
|---|
| 1275 | else if (events[i] == audio->captureEvent) { |
|---|
| 1276 | baudio_capture_getbuffer(audio); |
|---|
| 1277 | } |
|---|
| 1278 | } |
|---|
| 1279 | } |
|---|
| 1280 | } |
|---|
| 1281 | |
|---|
| 1282 | /* |
|---|
| 1283 | * Description: |
|---|
| 1284 | * Calculate average power level of 48 samples |
|---|
| 1285 | */ |
|---|
| 1286 | #define NESUB 48 /* 1ms in 48KHz sample rate */ |
|---|
| 1287 | #include "avl_dspfunc.h" |
|---|
| 1288 | static void baudio_capture_getbuffer(baudio_decode_t audio) |
|---|
| 1289 | { |
|---|
| 1290 | #ifdef CONFIG_AUD_PWR |
|---|
| 1291 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 1292 | BAPE_BufferDescriptor bufferDescriptor; |
|---|
| 1293 | size_t bufferSize; |
|---|
| 1294 | |
|---|
| 1295 | void *pCachedBuffer; |
|---|
| 1296 | uint32_t *pSource; |
|---|
| 1297 | |
|---|
| 1298 | Word32 i, tmp, lpower,lgl; |
|---|
| 1299 | Word16 tmp16,t1,t2,fract,expo,shift2; |
|---|
| 1300 | uint32_t num_sample, processed = 0; |
|---|
| 1301 | |
|---|
| 1302 | static Word32 pshift = 14; /* Norm(frsz>>4)-16 */ |
|---|
| 1303 | static Word16 cs = 1; /* channel shift. number of channel-1 */ |
|---|
| 1304 | |
|---|
| 1305 | for (;;) { |
|---|
| 1306 | rc = BAPE_OutputCapture_GetBuffer(audio->hCapture, &bufferDescriptor); |
|---|
| 1307 | if (rc) { |
|---|
| 1308 | BDBG_WRN(("BAPE_OutputCapture_GetBuffer failed")); |
|---|
| 1309 | return; |
|---|
| 1310 | } |
|---|
| 1311 | bufferSize = bufferDescriptor.bufferSize; |
|---|
| 1312 | if (bufferSize == 0) return; |
|---|
| 1313 | BMEM_Heap_ConvertAddressToCached(GetHEAP(), bufferDescriptor.buffers[BAPE_Channel_eLeft].pBuffer, &pCachedBuffer); |
|---|
| 1314 | pSource = pCachedBuffer; |
|---|
| 1315 | num_sample = bufferSize/8; |
|---|
| 1316 | |
|---|
| 1317 | while (processed + NESUB < num_sample) |
|---|
| 1318 | { |
|---|
| 1319 | lpower = 0; /* total power within NESUB samples */ |
|---|
| 1320 | for (i=0; i<NESUB; i++) { |
|---|
| 1321 | tmp = (long)((short)((*pSource++)>>16)); |
|---|
| 1322 | tmp += (long)((short)((*pSource++)>>16)); |
|---|
| 1323 | tmp >>= cs; |
|---|
| 1324 | lpower += (tmp*tmp)>>pshift; |
|---|
| 1325 | } |
|---|
| 1326 | lpower = MPY_32_16(lpower,32767); |
|---|
| 1327 | bvxx_Log2(lpower, &expo, &fract); |
|---|
| 1328 | expo += (Word16)pshift; |
|---|
| 1329 | lgl = (((Word32)expo)<<15)+fract; |
|---|
| 1330 | tmp16 = (16>>4)*NESUB; |
|---|
| 1331 | t1 = Norm16(tmp16); |
|---|
| 1332 | tmp16 = div_s((Word16)(1<<(14-t1)),tmp16); |
|---|
| 1333 | shift2 = 29-t1; |
|---|
| 1334 | bvxx_Log2(tmp16, &t1, &t2); |
|---|
| 1335 | t1 -= shift2; |
|---|
| 1336 | tmp = (((Word32)t1)<<15)+t2; |
|---|
| 1337 | lgl += tmp; |
|---|
| 1338 | lgl = MPY_32_16(lgl,9864); |
|---|
| 1339 | lgl *= 10; |
|---|
| 1340 | lgl = (lgl-2959245)/32768; |
|---|
| 1341 | /* TODO: need to check power value. when updating raaga firmware.*/ |
|---|
| 1342 | audio->energy[audio->ewptr] = lgl+(audio->config.avl?0:3); |
|---|
| 1343 | audio->ewptr++; |
|---|
| 1344 | if (audio->ewptr >= MAX_EBUFFER) audio->ewptr = 0; |
|---|
| 1345 | processed += NESUB; |
|---|
| 1346 | num_sample -= NESUB; |
|---|
| 1347 | } |
|---|
| 1348 | BMEM_Heap_FlushCache(GetHEAP(), pCachedBuffer, bufferSize); |
|---|
| 1349 | rc = BAPE_OutputCapture_ConsumeData(audio->hCapture, bufferSize); |
|---|
| 1350 | if (rc) { |
|---|
| 1351 | BDBG_WRN(("BAPE_OutputCapture_ConsumeData failed")); |
|---|
| 1352 | return; |
|---|
| 1353 | } |
|---|
| 1354 | } |
|---|
| 1355 | #endif |
|---|
| 1356 | } |
|---|
| 1357 | |
|---|
| 1358 | #define MAX_LR_SAMPLES 24 |
|---|
| 1359 | void baudio_decode_test_tone(baudio_decode_t audio, |
|---|
| 1360 | uint32_t *samples, /* array of samples, num_samples long */ |
|---|
| 1361 | uint32_t num_samples, /* Number of samples, should be less than sample array size */ |
|---|
| 1362 | bool leftChannel, /* true - program left channel, flase program right channel */ |
|---|
| 1363 | bool enable /* enable/disable hifidac tone test */ |
|---|
| 1364 | ) |
|---|
| 1365 | { |
|---|
| 1366 | int i; |
|---|
| 1367 | uint32_t reg,offset; |
|---|
| 1368 | BSTD_UNUSED(audio); |
|---|
| 1369 | BDBG_ASSERT(samples); |
|---|
| 1370 | BDBG_ASSERT(num_samples <= MAX_LR_SAMPLES); |
|---|
| 1371 | b_lock(audio); |
|---|
| 1372 | |
|---|
| 1373 | if (leftChannel) |
|---|
| 1374 | offset = 0; |
|---|
| 1375 | else |
|---|
| 1376 | offset = 32 * 4; /* See RDB, right samples start at offset 32 */ |
|---|
| 1377 | |
|---|
| 1378 | for (i = 0; i < num_samples; ++i) |
|---|
| 1379 | { |
|---|
| 1380 | BREG_Write32(GetREG(),BCHP_HIFIDAC_CTRL0_TESTTONE_SAMPLE_i_ARRAY_BASE + (i * 4) + offset,samples[i]); |
|---|
| 1381 | } |
|---|
| 1382 | |
|---|
| 1383 | /* enable/disable test */ |
|---|
| 1384 | reg = 0; |
|---|
| 1385 | |
|---|
| 1386 | if (enable) |
|---|
| 1387 | reg |= (BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_ENABLE_MASK | BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_SHARE_MASK); |
|---|
| 1388 | if (leftChannel) |
|---|
| 1389 | reg |= (BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_RIGHT_MASK | |
|---|
| 1390 | ((num_samples -1) << BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_REPEAT_LEFT_SHIFT)); |
|---|
| 1391 | else |
|---|
| 1392 | reg |= (BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_RIGHT_MASK | |
|---|
| 1393 | ((num_samples -1) << BCHP_HIFIDAC_CTRL0_TEST_TESTTONE_REPEAT_RIGHT_SHIFT)); |
|---|
| 1394 | |
|---|
| 1395 | BREG_Write32(GetREG(),BCHP_HIFIDAC_CTRL0_TEST,reg); |
|---|
| 1396 | |
|---|
| 1397 | b_unlock(audio); |
|---|
| 1398 | } |
|---|
| 1399 | |
|---|
| 1400 | static void baudio_decode_switch_mai_output(baudio_decode_t audio, bool compressed) |
|---|
| 1401 | { |
|---|
| 1402 | #if HAS_HDMI |
|---|
| 1403 | BAPE_MixerAddInputSettings addInputSettings; |
|---|
| 1404 | BAPE_Mixer_GetDefaultAddInputSettings(&addInputSettings); |
|---|
| 1405 | addInputSettings.sampleRateMaster = true; |
|---|
| 1406 | if (compressed) { |
|---|
| 1407 | BAPE_Mixer_RemoveInput(audio->hMaiMixer, audio->connectors[ConnectorType_eAvl]); |
|---|
| 1408 | BAPE_Mixer_AddInput(audio->hMaiMixer, audio->connectors[ConnectorType_eCompressed], &addInputSettings); |
|---|
| 1409 | |
|---|
| 1410 | } |
|---|
| 1411 | else { |
|---|
| 1412 | BAPE_Mixer_RemoveInput(audio->hMaiMixer, audio->connectors[ConnectorType_eCompressed]); |
|---|
| 1413 | BAPE_Mixer_AddInput(audio->hMaiMixer, audio->connectors[ConnectorType_eAvl], &addInputSettings); |
|---|
| 1414 | } |
|---|
| 1415 | #endif |
|---|
| 1416 | } |
|---|