| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2004-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_audyssey_adv.c $ |
|---|
| 39 | * $brcm_Revision: 3 $ |
|---|
| 40 | * $brcm_Date: 8/8/11 5:38p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: AutoVolumeLevel |
|---|
| 44 | * Specific APIs related to Broadcom AutoVolumeLevel (AVL) Audio Processing |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/modules/audio/7422/src/nexus_audyssey_adv.c $ |
|---|
| 49 | * |
|---|
| 50 | * 3 8/8/11 5:38p jgarrett |
|---|
| 51 | * SWDTV-6761: Adding StudioSound |
|---|
| 52 | * |
|---|
| 53 | * 2 5/25/11 5:16p jgarrett |
|---|
| 54 | * SW7425-408: Adding BDBG_OBJECT to input/output types and MS11 features |
|---|
| 55 | * |
|---|
| 56 | * 1 5/16/11 5:19p jgarrett |
|---|
| 57 | * SWDTV-6762: Adding Audyssey ADV/ABX |
|---|
| 58 | * |
|---|
| 59 | ***************************************************************************/ |
|---|
| 60 | |
|---|
| 61 | #include "nexus_audio_module.h" |
|---|
| 62 | |
|---|
| 63 | BDBG_MODULE(nexus_audyssey_adv); |
|---|
| 64 | |
|---|
| 65 | BDBG_OBJECT_ID(NEXUS_AudysseyAdv); |
|---|
| 66 | typedef struct NEXUS_AudysseyAdv |
|---|
| 67 | { |
|---|
| 68 | BDBG_OBJECT(NEXUS_AudysseyAdv) |
|---|
| 69 | NEXUS_AudioInputObject connector; |
|---|
| 70 | NEXUS_AudysseyAdvSettings settings; |
|---|
| 71 | NEXUS_AudioInput input; |
|---|
| 72 | BAPE_AudysseyAdvHandle apeHandle; |
|---|
| 73 | } NEXUS_AudysseyAdv; |
|---|
| 74 | |
|---|
| 75 | void NEXUS_AudysseyAdv_GetDefaultSettings( |
|---|
| 76 | NEXUS_AudysseyAdvSettings *pSettings /* [out] default settings */ |
|---|
| 77 | ) |
|---|
| 78 | { |
|---|
| 79 | BAPE_AudysseyAdvSettings piSettings; |
|---|
| 80 | unsigned i; |
|---|
| 81 | |
|---|
| 82 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 83 | BAPE_AudysseyAdv_GetDefaultSettings(&piSettings); |
|---|
| 84 | |
|---|
| 85 | pSettings->enabled = piSettings.enabled; |
|---|
| 86 | pSettings->channelMask = piSettings.channelMask; |
|---|
| 87 | pSettings->reInitialize = piSettings.reInitialize; |
|---|
| 88 | pSettings->volumeScalingEnabled = piSettings.volumeScalingEnabled; |
|---|
| 89 | pSettings->dynamicSurroundGainEnabled = piSettings.dynamicSurroundGainEnabled; |
|---|
| 90 | pSettings->hiLoCompress = piSettings.hiLoCompress; |
|---|
| 91 | BDBG_CASSERT((int)NEXUS_AudysseyAdvDynamicEqMode_eMax == (int)BAPE_AudysseyAdvDynamicEqMode_eMax); |
|---|
| 92 | pSettings->dynamicEqMode = piSettings.dynamicEqMode; |
|---|
| 93 | pSettings->volume = piSettings.volume; |
|---|
| 94 | pSettings->gainCompression = piSettings.gainCompression; |
|---|
| 95 | pSettings->headroomOffset = piSettings.headroomOffset; |
|---|
| 96 | for ( i = 0; i < 8; i++ ) |
|---|
| 97 | { |
|---|
| 98 | pSettings->chCalbGain[i] = piSettings.chCalbGain[i]; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | NEXUS_AudysseyAdvHandle NEXUS_AudysseyAdv_Open( |
|---|
| 103 | const NEXUS_AudysseyAdvSettings *pSettings /* Pass NULL for default settings */ |
|---|
| 104 | ) |
|---|
| 105 | { |
|---|
| 106 | NEXUS_AudysseyAdvHandle handle; |
|---|
| 107 | BAPE_AudysseyAdvSettings defaults; |
|---|
| 108 | BAPE_Connector connector; |
|---|
| 109 | BERR_Code errCode; |
|---|
| 110 | handle = BKNI_Malloc(sizeof(NEXUS_AudysseyAdv)); |
|---|
| 111 | if ( NULL == handle ) |
|---|
| 112 | { |
|---|
| 113 | (void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 114 | return NULL; |
|---|
| 115 | } |
|---|
| 116 | BKNI_Memset(handle, 0, sizeof(NEXUS_AudysseyAdv)); |
|---|
| 117 | BDBG_OBJECT_SET(handle, NEXUS_AudysseyAdv); |
|---|
| 118 | NEXUS_AUDIO_INPUT_INIT(&handle->connector, NEXUS_AudioInputType_eAudysseyAdv, handle); |
|---|
| 119 | handle->connector.format = NEXUS_AudioInputFormat_eNone; /* Determined by inputs */ |
|---|
| 120 | BAPE_AudysseyAdv_GetDefaultSettings(&defaults); |
|---|
| 121 | errCode = BAPE_AudysseyAdv_Create(NEXUS_AUDIO_DEVICE_HANDLE, &defaults, &handle->apeHandle); |
|---|
| 122 | if ( errCode ) |
|---|
| 123 | { |
|---|
| 124 | (void)BERR_TRACE(errCode); |
|---|
| 125 | BDBG_OBJECT_DESTROY(handle, NEXUS_AudysseyAdv); |
|---|
| 126 | BKNI_Free(handle); |
|---|
| 127 | return NULL; |
|---|
| 128 | } |
|---|
| 129 | handle->connector.format = NEXUS_AudioInputFormat_ePcmStereo; |
|---|
| 130 | BAPE_AudysseyAdv_GetConnector(handle->apeHandle, &connector); |
|---|
| 131 | handle->connector.port = (uint32_t)connector; |
|---|
| 132 | if ( NULL == pSettings ) |
|---|
| 133 | { |
|---|
| 134 | NEXUS_AudysseyAdv_GetDefaultSettings(&handle->settings); |
|---|
| 135 | } |
|---|
| 136 | else |
|---|
| 137 | { |
|---|
| 138 | (void)NEXUS_AudysseyAdv_SetSettings(handle, pSettings); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | return handle; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | void NEXUS_AudysseyAdv_Close( |
|---|
| 145 | NEXUS_AudysseyAdvHandle handle |
|---|
| 146 | ) |
|---|
| 147 | { |
|---|
| 148 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 149 | NEXUS_AudioInput_Shutdown(&handle->connector); |
|---|
| 150 | BAPE_AudysseyAdv_Destroy(handle->apeHandle); |
|---|
| 151 | BDBG_OBJECT_DESTROY(handle, NEXUS_AudysseyAdv); |
|---|
| 152 | BKNI_Free(handle); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | void NEXUS_AudysseyAdv_GetSettings( |
|---|
| 157 | NEXUS_AudysseyAdvHandle handle, |
|---|
| 158 | NEXUS_AudysseyAdvSettings *pSettings /* [out] Settings */ |
|---|
| 159 | ) |
|---|
| 160 | { |
|---|
| 161 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 162 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 163 | |
|---|
| 164 | BKNI_Memcpy(pSettings, &handle->settings, sizeof(NEXUS_AudysseyAdvSettings)); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | NEXUS_Error NEXUS_AudysseyAdv_SetSettings( |
|---|
| 168 | NEXUS_AudysseyAdvHandle handle, |
|---|
| 169 | const NEXUS_AudysseyAdvSettings *pSettings |
|---|
| 170 | ) |
|---|
| 171 | { |
|---|
| 172 | BERR_Code errCode; |
|---|
| 173 | BAPE_AudysseyAdvSettings piSettings; |
|---|
| 174 | unsigned i; |
|---|
| 175 | |
|---|
| 176 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 177 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 178 | |
|---|
| 179 | BAPE_AudysseyAdv_GetSettings(handle->apeHandle, &piSettings); |
|---|
| 180 | |
|---|
| 181 | piSettings.enabled = pSettings->enabled; |
|---|
| 182 | piSettings.channelMask = pSettings->channelMask; |
|---|
| 183 | piSettings.reInitialize = pSettings->reInitialize; |
|---|
| 184 | piSettings.volumeScalingEnabled = pSettings->volumeScalingEnabled; |
|---|
| 185 | piSettings.dynamicSurroundGainEnabled = pSettings->dynamicSurroundGainEnabled; |
|---|
| 186 | piSettings.hiLoCompress = pSettings->hiLoCompress; |
|---|
| 187 | piSettings.dynamicEqMode = pSettings->dynamicEqMode; |
|---|
| 188 | piSettings.volume = pSettings->volume; |
|---|
| 189 | piSettings.gainCompression = pSettings->gainCompression; |
|---|
| 190 | piSettings.headroomOffset = pSettings->headroomOffset; |
|---|
| 191 | for ( i = 0; i < 8; i++ ) |
|---|
| 192 | { |
|---|
| 193 | piSettings.chCalbGain[i] = pSettings->chCalbGain[i]; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | errCode = BAPE_AudysseyAdv_SetSettings(handle->apeHandle, &piSettings); |
|---|
| 197 | if ( errCode ) |
|---|
| 198 | { |
|---|
| 199 | return BERR_TRACE(errCode); |
|---|
| 200 | } |
|---|
| 201 | BKNI_Memcpy(&handle->settings, pSettings, sizeof(NEXUS_AudysseyAdvSettings)); |
|---|
| 202 | return BERR_SUCCESS; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | NEXUS_Error NEXUS_AudysseyAdv_GetStatus( |
|---|
| 206 | NEXUS_AudysseyAdvHandle handle, |
|---|
| 207 | NEXUS_AudysseyAdvStatus *pStatus /* [out] current status */ |
|---|
| 208 | ) |
|---|
| 209 | { |
|---|
| 210 | BAPE_AudysseyAdvStatus piStatus; |
|---|
| 211 | BERR_Code errCode; |
|---|
| 212 | unsigned i; |
|---|
| 213 | |
|---|
| 214 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 215 | BDBG_ASSERT(NULL != pStatus); |
|---|
| 216 | |
|---|
| 217 | errCode = BAPE_AudysseyAdv_GetStatus(handle->apeHandle, &piStatus); |
|---|
| 218 | if ( errCode ) |
|---|
| 219 | { |
|---|
| 220 | return BERR_TRACE(errCode); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | pStatus->volumeApplied = piStatus.volumeApplied; |
|---|
| 224 | for ( i = 0; i < 8; i++ ) |
|---|
| 225 | { |
|---|
| 226 | pStatus->chCalcLevel[i] = piStatus.chCalcLevel[i]; |
|---|
| 227 | } |
|---|
| 228 | pStatus->numChannels = piStatus.numChannels; |
|---|
| 229 | pStatus->dynamicEqMode = (NEXUS_AudysseyAdvDynamicEqMode)piStatus.dynamicEqMode; |
|---|
| 230 | |
|---|
| 231 | return BERR_SUCCESS; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | NEXUS_AudioInput NEXUS_AudysseyAdv_GetConnector( |
|---|
| 235 | NEXUS_AudysseyAdvHandle handle |
|---|
| 236 | ) |
|---|
| 237 | { |
|---|
| 238 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 239 | return &handle->connector; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | NEXUS_Error NEXUS_AudysseyAdv_AddInput( |
|---|
| 243 | NEXUS_AudysseyAdvHandle handle, |
|---|
| 244 | NEXUS_AudioInput input |
|---|
| 245 | ) |
|---|
| 246 | { |
|---|
| 247 | NEXUS_Error errCode; |
|---|
| 248 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 249 | BDBG_ASSERT(NULL != input); |
|---|
| 250 | if ( NULL != handle->input ) |
|---|
| 251 | { |
|---|
| 252 | BDBG_ERR(("Only one input can be added")); |
|---|
| 253 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 254 | } |
|---|
| 255 | errCode = BAPE_AudysseyAdv_AddInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 256 | if ( errCode ) |
|---|
| 257 | { |
|---|
| 258 | return BERR_TRACE(errCode); |
|---|
| 259 | } |
|---|
| 260 | errCode = NEXUS_AudioInput_P_AddInput(&handle->connector, input); |
|---|
| 261 | if ( errCode ) |
|---|
| 262 | { |
|---|
| 263 | (void)BAPE_AudysseyAdv_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 264 | return BERR_TRACE(errCode); |
|---|
| 265 | } |
|---|
| 266 | handle->input = input; |
|---|
| 267 | return BERR_SUCCESS; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | NEXUS_Error NEXUS_AudysseyAdv_RemoveInput( |
|---|
| 271 | NEXUS_AudysseyAdvHandle handle, |
|---|
| 272 | NEXUS_AudioInput input |
|---|
| 273 | ) |
|---|
| 274 | { |
|---|
| 275 | NEXUS_Error errCode; |
|---|
| 276 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 277 | BDBG_ASSERT(NULL != handle->input); |
|---|
| 278 | if ( input != handle->input ) |
|---|
| 279 | { |
|---|
| 280 | BDBG_ERR(("Input not connected")); |
|---|
| 281 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 282 | } |
|---|
| 283 | errCode = BAPE_AudysseyAdv_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 284 | if ( errCode ) |
|---|
| 285 | { |
|---|
| 286 | return BERR_TRACE(errCode); |
|---|
| 287 | } |
|---|
| 288 | errCode = NEXUS_AudioInput_P_RemoveInput(&handle->connector, input); |
|---|
| 289 | if ( errCode ) |
|---|
| 290 | { |
|---|
| 291 | return BERR_TRACE(errCode); |
|---|
| 292 | } |
|---|
| 293 | handle->input = NULL; |
|---|
| 294 | return BERR_SUCCESS; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | NEXUS_Error NEXUS_AudysseyAdv_RemoveAllInputs( |
|---|
| 298 | NEXUS_AudysseyAdvHandle handle |
|---|
| 299 | ) |
|---|
| 300 | { |
|---|
| 301 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAdv); |
|---|
| 302 | if ( handle->input ) |
|---|
| 303 | { |
|---|
| 304 | return NEXUS_AudysseyAdv_RemoveInput(handle, handle->input); |
|---|
| 305 | } |
|---|
| 306 | return BERR_SUCCESS; |
|---|
| 307 | } |
|---|
| 308 | |
|---|