| 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_3d_surround.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_3d_surround.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 4:57p jgarrett |
|---|
| 57 | * SWDTV-6763: Adding 3D Surround |
|---|
| 58 | * |
|---|
| 59 | ***************************************************************************/ |
|---|
| 60 | |
|---|
| 61 | #include "nexus_audio_module.h" |
|---|
| 62 | |
|---|
| 63 | BDBG_MODULE(nexus_3d_surround); |
|---|
| 64 | |
|---|
| 65 | BDBG_OBJECT_ID(NEXUS_3dSurround); |
|---|
| 66 | typedef struct NEXUS_3dSurround |
|---|
| 67 | { |
|---|
| 68 | BDBG_OBJECT(NEXUS_3dSurround) |
|---|
| 69 | NEXUS_AudioInputObject connector; |
|---|
| 70 | NEXUS_3dSurroundSettings settings; |
|---|
| 71 | NEXUS_AudioInput input; |
|---|
| 72 | BAPE_3dSurroundHandle apeHandle; |
|---|
| 73 | } NEXUS_3dSurround; |
|---|
| 74 | |
|---|
| 75 | void NEXUS_3dSurround_GetDefaultSettings( |
|---|
| 76 | NEXUS_3dSurroundSettings *pSettings /* [out] default settings */ |
|---|
| 77 | ) |
|---|
| 78 | { |
|---|
| 79 | BAPE_3dSurroundSettings piSettings; |
|---|
| 80 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 81 | BAPE_3dSurround_GetDefaultSettings(&piSettings); |
|---|
| 82 | pSettings->enabled = piSettings.enabled; |
|---|
| 83 | pSettings->softLimiterEnabled = piSettings.softLimiterEnabled; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | NEXUS_3dSurroundHandle NEXUS_3dSurround_Open( |
|---|
| 87 | const NEXUS_3dSurroundSettings *pSettings /* Pass NULL for default settings */ |
|---|
| 88 | ) |
|---|
| 89 | { |
|---|
| 90 | NEXUS_3dSurroundHandle handle; |
|---|
| 91 | BAPE_3dSurroundSettings defaults; |
|---|
| 92 | BAPE_Connector connector; |
|---|
| 93 | BERR_Code errCode; |
|---|
| 94 | handle = BKNI_Malloc(sizeof(NEXUS_3dSurround)); |
|---|
| 95 | if ( NULL == handle ) |
|---|
| 96 | { |
|---|
| 97 | (void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 98 | return NULL; |
|---|
| 99 | } |
|---|
| 100 | BKNI_Memset(handle, 0, sizeof(NEXUS_3dSurround)); |
|---|
| 101 | BDBG_OBJECT_SET(handle, NEXUS_3dSurround); |
|---|
| 102 | NEXUS_AUDIO_INPUT_INIT(&handle->connector, NEXUS_AudioInputType_e3dSurround, handle); |
|---|
| 103 | handle->connector.format = NEXUS_AudioInputFormat_eNone; /* Determined by inputs */ |
|---|
| 104 | BAPE_3dSurround_GetDefaultSettings(&defaults); |
|---|
| 105 | errCode = BAPE_3dSurround_Create(NEXUS_AUDIO_DEVICE_HANDLE, &defaults, &handle->apeHandle); |
|---|
| 106 | if ( errCode ) |
|---|
| 107 | { |
|---|
| 108 | (void)BERR_TRACE(errCode); |
|---|
| 109 | BDBG_OBJECT_DESTROY(handle, NEXUS_3dSurround); |
|---|
| 110 | BKNI_Free(handle); |
|---|
| 111 | return NULL; |
|---|
| 112 | } |
|---|
| 113 | handle->connector.format = NEXUS_AudioInputFormat_ePcmStereo; |
|---|
| 114 | BAPE_3dSurround_GetConnector(handle->apeHandle, &connector); |
|---|
| 115 | handle->connector.port = (uint32_t)connector; |
|---|
| 116 | if ( NULL == pSettings ) |
|---|
| 117 | { |
|---|
| 118 | NEXUS_3dSurround_GetDefaultSettings(&handle->settings); |
|---|
| 119 | } |
|---|
| 120 | else |
|---|
| 121 | { |
|---|
| 122 | (void)NEXUS_3dSurround_SetSettings(handle, pSettings); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | return handle; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | void NEXUS_3dSurround_Close( |
|---|
| 129 | NEXUS_3dSurroundHandle handle |
|---|
| 130 | ) |
|---|
| 131 | { |
|---|
| 132 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 133 | NEXUS_AudioInput_Shutdown(&handle->connector); |
|---|
| 134 | BAPE_3dSurround_Destroy(handle->apeHandle); |
|---|
| 135 | BDBG_OBJECT_DESTROY(handle, NEXUS_3dSurround); |
|---|
| 136 | BKNI_Free(handle); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | void NEXUS_3dSurround_GetSettings( |
|---|
| 141 | NEXUS_3dSurroundHandle handle, |
|---|
| 142 | NEXUS_3dSurroundSettings *pSettings /* [out] Settings */ |
|---|
| 143 | ) |
|---|
| 144 | { |
|---|
| 145 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 146 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 147 | |
|---|
| 148 | BKNI_Memcpy(pSettings, &handle->settings, sizeof(NEXUS_3dSurroundSettings)); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | NEXUS_Error NEXUS_3dSurround_SetSettings( |
|---|
| 152 | NEXUS_3dSurroundHandle handle, |
|---|
| 153 | const NEXUS_3dSurroundSettings *pSettings |
|---|
| 154 | ) |
|---|
| 155 | { |
|---|
| 156 | BERR_Code errCode; |
|---|
| 157 | BAPE_3dSurroundSettings piSettings; |
|---|
| 158 | |
|---|
| 159 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 160 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 161 | |
|---|
| 162 | BAPE_3dSurround_GetSettings(handle->apeHandle, &piSettings); |
|---|
| 163 | |
|---|
| 164 | piSettings.enabled = pSettings->enabled; |
|---|
| 165 | piSettings.softLimiterEnabled = pSettings->softLimiterEnabled; |
|---|
| 166 | |
|---|
| 167 | errCode = BAPE_3dSurround_SetSettings(handle->apeHandle, &piSettings); |
|---|
| 168 | if ( errCode ) |
|---|
| 169 | { |
|---|
| 170 | return BERR_TRACE(errCode); |
|---|
| 171 | } |
|---|
| 172 | BKNI_Memcpy(&handle->settings, pSettings, sizeof(NEXUS_3dSurroundSettings)); |
|---|
| 173 | return BERR_SUCCESS; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | NEXUS_AudioInput NEXUS_3dSurround_GetConnector( |
|---|
| 177 | NEXUS_3dSurroundHandle handle |
|---|
| 178 | ) |
|---|
| 179 | { |
|---|
| 180 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 181 | return &handle->connector; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | NEXUS_Error NEXUS_3dSurround_AddInput( |
|---|
| 185 | NEXUS_3dSurroundHandle handle, |
|---|
| 186 | NEXUS_AudioInput input |
|---|
| 187 | ) |
|---|
| 188 | { |
|---|
| 189 | NEXUS_Error errCode; |
|---|
| 190 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 191 | BDBG_ASSERT(NULL != input); |
|---|
| 192 | if ( NULL != handle->input ) |
|---|
| 193 | { |
|---|
| 194 | BDBG_ERR(("Only one input can be added")); |
|---|
| 195 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 196 | } |
|---|
| 197 | errCode = BAPE_3dSurround_AddInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 198 | if ( errCode ) |
|---|
| 199 | { |
|---|
| 200 | return BERR_TRACE(errCode); |
|---|
| 201 | } |
|---|
| 202 | errCode = NEXUS_AudioInput_P_AddInput(&handle->connector, input); |
|---|
| 203 | if ( errCode ) |
|---|
| 204 | { |
|---|
| 205 | (void)BAPE_3dSurround_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 206 | return BERR_TRACE(errCode); |
|---|
| 207 | } |
|---|
| 208 | handle->input = input; |
|---|
| 209 | return BERR_SUCCESS; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | NEXUS_Error NEXUS_3dSurround_RemoveInput( |
|---|
| 213 | NEXUS_3dSurroundHandle handle, |
|---|
| 214 | NEXUS_AudioInput input |
|---|
| 215 | ) |
|---|
| 216 | { |
|---|
| 217 | NEXUS_Error errCode; |
|---|
| 218 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 219 | BDBG_ASSERT(NULL != handle->input); |
|---|
| 220 | if ( input != handle->input ) |
|---|
| 221 | { |
|---|
| 222 | BDBG_ERR(("Input not connected")); |
|---|
| 223 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 224 | } |
|---|
| 225 | errCode = BAPE_3dSurround_RemoveInput(handle->apeHandle, (BAPE_Connector)input->port); |
|---|
| 226 | if ( errCode ) |
|---|
| 227 | { |
|---|
| 228 | return BERR_TRACE(errCode); |
|---|
| 229 | } |
|---|
| 230 | errCode = NEXUS_AudioInput_P_RemoveInput(&handle->connector, input); |
|---|
| 231 | if ( errCode ) |
|---|
| 232 | { |
|---|
| 233 | return BERR_TRACE(errCode); |
|---|
| 234 | } |
|---|
| 235 | handle->input = NULL; |
|---|
| 236 | return BERR_SUCCESS; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | NEXUS_Error NEXUS_3dSurround_RemoveAllInputs( |
|---|
| 240 | NEXUS_3dSurroundHandle handle |
|---|
| 241 | ) |
|---|
| 242 | { |
|---|
| 243 | BDBG_OBJECT_ASSERT(handle, NEXUS_3dSurround); |
|---|
| 244 | if ( handle->input ) |
|---|
| 245 | { |
|---|
| 246 | return NEXUS_3dSurround_RemoveInput(handle, handle->input); |
|---|
| 247 | } |
|---|
| 248 | return BERR_SUCCESS; |
|---|
| 249 | } |
|---|
| 250 | |
|---|