| 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_abx.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_abx.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_abx); |
|---|
| 64 | |
|---|
| 65 | BDBG_OBJECT_ID(NEXUS_AudysseyAbx); |
|---|
| 66 | typedef struct NEXUS_AudysseyAbx |
|---|
| 67 | { |
|---|
| 68 | BDBG_OBJECT(NEXUS_AudysseyAbx) |
|---|
| 69 | NEXUS_AudioInputObject connector; |
|---|
| 70 | NEXUS_AudysseyAbxSettings settings; |
|---|
| 71 | NEXUS_AudioInput input; |
|---|
| 72 | BAPE_AudysseyAbxHandle apeHandle; |
|---|
| 73 | } NEXUS_AudysseyAbx; |
|---|
| 74 | |
|---|
| 75 | void NEXUS_AudysseyAbx_GetDefaultSettings( |
|---|
| 76 | NEXUS_AudysseyAbxSettings *pSettings /* [out] default settings */ |
|---|
| 77 | ) |
|---|
| 78 | { |
|---|
| 79 | BAPE_AudysseyAbxSettings piSettings; |
|---|
| 80 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 81 | BAPE_AudysseyAbx_GetDefaultSettings(&piSettings); |
|---|
| 82 | pSettings->enabled = piSettings.enabled; |
|---|
| 83 | pSettings->filterSet = piSettings.filterSet; |
|---|
| 84 | pSettings->harmonicGain = piSettings.harmonicGain; |
|---|
| 85 | pSettings->dryGain = piSettings.dryGain; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | NEXUS_AudysseyAbxHandle NEXUS_AudysseyAbx_Open( |
|---|
| 89 | const NEXUS_AudysseyAbxSettings *pSettings /* Pass NULL for default settings */ |
|---|
| 90 | ) |
|---|
| 91 | { |
|---|
| 92 | NEXUS_AudysseyAbxHandle handle; |
|---|
| 93 | BAPE_AudysseyAbxSettings defaults; |
|---|
| 94 | BAPE_Connector connector; |
|---|
| 95 | BERR_Code errCode; |
|---|
| 96 | handle = BKNI_Malloc(sizeof(NEXUS_AudysseyAbx)); |
|---|
| 97 | if ( NULL == handle ) |
|---|
| 98 | { |
|---|
| 99 | (void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 100 | return NULL; |
|---|
| 101 | } |
|---|
| 102 | BKNI_Memset(handle, 0, sizeof(NEXUS_AudysseyAbx)); |
|---|
| 103 | BDBG_OBJECT_SET(handle, NEXUS_AudysseyAbx); |
|---|
| 104 | NEXUS_AUDIO_INPUT_INIT(&handle->connector, NEXUS_AudioInputType_eAudysseyAbx, handle); |
|---|
| 105 | handle->connector.format = NEXUS_AudioInputFormat_eNone; /* Determined by inputs */ |
|---|
| 106 | BAPE_AudysseyAbx_GetDefaultSettings(&defaults); |
|---|
| 107 | errCode = BAPE_AudysseyAbx_Create(NEXUS_AUDIO_DEVICE_HANDLE, &defaults, &handle->apeHandle); |
|---|
| 108 | if ( errCode ) |
|---|
| 109 | { |
|---|
| 110 | (void)BERR_TRACE(errCode); |
|---|
| 111 | BDBG_OBJECT_DESTROY(handle, NEXUS_AudysseyAbx); |
|---|
| 112 | BKNI_Free(handle); |
|---|
| 113 | return NULL; |
|---|
| 114 | } |
|---|
| 115 | handle->connector.format = NEXUS_AudioInputFormat_ePcmStereo; |
|---|
| 116 | BAPE_AudysseyAbx_GetConnector(handle->apeHandle, &connector); |
|---|
| 117 | handle->connector.port = (uint32_t)connector; |
|---|
| 118 | if ( NULL == pSettings ) |
|---|
| 119 | { |
|---|
| 120 | NEXUS_AudysseyAbx_GetDefaultSettings(&handle->settings); |
|---|
| 121 | } |
|---|
| 122 | else |
|---|
| 123 | { |
|---|
| 124 | (void)NEXUS_AudysseyAbx_SetSettings(handle, pSettings); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | return handle; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | void NEXUS_AudysseyAbx_Close( |
|---|
| 131 | NEXUS_AudysseyAbxHandle handle |
|---|
| 132 | ) |
|---|
| 133 | { |
|---|
| 134 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 135 | NEXUS_AudioInput_Shutdown(&handle->connector); |
|---|
| 136 | BAPE_AudysseyAbx_Destroy(handle->apeHandle); |
|---|
| 137 | BDBG_OBJECT_DESTROY(handle, NEXUS_AudysseyAbx); |
|---|
| 138 | BKNI_Free(handle); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | void NEXUS_AudysseyAbx_GetSettings( |
|---|
| 143 | NEXUS_AudysseyAbxHandle handle, |
|---|
| 144 | NEXUS_AudysseyAbxSettings *pSettings /* [out] Settings */ |
|---|
| 145 | ) |
|---|
| 146 | { |
|---|
| 147 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 148 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 149 | |
|---|
| 150 | BKNI_Memcpy(pSettings, &handle->settings, sizeof(NEXUS_AudysseyAbxSettings)); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | NEXUS_Error NEXUS_AudysseyAbx_SetSettings( |
|---|
| 154 | NEXUS_AudysseyAbxHandle handle, |
|---|
| 155 | const NEXUS_AudysseyAbxSettings *pSettings |
|---|
| 156 | ) |
|---|
| 157 | { |
|---|
| 158 | BERR_Code errCode; |
|---|
| 159 | BAPE_AudysseyAbxSettings piSettings; |
|---|
| 160 | |
|---|
| 161 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 162 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 163 | |
|---|
| 164 | BAPE_AudysseyAbx_GetSettings(handle->apeHandle, &piSettings); |
|---|
| 165 | |
|---|
| 166 | piSettings.enabled = pSettings->enabled; |
|---|
| 167 | piSettings.filterSet = pSettings->filterSet; |
|---|
| 168 | piSettings.harmonicGain = pSettings->harmonicGain; |
|---|
| 169 | piSettings.dryGain = pSettings->dryGain; |
|---|
| 170 | |
|---|
| 171 | errCode = BAPE_AudysseyAbx_SetSettings(handle->apeHandle, &piSettings); |
|---|
| 172 | if ( errCode ) |
|---|
| 173 | { |
|---|
| 174 | return BERR_TRACE(errCode); |
|---|
| 175 | } |
|---|
| 176 | BKNI_Memcpy(&handle->settings, pSettings, sizeof(NEXUS_AudysseyAbxSettings)); |
|---|
| 177 | return BERR_SUCCESS; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | NEXUS_AudioInput NEXUS_AudysseyAbx_GetConnector( |
|---|
| 181 | NEXUS_AudysseyAbxHandle handle |
|---|
| 182 | ) |
|---|
| 183 | { |
|---|
| 184 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 185 | return &handle->connector; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | NEXUS_Error NEXUS_AudysseyAbx_AddInput( |
|---|
| 189 | NEXUS_AudysseyAbxHandle handle, |
|---|
| 190 | NEXUS_AudioInput input |
|---|
| 191 | ) |
|---|
| 192 | { |
|---|
| 193 | NEXUS_Error errCode; |
|---|
| 194 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 195 | BDBG_ASSERT(NULL != input); |
|---|
| 196 | if ( NULL != handle->input ) |
|---|
| 197 | { |
|---|
| 198 | BDBG_ERR(("Only one input can be added")); |
|---|
| 199 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 200 | } |
|---|
| 201 | errCode = BAPE_AudysseyAbx_AddInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 202 | if ( errCode ) |
|---|
| 203 | { |
|---|
| 204 | return BERR_TRACE(errCode); |
|---|
| 205 | } |
|---|
| 206 | errCode = NEXUS_AudioInput_P_AddInput(&handle->connector, input); |
|---|
| 207 | if ( errCode ) |
|---|
| 208 | { |
|---|
| 209 | (void)BAPE_AudysseyAbx_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 210 | return BERR_TRACE(errCode); |
|---|
| 211 | } |
|---|
| 212 | handle->input = input; |
|---|
| 213 | return BERR_SUCCESS; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | NEXUS_Error NEXUS_AudysseyAbx_RemoveInput( |
|---|
| 217 | NEXUS_AudysseyAbxHandle handle, |
|---|
| 218 | NEXUS_AudioInput input |
|---|
| 219 | ) |
|---|
| 220 | { |
|---|
| 221 | NEXUS_Error errCode; |
|---|
| 222 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 223 | BDBG_ASSERT(NULL != handle->input); |
|---|
| 224 | if ( input != handle->input ) |
|---|
| 225 | { |
|---|
| 226 | BDBG_ERR(("Input not connected")); |
|---|
| 227 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 228 | } |
|---|
| 229 | errCode = BAPE_AudysseyAbx_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 230 | if ( errCode ) |
|---|
| 231 | { |
|---|
| 232 | return BERR_TRACE(errCode); |
|---|
| 233 | } |
|---|
| 234 | errCode = NEXUS_AudioInput_P_RemoveInput(&handle->connector, input); |
|---|
| 235 | if ( errCode ) |
|---|
| 236 | { |
|---|
| 237 | return BERR_TRACE(errCode); |
|---|
| 238 | } |
|---|
| 239 | handle->input = NULL; |
|---|
| 240 | return BERR_SUCCESS; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | NEXUS_Error NEXUS_AudysseyAbx_RemoveAllInputs( |
|---|
| 244 | NEXUS_AudysseyAbxHandle handle |
|---|
| 245 | ) |
|---|
| 246 | { |
|---|
| 247 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudysseyAbx); |
|---|
| 248 | if ( handle->input ) |
|---|
| 249 | { |
|---|
| 250 | return NEXUS_AudysseyAbx_RemoveInput(handle, handle->input); |
|---|
| 251 | } |
|---|
| 252 | return BERR_SUCCESS; |
|---|
| 253 | } |
|---|
| 254 | |
|---|