| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-2011, 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: bape_equalizer.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/14 $ |
|---|
| 12 | * $brcm_Date: 9/15/11 3:36p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: Audio Equalizer Interface |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/ape/7422/bape_equalizer.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/14 9/15/11 3:36p jgarrett |
|---|
| 21 | * SWDTV-8673: Returning error instead of asserting if stages are changed |
|---|
| 22 | * while running |
|---|
| 23 | * |
|---|
| 24 | * Hydra_Software_Devel/14 9/15/11 3:27p jgarrett |
|---|
| 25 | * SWDTV-8673: Returning error instead of asserting if stages are changed |
|---|
| 26 | * while running |
|---|
| 27 | * |
|---|
| 28 | * Hydra_Software_Devel/13 9/8/11 10:42a jgarrett |
|---|
| 29 | * SWDTV-6627: Adding BAPE_Equalizer_GetDefaultSettings stub for chips |
|---|
| 30 | * w/out EQ support |
|---|
| 31 | * |
|---|
| 32 | * Hydra_Software_Devel/12 9/7/11 8:05p jgarrett |
|---|
| 33 | * SWDTV-6627: Fixing memory leaks |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/11 9/7/11 7:31p sgadara |
|---|
| 36 | * SWDTV-6627: [35233] Correcting the enums |
|---|
| 37 | * |
|---|
| 38 | * Hydra_Software_Devel/10 9/7/11 6:37p sgadara |
|---|
| 39 | * SWDTV-6627: [35233] Initializing required SRC registers and fixing the |
|---|
| 40 | * coeffcient register bit format |
|---|
| 41 | * |
|---|
| 42 | * Hydra_Software_Devel/9 9/7/11 4:30p sgadara |
|---|
| 43 | * SWDTV-6627: [35233] Support shallow EQ object-No Eq stages |
|---|
| 44 | * |
|---|
| 45 | * Hydra_Software_Devel/8 9/7/11 3:14p jgarrett |
|---|
| 46 | * SWDTV-6627: Adding BAPE_Equalizer_GetDefaultSettings |
|---|
| 47 | * |
|---|
| 48 | * Hydra_Software_Devel/7 9/2/11 4:01p sgadara |
|---|
| 49 | * SWDTV-6627: [35233] Refine the SRC coefficient memory allocation |
|---|
| 50 | * |
|---|
| 51 | * Hydra_Software_Devel/6 8/29/11 4:18p jgarrett |
|---|
| 52 | * SWDTV-6627: Fixing warnings in stub routines |
|---|
| 53 | * |
|---|
| 54 | * Hydra_Software_Devel/5 8/26/11 9:50p sgadara |
|---|
| 55 | * SWDTV-6627: [35233] Add Equalizer support |
|---|
| 56 | * |
|---|
| 57 | * Hydra_Software_Devel/4 8/15/11 12:12p jgarrett |
|---|
| 58 | * SWDTV-6627: Coverity CID 633 |
|---|
| 59 | * |
|---|
| 60 | * Hydra_Software_Devel/3 8/15/11 10:47a jgarrett |
|---|
| 61 | * SWDTV-6627: Coverity CID 629,630 |
|---|
| 62 | * |
|---|
| 63 | * Hydra_Software_Devel/2 8/12/11 6:53p jgarrett |
|---|
| 64 | * SWDTV-6627: Refactoring initial EQ code |
|---|
| 65 | * |
|---|
| 66 | * Hydra_Software_Devel/1 8/12/11 5:27p sgadara |
|---|
| 67 | * SWDTV-6627: [35233] Add first cut of Equalizer support |
|---|
| 68 | |
|---|
| 69 | ***************************************************************************/ |
|---|
| 70 | #include "bape.h" |
|---|
| 71 | #include "bape_priv.h" |
|---|
| 72 | #include "bape_eq_coeff_priv.h" |
|---|
| 73 | |
|---|
| 74 | BDBG_MODULE(bape_equalizer); |
|---|
| 75 | |
|---|
| 76 | BDBG_OBJECT_ID(BAPE_Equalizer); |
|---|
| 77 | |
|---|
| 78 | #ifdef BCHP_AUD_FMM_SRC_CTRL0_SRC_CFGi_SRC_TYPE_IIR |
|---|
| 79 | |
|---|
| 80 | #define BAPE_MAX_STAGES_PER_EQUALIZER BAPE_CHIP_MAX_SRCS /* Increase if required,with SRCs availability assured since a few stages can be packed into single SRC */ |
|---|
| 81 | #define BAPE_P_MAX_CASCADED_SRCS_PER_EQUALIZER BAPE_CHIP_MAX_SRCS |
|---|
| 82 | #define BAPE_P_MAX_EQSTAGE_INSTANCES BAPE_CHIP_MAX_SRCS |
|---|
| 83 | |
|---|
| 84 | typedef struct BAPE_Equalizer |
|---|
| 85 | { |
|---|
| 86 | BDBG_OBJECT(BAPE_Equalizer) |
|---|
| 87 | BAPE_Handle deviceHandle; |
|---|
| 88 | BAPE_Connector input; |
|---|
| 89 | BAPE_PathNode pathNode; |
|---|
| 90 | bool ready; |
|---|
| 91 | bool running; |
|---|
| 92 | unsigned sampleRate; |
|---|
| 93 | unsigned numChannelPairs; |
|---|
| 94 | unsigned numCascadeSrcs; |
|---|
| 95 | BAPE_SrcGroupHandle src[BAPE_P_MAX_CASCADED_SRCS_PER_EQUALIZER]; |
|---|
| 96 | BAPE_EqualizerStageHandle eqStage[BAPE_MAX_STAGES_PER_EQUALIZER]; |
|---|
| 97 | }BAPE_Equalizer; |
|---|
| 98 | |
|---|
| 99 | typedef struct BAPE_EqualizerStage |
|---|
| 100 | { |
|---|
| 101 | unsigned sampleRate; |
|---|
| 102 | BAPE_SrcGroupHandle srcGroups[BAPE_P_MAX_EQSTAGE_INSTANCES]; /* currently no EQ operation needs more than 1 SRC per Channel Pair */ |
|---|
| 103 | BAPE_EqualizerStageSettings settings; |
|---|
| 104 | }BAPE_EqualizerStage; |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | /********** Default Tone Control Settings *******************/ |
|---|
| 108 | static const BAPE_EqualizerToneControlSettings deftoneControlsettings = |
|---|
| 109 | { |
|---|
| 110 | /* bass */ |
|---|
| 111 | 0, |
|---|
| 112 | 100, |
|---|
| 113 | BAPE_ToneControlEqType_eShelving, |
|---|
| 114 | 100, |
|---|
| 115 | /* treble */ |
|---|
| 116 | 0, |
|---|
| 117 | 10000, |
|---|
| 118 | BAPE_ToneControlEqType_eShelving, |
|---|
| 119 | 10000 |
|---|
| 120 | }; |
|---|
| 121 | |
|---|
| 122 | /********** Default Five Band Settings *******************/ |
|---|
| 123 | static const BAPE_EqualizerFiveBandSettings deffiveBandSettings = |
|---|
| 124 | { |
|---|
| 125 | 0,0,0,0,0 /* Gains at 100,300,1000,3000 and 10000 hz respectively */ |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | /********** Default Seven Band Settings *******************/ |
|---|
| 129 | static const BAPE_EqualizerSevenBandSettings defsevenBandSettings = |
|---|
| 130 | { |
|---|
| 131 | /* bandSettings[7] */ |
|---|
| 132 | { |
|---|
| 133 | { |
|---|
| 134 | 1000, /* peak */ |
|---|
| 135 | 0, /* gain */ |
|---|
| 136 | 100 /* q */ |
|---|
| 137 | }, |
|---|
| 138 | { |
|---|
| 139 | 1000, /* peak */ |
|---|
| 140 | 0, /* gain */ |
|---|
| 141 | 100 /* q */ |
|---|
| 142 | }, |
|---|
| 143 | { |
|---|
| 144 | 1000, /* peak */ |
|---|
| 145 | 0, /* gain */ |
|---|
| 146 | 100 /* q */ |
|---|
| 147 | }, |
|---|
| 148 | { |
|---|
| 149 | 1000, /* peak */ |
|---|
| 150 | 0, /* gain */ |
|---|
| 151 | 100 /* q */ |
|---|
| 152 | }, |
|---|
| 153 | { |
|---|
| 154 | 1000, /* peak */ |
|---|
| 155 | 0, /* gain */ |
|---|
| 156 | 100 /* q */ |
|---|
| 157 | }, |
|---|
| 158 | { |
|---|
| 159 | 1000, /* peak */ |
|---|
| 160 | 0, /* gain */ |
|---|
| 161 | 100 /* q */ |
|---|
| 162 | }, |
|---|
| 163 | { |
|---|
| 164 | 1000, /* peak */ |
|---|
| 165 | 0, /* gain */ |
|---|
| 166 | 100 /* q */ |
|---|
| 167 | } |
|---|
| 168 | }, |
|---|
| 169 | 7 /* windowStep */ |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | /********** Default Subsonic Filter Settings *******************/ |
|---|
| 173 | static const BAPE_EqualizerSubsonicSettings defsubsonicSettings = |
|---|
| 174 | { |
|---|
| 175 | 0, |
|---|
| 176 | BAPE_EqualizerFilterOrder_e4, |
|---|
| 177 | BAPE_EqualizerFilterType_eButterworth |
|---|
| 178 | }; |
|---|
| 179 | |
|---|
| 180 | /********** Default Subwoofer Filter Settings *******************/ |
|---|
| 181 | static const BAPE_EqualizerSubwooferSettings defsubwooferSettings = |
|---|
| 182 | { |
|---|
| 183 | 0, |
|---|
| 184 | BAPE_EqualizerFilterOrder_e4, |
|---|
| 185 | BAPE_EqualizerFilterType_eButterworth |
|---|
| 186 | }; |
|---|
| 187 | |
|---|
| 188 | /********** Default Custom Equalizer Settings *******************/ |
|---|
| 189 | static const BAPE_EqualizerCustomSettings defcustomSettings = |
|---|
| 190 | { |
|---|
| 191 | 8, |
|---|
| 192 | { /* filtercoefficients[8] */ |
|---|
| 193 | { |
|---|
| 194 | 0x4000000, |
|---|
| 195 | 0,0,0,0 |
|---|
| 196 | }, |
|---|
| 197 | { |
|---|
| 198 | 0x4000000, |
|---|
| 199 | 0,0,0,0 |
|---|
| 200 | }, |
|---|
| 201 | { |
|---|
| 202 | 0x4000000, |
|---|
| 203 | 0,0,0,0 |
|---|
| 204 | }, |
|---|
| 205 | { |
|---|
| 206 | 0x4000000, |
|---|
| 207 | 0,0,0,0 |
|---|
| 208 | }, |
|---|
| 209 | { |
|---|
| 210 | 0x4000000, |
|---|
| 211 | 0,0,0,0 |
|---|
| 212 | }, |
|---|
| 213 | { |
|---|
| 214 | 0x4000000, |
|---|
| 215 | 0,0,0,0 |
|---|
| 216 | }, |
|---|
| 217 | { |
|---|
| 218 | 0x4000000, |
|---|
| 219 | 0,0,0,0 |
|---|
| 220 | }, |
|---|
| 221 | { |
|---|
| 222 | 0x4000000, |
|---|
| 223 | 0,0,0,0 |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | }; |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | /*************************************************************************/ |
|---|
| 230 | /* Allocate mixer resources */ |
|---|
| 231 | static BERR_Code BAPE_Equalizer_P_AllocatePathFromInput( |
|---|
| 232 | BAPE_PathNode *pNode, |
|---|
| 233 | BAPE_PathConnection *pConnection |
|---|
| 234 | ); |
|---|
| 235 | |
|---|
| 236 | /*************************************************************************/ |
|---|
| 237 | /* Release mixer resources */ |
|---|
| 238 | static void BAPE_Equalizer_P_FreePathFromInput( |
|---|
| 239 | BAPE_PathNode *pNode, |
|---|
| 240 | BAPE_PathConnection *pConnection |
|---|
| 241 | ); |
|---|
| 242 | |
|---|
| 243 | /*************************************************************************/ |
|---|
| 244 | static BERR_Code BAPE_Equalizer_P_ConfigPathFromInput( |
|---|
| 245 | BAPE_PathNode *pNode, |
|---|
| 246 | BAPE_PathConnection *pConnection |
|---|
| 247 | ); |
|---|
| 248 | |
|---|
| 249 | /*************************************************************************/ |
|---|
| 250 | static BERR_Code BAPE_Equalizer_P_StartPathFromInput( |
|---|
| 251 | BAPE_PathNode *pNode, |
|---|
| 252 | BAPE_PathConnection *pConnection |
|---|
| 253 | ); |
|---|
| 254 | |
|---|
| 255 | /*************************************************************************/ |
|---|
| 256 | static void BAPE_Equalizer_P_StopPathFromInput( |
|---|
| 257 | BAPE_PathNode *pNode, |
|---|
| 258 | BAPE_PathConnection *pConnection |
|---|
| 259 | ); |
|---|
| 260 | |
|---|
| 261 | /*************************************************************************/ |
|---|
| 262 | static BERR_Code BAPE_Equalizer_P_ConnectorSupported( |
|---|
| 263 | BAPE_PathNode *pNode, |
|---|
| 264 | BAPE_PathConnector *pConnector |
|---|
| 265 | ); |
|---|
| 266 | |
|---|
| 267 | /*************************************************************************/ |
|---|
| 268 | static BERR_Code BAPE_Equalizer_P_AllocateResources(BAPE_EqualizerHandle equalizer, BAPE_PathConnection *pConnection); |
|---|
| 269 | |
|---|
| 270 | /*************************************************************************/ |
|---|
| 271 | static void BAPE_Equalizer_P_FreeResources(BAPE_EqualizerHandle handle); |
|---|
| 272 | |
|---|
| 273 | /*************************************************************************/ |
|---|
| 274 | static void BAPE_Equalizer_P_RemoveInputCallback(BAPE_PathNode *pNode, BAPE_PathConnector *pConnector); |
|---|
| 275 | |
|---|
| 276 | /*************************************************************************/ |
|---|
| 277 | static void BAPE_Equalizer_P_InputSampleRateChange_isr( |
|---|
| 278 | struct BAPE_PathNode *pNode, |
|---|
| 279 | struct BAPE_PathConnection *pConnection |
|---|
| 280 | ); |
|---|
| 281 | |
|---|
| 282 | /*************************************************************************/ |
|---|
| 283 | static void BAPE_EqualizerStage_P_GenerateCoefficients_isr( |
|---|
| 284 | BAPE_EqualizerStageHandle eqStage, |
|---|
| 285 | BAPE_SRC_P_IIRCoeff *pCoeff); |
|---|
| 286 | |
|---|
| 287 | /*************************************************************************/ |
|---|
| 288 | static void BAPE_EqualizerStage_P_UpdateCoefficients_isr( |
|---|
| 289 | BAPE_EqualizerStageHandle eqStage, |
|---|
| 290 | BAPE_SRC_P_IIRCoeff *pCoeff); |
|---|
| 291 | |
|---|
| 292 | /*************************************************************************** |
|---|
| 293 | Summary: |
|---|
| 294 | Get default open settings for an equalizer stage |
|---|
| 295 | ***************************************************************************/ |
|---|
| 296 | void BAPE_EqualizerStage_GetDefaultSettings( |
|---|
| 297 | BAPE_EqualizerStageType type, |
|---|
| 298 | BAPE_EqualizerStageSettings *pSettings /* [out] */ |
|---|
| 299 | ) |
|---|
| 300 | { |
|---|
| 301 | BDBG_ASSERT(pSettings); |
|---|
| 302 | |
|---|
| 303 | pSettings->type = type; |
|---|
| 304 | pSettings->rampSettings.enable = false; |
|---|
| 305 | pSettings->rampSettings.stepSize = 0xA; |
|---|
| 306 | pSettings->bypassEnabled = false; |
|---|
| 307 | |
|---|
| 308 | switch(pSettings->type) |
|---|
| 309 | { |
|---|
| 310 | case BAPE_EqualizerStageType_eToneControl: |
|---|
| 311 | pSettings->modeSettings.toneControl = deftoneControlsettings; |
|---|
| 312 | break; |
|---|
| 313 | case BAPE_EqualizerStageType_eFiveBand: |
|---|
| 314 | pSettings->modeSettings.fiveBand = deffiveBandSettings; |
|---|
| 315 | break; |
|---|
| 316 | case BAPE_EqualizerStageType_eSevenBand: |
|---|
| 317 | pSettings->modeSettings.sevenBand = defsevenBandSettings; |
|---|
| 318 | break; |
|---|
| 319 | case BAPE_EqualizerStageType_eSubsonic: |
|---|
| 320 | pSettings->modeSettings.subsonic = defsubsonicSettings; |
|---|
| 321 | break; |
|---|
| 322 | case BAPE_EqualizerStageType_eSubwoofer: |
|---|
| 323 | pSettings->modeSettings.subwoofer = defsubwooferSettings; |
|---|
| 324 | break; |
|---|
| 325 | case BAPE_EqualizerStageType_eCustom: |
|---|
| 326 | pSettings->modeSettings.custom = defcustomSettings; |
|---|
| 327 | break; |
|---|
| 328 | default: |
|---|
| 329 | BDBG_ERR(("Unsupported Equalizer Stage Type %d", pSettings->type)); |
|---|
| 330 | /*return BERR_NOT_SUPPORTED;*/ |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | BERR_Code BAPE_EqualizerStage_Create( |
|---|
| 337 | BAPE_Handle deviceHandle, |
|---|
| 338 | const BAPE_EqualizerStageSettings *pSettings, |
|---|
| 339 | BAPE_EqualizerStageHandle *pHandle /* [out] */ |
|---|
| 340 | ) |
|---|
| 341 | { |
|---|
| 342 | BAPE_EqualizerStageHandle handle=NULL; |
|---|
| 343 | BAPE_EqualizerStageSettings defaultSettings; |
|---|
| 344 | |
|---|
| 345 | BDBG_ASSERT(pHandle); |
|---|
| 346 | BSTD_UNUSED(deviceHandle); |
|---|
| 347 | |
|---|
| 348 | handle = BKNI_Malloc(sizeof(BAPE_EqualizerStage)); |
|---|
| 349 | if(NULL == handle) |
|---|
| 350 | { |
|---|
| 351 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 352 | } |
|---|
| 353 | BKNI_Memset(handle, 0, sizeof(BAPE_EqualizerStage)); |
|---|
| 354 | |
|---|
| 355 | if ( NULL == pSettings ) |
|---|
| 356 | { |
|---|
| 357 | BAPE_EqualizerStage_GetDefaultSettings(BAPE_EqualizerStageType_eToneControl, &defaultSettings); |
|---|
| 358 | pSettings = &defaultSettings; |
|---|
| 359 | } |
|---|
| 360 | handle->settings = *pSettings; |
|---|
| 361 | |
|---|
| 362 | *pHandle = handle; |
|---|
| 363 | |
|---|
| 364 | return BERR_SUCCESS; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | void BAPE_EqualizerStage_Destroy( |
|---|
| 368 | BAPE_EqualizerStageHandle handle |
|---|
| 369 | ) |
|---|
| 370 | { |
|---|
| 371 | unsigned i; |
|---|
| 372 | BDBG_ASSERT(handle); |
|---|
| 373 | |
|---|
| 374 | for(i=0; i<BAPE_P_MAX_EQSTAGE_INSTANCES; i++) |
|---|
| 375 | { |
|---|
| 376 | if(NULL != handle->srcGroups[i]) |
|---|
| 377 | { |
|---|
| 378 | BDBG_ERR(("Equalizer Stage is still in use, so cannot be destroyed")); |
|---|
| 379 | return; |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | BKNI_Free(handle); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | void BAPE_EqualizerStage_GetSettings( |
|---|
| 387 | BAPE_EqualizerStageHandle handle, |
|---|
| 388 | BAPE_EqualizerStageSettings *pSettings /* [out] */ |
|---|
| 389 | ) |
|---|
| 390 | { |
|---|
| 391 | BDBG_ASSERT(pSettings); |
|---|
| 392 | |
|---|
| 393 | *pSettings = handle->settings; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | BERR_Code BAPE_EqualizerStage_SetSettings( |
|---|
| 397 | BAPE_EqualizerStageHandle handle, |
|---|
| 398 | const BAPE_EqualizerStageSettings *pSettings |
|---|
| 399 | ) |
|---|
| 400 | { |
|---|
| 401 | unsigned i; |
|---|
| 402 | |
|---|
| 403 | if(pSettings->rampSettings.enable != handle->settings.rampSettings.enable) |
|---|
| 404 | { |
|---|
| 405 | BDBG_ERR(("Equalizer ramp enable cannot be changed on the fly.")); |
|---|
| 406 | return BERR_NOT_SUPPORTED; |
|---|
| 407 | } |
|---|
| 408 | handle->settings = *pSettings; |
|---|
| 409 | |
|---|
| 410 | for(i=0; i<BAPE_P_MAX_EQSTAGE_INSTANCES; i++) |
|---|
| 411 | { |
|---|
| 412 | if(NULL != handle->srcGroups[i]) |
|---|
| 413 | { |
|---|
| 414 | break; |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | if(i < BAPE_P_MAX_EQSTAGE_INSTANCES) |
|---|
| 418 | { |
|---|
| 419 | BAPE_SRC_P_IIRCoeff coeff; |
|---|
| 420 | |
|---|
| 421 | /* Initialize to Bypass */ |
|---|
| 422 | BKNI_Memset(&coeff, 0, sizeof(BAPE_SRC_P_IIRCoeff)); |
|---|
| 423 | for(i=0; i<BAPE_CHIP_P_MAX_IIR_FILTERS_PER_SRC; i++) |
|---|
| 424 | { |
|---|
| 425 | coeff.b0[i] = 0x02000000; /* Coefficients registers are 3.25 format */ |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | BKNI_EnterCriticalSection(); |
|---|
| 429 | BAPE_EqualizerStage_P_GenerateCoefficients_isr(handle, &coeff); /* call from non-critical section once Book-keeping is implemented */ |
|---|
| 430 | BAPE_EqualizerStage_P_UpdateCoefficients_isr(handle, &coeff); |
|---|
| 431 | BKNI_LeaveCriticalSection(); |
|---|
| 432 | } |
|---|
| 433 | else |
|---|
| 434 | { |
|---|
| 435 | BDBG_MSG(("Equalizer Stage is not active, the settings are saved, not programmed")); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | return BERR_SUCCESS; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | void BAPE_Equalizer_GetDefaultSettings( |
|---|
| 442 | BAPE_EqualizerSettings *pSettings /* [out] */ |
|---|
| 443 | ) |
|---|
| 444 | { |
|---|
| 445 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 446 | BKNI_Memset(pSettings, 0, sizeof(BAPE_EqualizerSettings)); |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | BERR_Code BAPE_Equalizer_Create( |
|---|
| 450 | BAPE_Handle deviceHandle, |
|---|
| 451 | const BAPE_EqualizerSettings *pSettings, |
|---|
| 452 | BAPE_EqualizerHandle *pHandle /* [out] */ |
|---|
| 453 | ) |
|---|
| 454 | { |
|---|
| 455 | BERR_Code errCode; |
|---|
| 456 | BAPE_EqualizerHandle handle; |
|---|
| 457 | BAPE_EqualizerSettings defaultSettings; |
|---|
| 458 | |
|---|
| 459 | BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device); |
|---|
| 460 | BDBG_ASSERT(NULL != pHandle); |
|---|
| 461 | BSTD_UNUSED(defaultSettings); |
|---|
| 462 | BSTD_UNUSED(pSettings); |
|---|
| 463 | |
|---|
| 464 | *pHandle = NULL; |
|---|
| 465 | |
|---|
| 466 | handle = BKNI_Malloc(sizeof(BAPE_Equalizer)); |
|---|
| 467 | if ( NULL == handle ) |
|---|
| 468 | { |
|---|
| 469 | errCode = BERR_OUT_OF_SYSTEM_MEMORY; |
|---|
| 470 | return BERR_TRACE(errCode); |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | BKNI_Memset(handle, 0, sizeof(BAPE_Equalizer)); |
|---|
| 474 | BDBG_OBJECT_SET(handle, BAPE_Equalizer); |
|---|
| 475 | |
|---|
| 476 | handle->deviceHandle = deviceHandle; |
|---|
| 477 | handle->sampleRate = 0; |
|---|
| 478 | BAPE_P_InitPathNode(&handle->pathNode, BAPE_PathNodeType_eEqualizer, 0, 1, deviceHandle, handle); |
|---|
| 479 | handle->pathNode.pName = "Equalizer"; |
|---|
| 480 | handle->pathNode.paths[0].connector.dataSource = BAPE_DataSource_eFci; |
|---|
| 481 | handle->pathNode.paths[0].connector.numChannelPairs = 1; |
|---|
| 482 | /* Fill in node connection routines */ |
|---|
| 483 | handle->pathNode.allocatePathFromInput = BAPE_Equalizer_P_AllocatePathFromInput; |
|---|
| 484 | handle->pathNode.freePathFromInput = BAPE_Equalizer_P_FreePathFromInput; |
|---|
| 485 | handle->pathNode.configPathFromInput = BAPE_Equalizer_P_ConfigPathFromInput; |
|---|
| 486 | handle->pathNode.startPathFromInput = BAPE_Equalizer_P_StartPathFromInput; |
|---|
| 487 | handle->pathNode.stopPathFromInput = BAPE_Equalizer_P_StopPathFromInput; |
|---|
| 488 | handle->pathNode.inputSampleRateChange_isr = BAPE_Equalizer_P_InputSampleRateChange_isr; |
|---|
| 489 | /*handle->pathNode.inputFormatChange = BAPE_StandardMixer_P_InputFormatChange;*/ |
|---|
| 490 | handle->pathNode.connectorSupported = BAPE_Equalizer_P_ConnectorSupported; |
|---|
| 491 | handle->pathNode.removeInput = BAPE_Equalizer_P_RemoveInputCallback; |
|---|
| 492 | |
|---|
| 493 | *pHandle = handle; |
|---|
| 494 | |
|---|
| 495 | /* TODO: Attach to device handle for resource tracking */ |
|---|
| 496 | |
|---|
| 497 | return BERR_SUCCESS; |
|---|
| 498 | |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | void BAPE_Equalizer_Destroy( |
|---|
| 502 | BAPE_EqualizerHandle handle |
|---|
| 503 | ) |
|---|
| 504 | { |
|---|
| 505 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 506 | |
|---|
| 507 | BDBG_ASSERT(!handle->running); |
|---|
| 508 | |
|---|
| 509 | /* Remove all stages */ |
|---|
| 510 | BAPE_Equalizer_ClearStages(handle); |
|---|
| 511 | |
|---|
| 512 | /* Remove all inputs */ |
|---|
| 513 | BAPE_Equalizer_RemoveAllInputs(handle); |
|---|
| 514 | |
|---|
| 515 | /* Break any downstream connections */ |
|---|
| 516 | BAPE_Connector_P_RemoveAllConnections(&handle->pathNode.paths[0].connector); |
|---|
| 517 | |
|---|
| 518 | #if 0 /* TODO */ |
|---|
| 519 | /* Unlink from device */ |
|---|
| 520 | BLST_S_REMOVE(&handle->deviceHandle->equalizerList, handle, BAPE_Mixer, pathNode); |
|---|
| 521 | #endif |
|---|
| 522 | BDBG_OBJECT_DESTROY(handle, BAPE_Equalizer); |
|---|
| 523 | BKNI_Free(handle); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | BERR_Code BAPE_Equalizer_SetStages( |
|---|
| 527 | BAPE_EqualizerHandle handle, |
|---|
| 528 | BAPE_EqualizerStageHandle *pStages, |
|---|
| 529 | unsigned numStages |
|---|
| 530 | ) |
|---|
| 531 | { |
|---|
| 532 | unsigned i; |
|---|
| 533 | |
|---|
| 534 | BDBG_OBJECT_ASSERT(handle,BAPE_Equalizer); |
|---|
| 535 | |
|---|
| 536 | if ( numStages > 0 ) |
|---|
| 537 | { |
|---|
| 538 | BDBG_ASSERT(pStages); |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | if ( handle->running ) |
|---|
| 542 | { |
|---|
| 543 | BDBG_ERR(("Cannot change Equalizer stages while running")); |
|---|
| 544 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | if ( numStages > BAPE_MAX_STAGES_PER_EQUALIZER ) |
|---|
| 548 | { |
|---|
| 549 | BDBG_ERR(("Exceeded maximum number of stages per Equalizer %u on this chipset", BAPE_MAX_STAGES_PER_EQUALIZER)); |
|---|
| 550 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | /* Release stored resources */ |
|---|
| 554 | BAPE_Equalizer_P_FreeResources(handle); |
|---|
| 555 | |
|---|
| 556 | /* Invalidate all stage handles */ |
|---|
| 557 | BKNI_Memset(handle->eqStage, 0, sizeof(handle->eqStage)); |
|---|
| 558 | /* Copy stage Handles */ |
|---|
| 559 | for ( i = 0; i < numStages; i++ ) |
|---|
| 560 | { |
|---|
| 561 | handle->eqStage[i] = pStages[i]; |
|---|
| 562 | } |
|---|
| 563 | handle->numCascadeSrcs = numStages; /* TODO: Is this accurate? Seems like this may be able to pack some stages (e.g. TC + Subwoofer or TC + Subsonic) */ |
|---|
| 564 | |
|---|
| 565 | return BERR_SUCCESS; |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | void BAPE_Equalizer_ClearStages( |
|---|
| 569 | BAPE_EqualizerHandle handle |
|---|
| 570 | ) |
|---|
| 571 | { |
|---|
| 572 | (void)BAPE_Equalizer_SetStages(handle, NULL, 0); |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | BERR_Code BAPE_Equalizer_AddInput( |
|---|
| 576 | BAPE_EqualizerHandle handle, |
|---|
| 577 | BAPE_Connector input |
|---|
| 578 | ) |
|---|
| 579 | { |
|---|
| 580 | BERR_Code errCode; |
|---|
| 581 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 582 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 583 | |
|---|
| 584 | if ( NULL != handle->input ) |
|---|
| 585 | { |
|---|
| 586 | BDBG_ERR(("Can not have more than one input")); |
|---|
| 587 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 588 | } |
|---|
| 589 | errCode = BAPE_PathNode_P_AddInput(&handle->pathNode, input); |
|---|
| 590 | if ( errCode ) |
|---|
| 591 | { |
|---|
| 592 | return BERR_TRACE(errCode); |
|---|
| 593 | } |
|---|
| 594 | handle->input = input; |
|---|
| 595 | return BERR_SUCCESS; |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | BERR_Code BAPE_Equalizer_RemoveInput( |
|---|
| 599 | BAPE_EqualizerHandle handle, |
|---|
| 600 | BAPE_Connector input |
|---|
| 601 | ) |
|---|
| 602 | { |
|---|
| 603 | BERR_Code errCode; |
|---|
| 604 | |
|---|
| 605 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 606 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 607 | |
|---|
| 608 | if ( input != handle->input ) |
|---|
| 609 | { |
|---|
| 610 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | /* Make sure we remove all resources */ |
|---|
| 614 | BAPE_Equalizer_P_FreeResources(handle); |
|---|
| 615 | errCode = BAPE_PathNode_P_RemoveInput(&handle->pathNode, input); |
|---|
| 616 | if ( errCode ) |
|---|
| 617 | { |
|---|
| 618 | return BERR_TRACE(errCode); |
|---|
| 619 | } |
|---|
| 620 | handle->input = NULL; |
|---|
| 621 | return BERR_SUCCESS; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | BERR_Code BAPE_Equalizer_RemoveAllInputs( |
|---|
| 625 | BAPE_EqualizerHandle handle |
|---|
| 626 | ) |
|---|
| 627 | { |
|---|
| 628 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 629 | |
|---|
| 630 | if ( handle->input ) |
|---|
| 631 | { |
|---|
| 632 | return BAPE_Equalizer_RemoveInput(handle, handle->input); |
|---|
| 633 | } |
|---|
| 634 | return BERR_SUCCESS; |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | void BAPE_Equalizer_GetConnector( |
|---|
| 638 | BAPE_EqualizerHandle handle, |
|---|
| 639 | BAPE_Connector *pConnector /* [out] */ |
|---|
| 640 | ) |
|---|
| 641 | { |
|---|
| 642 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 643 | BDBG_ASSERT(NULL != pConnector); |
|---|
| 644 | *pConnector = &handle->pathNode.paths[0].connector; |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | /*************************************************************************/ |
|---|
| 649 | /* Private Routines */ |
|---|
| 650 | /*************************************************************************/ |
|---|
| 651 | |
|---|
| 652 | /*************************************************************************/ |
|---|
| 653 | /* Allocate mixer resources */ |
|---|
| 654 | static BERR_Code BAPE_Equalizer_P_AllocatePathFromInput( |
|---|
| 655 | BAPE_PathNode *pNode, |
|---|
| 656 | BAPE_PathConnection *pConnection |
|---|
| 657 | ) |
|---|
| 658 | { |
|---|
| 659 | BAPE_EqualizerHandle handle; |
|---|
| 660 | BERR_Code errCode; |
|---|
| 661 | |
|---|
| 662 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 663 | |
|---|
| 664 | handle = pNode->pHandle; |
|---|
| 665 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 666 | |
|---|
| 667 | /* Grab SRC resources */ |
|---|
| 668 | errCode = BAPE_Equalizer_P_AllocateResources(handle, pConnection); |
|---|
| 669 | if ( errCode ) |
|---|
| 670 | { |
|---|
| 671 | return BERR_TRACE(errCode); |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | return BERR_SUCCESS; |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | /*************************************************************************/ |
|---|
| 678 | /* Release mixer resources */ |
|---|
| 679 | static void BAPE_Equalizer_P_FreePathFromInput( |
|---|
| 680 | BAPE_PathNode *pNode, |
|---|
| 681 | BAPE_PathConnection *pConnection |
|---|
| 682 | ) |
|---|
| 683 | { |
|---|
| 684 | BAPE_EqualizerHandle handle; |
|---|
| 685 | |
|---|
| 686 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 687 | BSTD_UNUSED(pConnection); |
|---|
| 688 | |
|---|
| 689 | handle = pNode->pHandle; |
|---|
| 690 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 691 | |
|---|
| 692 | /* Free mixer-level resources if needed */ |
|---|
| 693 | BAPE_Equalizer_P_FreeResources(handle); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | /*************************************************************************/ |
|---|
| 697 | static BERR_Code BAPE_Equalizer_P_ConfigPathFromInput( |
|---|
| 698 | BAPE_PathNode *pNode, |
|---|
| 699 | BAPE_PathConnection *pConnection |
|---|
| 700 | ) |
|---|
| 701 | { |
|---|
| 702 | unsigned numChannelPairs; |
|---|
| 703 | BAPE_SrcGroupSettings srcSettings; |
|---|
| 704 | BERR_Code errCode; |
|---|
| 705 | |
|---|
| 706 | BAPE_EqualizerHandle handle; |
|---|
| 707 | |
|---|
| 708 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 709 | |
|---|
| 710 | handle = pNode->pHandle; |
|---|
| 711 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 712 | |
|---|
| 713 | BDBG_ENTER(BAPE_Equalizer_P_ConfigPathFromInput); |
|---|
| 714 | |
|---|
| 715 | /* Setup linkage from conection into mixer */ |
|---|
| 716 | numChannelPairs = handle->numChannelPairs; |
|---|
| 717 | |
|---|
| 718 | /* Make sure we have allocated at least one SRC */ |
|---|
| 719 | if ( NULL == handle->src[0] ) |
|---|
| 720 | { |
|---|
| 721 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | /* Set the first SRC's input */ |
|---|
| 725 | BAPE_SrcGroup_P_GetSettings(handle->src[0], &srcSettings); |
|---|
| 726 | BAPE_FciIdGroup_Init(&srcSettings.input); |
|---|
| 727 | |
|---|
| 728 | /* This should set the input to the first SRC */ |
|---|
| 729 | switch ( pConnection->pSource->dataSource ) |
|---|
| 730 | { |
|---|
| 731 | case BAPE_DataSource_eFci: /* Mixer/EQ */ |
|---|
| 732 | srcSettings.input = pConnection->inputFciGroup; |
|---|
| 733 | break; |
|---|
| 734 | default: |
|---|
| 735 | /* Other connection types are not currently supported. Ideally, we should support a buffer source and allocate sfifos if required. */ |
|---|
| 736 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | errCode = BAPE_SrcGroup_P_SetSettings(handle->src[0], &srcSettings); |
|---|
| 740 | if ( errCode ) |
|---|
| 741 | { |
|---|
| 742 | return BERR_TRACE(errCode); |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | #if 0 /* Book keep Coeff for 32,44.1 and 48khz */ |
|---|
| 746 | /* Update SRC Coefficients */ |
|---|
| 747 | BKNI_EnterCriticalSection(); |
|---|
| 748 | BAPE_Equalizer_P_UpdateCoefficients_isr(handle); |
|---|
| 749 | BKNI_LeaveCriticalSection(); |
|---|
| 750 | #endif |
|---|
| 751 | |
|---|
| 752 | BDBG_LEAVE(BAPE_Equalizer_P_ConfigPathFromInput); |
|---|
| 753 | return BERR_SUCCESS; |
|---|
| 754 | } |
|---|
| 755 | |
|---|
| 756 | /*************************************************************************/ |
|---|
| 757 | static BERR_Code BAPE_Equalizer_P_StartPathFromInput( |
|---|
| 758 | BAPE_PathNode *pNode, |
|---|
| 759 | BAPE_PathConnection *pConnection |
|---|
| 760 | ) |
|---|
| 761 | { |
|---|
| 762 | int srcCascadeIndex; |
|---|
| 763 | BAPE_EqualizerHandle handle; |
|---|
| 764 | BAPE_Connector input; |
|---|
| 765 | BERR_Code errCode; |
|---|
| 766 | |
|---|
| 767 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 768 | |
|---|
| 769 | BDBG_ENTER(BAPE_Equalizer_P_StartPathFromInput); |
|---|
| 770 | handle = pNode->pHandle; |
|---|
| 771 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 772 | input = pConnection->pSource; |
|---|
| 773 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 774 | |
|---|
| 775 | BDBG_MSG(("Input %s, %s starting", input->pParent->pName, input->pName)); |
|---|
| 776 | |
|---|
| 777 | /* Start SRCs in consumer..producer order */ |
|---|
| 778 | for ( srcCascadeIndex = (int)handle->numCascadeSrcs-1; srcCascadeIndex >= 0; srcCascadeIndex-- ) |
|---|
| 779 | { |
|---|
| 780 | errCode = BAPE_SrcGroup_P_Start(handle->src[srcCascadeIndex]); |
|---|
| 781 | if ( errCode ) |
|---|
| 782 | { |
|---|
| 783 | errCode = BERR_TRACE(errCode); |
|---|
| 784 | goto err_src; |
|---|
| 785 | } |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | handle->running = true; |
|---|
| 789 | |
|---|
| 790 | BDBG_LEAVE(BAPE_Equalizer_P_StartPathFromInput); |
|---|
| 791 | return BERR_SUCCESS; |
|---|
| 792 | |
|---|
| 793 | err_src: |
|---|
| 794 | BAPE_Equalizer_P_StopPathFromInput(pNode, pConnection); |
|---|
| 795 | |
|---|
| 796 | return errCode; |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | /*************************************************************************/ |
|---|
| 800 | static void BAPE_Equalizer_P_StopPathFromInput( |
|---|
| 801 | BAPE_PathNode *pNode, |
|---|
| 802 | BAPE_PathConnection *pConnection |
|---|
| 803 | ) |
|---|
| 804 | { |
|---|
| 805 | unsigned srcCascadeIndex; |
|---|
| 806 | BAPE_EqualizerHandle handle; |
|---|
| 807 | BAPE_Connector input; |
|---|
| 808 | |
|---|
| 809 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 810 | |
|---|
| 811 | BDBG_ENTER(BAPE_Equalizer_P_StopPathFromInput); |
|---|
| 812 | handle = pNode->pHandle; |
|---|
| 813 | BDBG_OBJECT_ASSERT(handle, BAPE_Equalizer); |
|---|
| 814 | input = pConnection->pSource; |
|---|
| 815 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 816 | |
|---|
| 817 | BDBG_MSG(("Input %s, %s stopping", input->pParent->pName, input->pName)); |
|---|
| 818 | |
|---|
| 819 | /* Sop SRCs in producer..consumer order */ |
|---|
| 820 | for ( srcCascadeIndex = 0; srcCascadeIndex < handle->numCascadeSrcs;srcCascadeIndex++ ) |
|---|
| 821 | { |
|---|
| 822 | BAPE_SrcGroup_P_Stop(handle->src[srcCascadeIndex]); |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | handle->running = false; |
|---|
| 826 | |
|---|
| 827 | BDBG_LEAVE(BAPE_Equalizer_P_StopPathFromInput); |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | /*************************************************************************/ |
|---|
| 831 | static BERR_Code BAPE_Equalizer_P_ConnectorSupported( |
|---|
| 832 | BAPE_PathNode *pNode, |
|---|
| 833 | BAPE_PathConnector *pConnector |
|---|
| 834 | ) |
|---|
| 835 | { |
|---|
| 836 | |
|---|
| 837 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 838 | BDBG_OBJECT_ASSERT(pConnector, BAPE_PathConnector); |
|---|
| 839 | |
|---|
| 840 | if ( pConnector->dataSource == BAPE_DataSource_eFci && |
|---|
| 841 | pConnector->numChannelPairs == 1 && /* Stereo for now -- TODO: Multichannel handling if required */ |
|---|
| 842 | !pConnector->compressed ) |
|---|
| 843 | { |
|---|
| 844 | return BERR_SUCCESS; |
|---|
| 845 | } |
|---|
| 846 | else |
|---|
| 847 | { |
|---|
| 848 | BDBG_ERR(("Only stereo FCI input is supported")); |
|---|
| 849 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 850 | } |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | /*************************************************************************/ |
|---|
| 854 | static void BAPE_Equalizer_P_RemoveInputCallback(BAPE_PathNode *pNode, BAPE_PathConnector *pConnector) |
|---|
| 855 | { |
|---|
| 856 | (void)BAPE_Equalizer_RemoveInput(pNode->pHandle, pConnector); |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | /*************************************************************************/ |
|---|
| 860 | static BERR_Code BAPE_Equalizer_P_AllocateResources(BAPE_EqualizerHandle equalizer, BAPE_PathConnection *pConnection) |
|---|
| 861 | { |
|---|
| 862 | unsigned numChannelPairs=0,i=0, j=0; |
|---|
| 863 | BAPE_SrcGroupSettings srcSettings; |
|---|
| 864 | BAPE_SrcGroupCreateSettings srcCreateSettings; |
|---|
| 865 | BERR_Code errCode=BERR_SUCCESS; |
|---|
| 866 | |
|---|
| 867 | BDBG_OBJECT_ASSERT(equalizer, BAPE_Equalizer); |
|---|
| 868 | |
|---|
| 869 | if ( equalizer->ready ) |
|---|
| 870 | { |
|---|
| 871 | BDBG_MSG(("equalizer %p already has resources allocated", equalizer)); |
|---|
| 872 | return BERR_SUCCESS; |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | numChannelPairs = pConnection->pSource->numChannelPairs;; |
|---|
| 876 | |
|---|
| 877 | equalizer->numChannelPairs = numChannelPairs; |
|---|
| 878 | |
|---|
| 879 | BDBG_MSG(("equalizer %p : Allocating equalizer with %u channel pairs.", |
|---|
| 880 | equalizer, numChannelPairs)); |
|---|
| 881 | |
|---|
| 882 | BAPE_SrcGroup_P_GetDefaultCreateSettings(&srcCreateSettings); |
|---|
| 883 | srcCreateSettings.numChannelPairs = numChannelPairs; |
|---|
| 884 | |
|---|
| 885 | /* Shallow EQ object - Allocate one SRC in Bypass */ |
|---|
| 886 | if( NULL == equalizer->eqStage[0] ) |
|---|
| 887 | { |
|---|
| 888 | equalizer->numCascadeSrcs = 1; |
|---|
| 889 | srcCreateSettings.mode = BAPE_SrcMode_eBypass; |
|---|
| 890 | } |
|---|
| 891 | else |
|---|
| 892 | { |
|---|
| 893 | srcCreateSettings.mode = BAPE_SrcMode_eIir; |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | for(i=0; i < equalizer->numCascadeSrcs; i++) |
|---|
| 897 | { |
|---|
| 898 | if(BAPE_SrcMode_eIir == srcCreateSettings.mode) |
|---|
| 899 | { |
|---|
| 900 | srcCreateSettings.equalizerSettings.rampEnable = equalizer->eqStage[i]->settings.rampSettings.enable; |
|---|
| 901 | } |
|---|
| 902 | |
|---|
| 903 | /* Only one SRC Group per EQ object supported */ |
|---|
| 904 | /* Allocate required number of SRCs */ |
|---|
| 905 | errCode = BAPE_SrcGroup_P_Create(equalizer->deviceHandle, &srcCreateSettings, &equalizer->src[i]); |
|---|
| 906 | if ( errCode ) |
|---|
| 907 | { |
|---|
| 908 | (void)BERR_TRACE(errCode); |
|---|
| 909 | goto err_src_create; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | if(equalizer->eqStage[i]) |
|---|
| 913 | { |
|---|
| 914 | for(j=0; j<BAPE_P_MAX_EQSTAGE_INSTANCES; j++) |
|---|
| 915 | { |
|---|
| 916 | if(NULL == equalizer->eqStage[i]->srcGroups[j]) |
|---|
| 917 | { |
|---|
| 918 | equalizer->eqStage[i]->srcGroups[j] = equalizer->src[i]; |
|---|
| 919 | break; |
|---|
| 920 | } |
|---|
| 921 | } |
|---|
| 922 | if(j >= BAPE_P_MAX_EQSTAGE_INSTANCES) |
|---|
| 923 | { |
|---|
| 924 | BDBG_ERR(("The number of SrcGroup handle entries in EQ Stage already reached maximum." |
|---|
| 925 | "Check if the entries are not cleared upon Free resources")); |
|---|
| 926 | } |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | /* Setup settings and Cascade Linkage */ |
|---|
| 930 | BAPE_SrcGroup_P_GetSettings(equalizer->src[i], &srcSettings); |
|---|
| 931 | srcSettings.rampEnabled = false; |
|---|
| 932 | srcSettings.startupRampEnabled = false; |
|---|
| 933 | |
|---|
| 934 | if ( i > 0 ) |
|---|
| 935 | { |
|---|
| 936 | BAPE_SrcGroup_P_GetOutputFciIds(equalizer->src[i-1], &srcSettings.input); |
|---|
| 937 | } |
|---|
| 938 | /* TODO: Coef memory */ |
|---|
| 939 | errCode = BAPE_SrcGroup_P_SetSettings(equalizer->src[i], &srcSettings); |
|---|
| 940 | if ( errCode ) |
|---|
| 941 | { |
|---|
| 942 | (void)BERR_TRACE(errCode); |
|---|
| 943 | goto err_src_settings; |
|---|
| 944 | } |
|---|
| 945 | } |
|---|
| 946 | equalizer->ready = true; |
|---|
| 947 | |
|---|
| 948 | #if 1 /* JDG: We should review this. It should really be in AllocatePathToOutput but that might require some bape_path_priv or bape_mixer_standard changes. */ |
|---|
| 949 | i = equalizer->numCascadeSrcs - 1; |
|---|
| 950 | /* Setup Downstream connections as well */ |
|---|
| 951 | for ( pConnection = BLST_SQ_FIRST(&equalizer->pathNode.paths[0].connector.connectionList); |
|---|
| 952 | pConnection != NULL; |
|---|
| 953 | pConnection = BLST_SQ_NEXT(pConnection, downstreamNode) ) |
|---|
| 954 | { |
|---|
| 955 | BAPE_SrcGroup_P_GetOutputFciIds(equalizer->src[i], &pConnection->inputFciGroup); |
|---|
| 956 | } |
|---|
| 957 | #endif |
|---|
| 958 | |
|---|
| 959 | return BERR_SUCCESS; |
|---|
| 960 | |
|---|
| 961 | err_src_create: |
|---|
| 962 | err_src_settings: |
|---|
| 963 | for ( i = 0; i < equalizer->numCascadeSrcs; i++ ) |
|---|
| 964 | { |
|---|
| 965 | if ( equalizer->src[i] ) |
|---|
| 966 | { |
|---|
| 967 | if(equalizer->eqStage[i]) |
|---|
| 968 | { |
|---|
| 969 | for(j=0; j<BAPE_P_MAX_EQSTAGE_INSTANCES; j++) |
|---|
| 970 | { |
|---|
| 971 | if(equalizer->src[i] == equalizer->eqStage[i]->srcGroups[j]) |
|---|
| 972 | { |
|---|
| 973 | equalizer->eqStage[i]->srcGroups[j] = NULL; |
|---|
| 974 | } |
|---|
| 975 | } |
|---|
| 976 | } |
|---|
| 977 | BAPE_SrcGroup_P_Destroy(equalizer->src[i]); |
|---|
| 978 | equalizer->src[i] = NULL; |
|---|
| 979 | } |
|---|
| 980 | } |
|---|
| 981 | BAPE_Equalizer_P_FreeResources(equalizer); |
|---|
| 982 | |
|---|
| 983 | return BERR_SUCCESS; |
|---|
| 984 | } |
|---|
| 985 | |
|---|
| 986 | /*************************************************************************/ |
|---|
| 987 | static void BAPE_Equalizer_P_FreeResources(BAPE_EqualizerHandle equalizer) |
|---|
| 988 | { |
|---|
| 989 | BAPE_PathConnection *pConnection; |
|---|
| 990 | unsigned i,j; |
|---|
| 991 | |
|---|
| 992 | BSTD_UNUSED(equalizer); |
|---|
| 993 | |
|---|
| 994 | if ( equalizer->running ) |
|---|
| 995 | { |
|---|
| 996 | BDBG_ERR(("Can't release resources while equalizer %p is running", equalizer)); |
|---|
| 997 | BDBG_ASSERT(!equalizer->running); |
|---|
| 998 | return; |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | if ( !equalizer->ready ) |
|---|
| 1002 | { |
|---|
| 1003 | /* Nothing to do */ |
|---|
| 1004 | return; |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | for ( i = 0; i < BAPE_P_MAX_CASCADED_SRCS_PER_EQUALIZER; i++ ) |
|---|
| 1008 | { |
|---|
| 1009 | if ( equalizer->src[i] ) |
|---|
| 1010 | { |
|---|
| 1011 | if(equalizer->eqStage[i]) |
|---|
| 1012 | { |
|---|
| 1013 | for(j=0; j<BAPE_P_MAX_EQSTAGE_INSTANCES; j++) |
|---|
| 1014 | { |
|---|
| 1015 | if(equalizer->src[i] == equalizer->eqStage[i]->srcGroups[j]) |
|---|
| 1016 | { |
|---|
| 1017 | equalizer->eqStage[i]->srcGroups[j] = NULL; |
|---|
| 1018 | } |
|---|
| 1019 | } |
|---|
| 1020 | } |
|---|
| 1021 | BAPE_SrcGroup_P_Destroy(equalizer->src[i]); |
|---|
| 1022 | equalizer->src[i] = NULL; |
|---|
| 1023 | } |
|---|
| 1024 | } |
|---|
| 1025 | equalizer->ready = false; |
|---|
| 1026 | |
|---|
| 1027 | /* JDG: We should review this as well. */ |
|---|
| 1028 | /* Invalidate Downstream connections as well */ |
|---|
| 1029 | for ( pConnection = BLST_SQ_FIRST(&equalizer->pathNode.paths[0].connector.connectionList); |
|---|
| 1030 | pConnection != NULL; |
|---|
| 1031 | pConnection = BLST_SQ_NEXT(pConnection, downstreamNode) ) |
|---|
| 1032 | { |
|---|
| 1033 | BAPE_FciIdGroup_Init(&pConnection->inputFciGroup); |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | equalizer->ready = false; |
|---|
| 1037 | } |
|---|
| 1038 | |
|---|
| 1039 | /*************************************************************************/ |
|---|
| 1040 | static void BAPE_Equalizer_P_InputSampleRateChange_isr( |
|---|
| 1041 | struct BAPE_PathNode *pNode, |
|---|
| 1042 | struct BAPE_PathConnection *pConnection |
|---|
| 1043 | ) |
|---|
| 1044 | { |
|---|
| 1045 | unsigned i; |
|---|
| 1046 | BAPE_EqualizerHandle handle; |
|---|
| 1047 | BAPE_SRC_P_IIRCoeff coeff; |
|---|
| 1048 | |
|---|
| 1049 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 1050 | |
|---|
| 1051 | handle = pNode->pHandle; |
|---|
| 1052 | BSTD_UNUSED(pConnection); |
|---|
| 1053 | |
|---|
| 1054 | /* Initialize to Bypass */ |
|---|
| 1055 | BKNI_Memset(&coeff, 0, sizeof(BAPE_SRC_P_IIRCoeff)); |
|---|
| 1056 | for(i=0; i<BAPE_CHIP_P_MAX_IIR_FILTERS_PER_SRC; i++) |
|---|
| 1057 | { |
|---|
| 1058 | coeff.b0[i] = 0x02000000; /* Coefficients registers are 3.25 format */ |
|---|
| 1059 | } |
|---|
| 1060 | |
|---|
| 1061 | handle->sampleRate = pConnection->pSource->sampleRate; |
|---|
| 1062 | for(i=0; i<BAPE_MAX_STAGES_PER_EQUALIZER; i++) |
|---|
| 1063 | { |
|---|
| 1064 | if(NULL == handle->eqStage[i]) |
|---|
| 1065 | break; |
|---|
| 1066 | handle->eqStage[i]->sampleRate = pConnection->pSource->sampleRate; |
|---|
| 1067 | |
|---|
| 1068 | BAPE_EqualizerStage_P_GenerateCoefficients_isr(handle->eqStage[i], &coeff); /* Remove once Book keeping is implemented */ |
|---|
| 1069 | BAPE_EqualizerStage_P_UpdateCoefficients_isr(handle->eqStage[i], &coeff); |
|---|
| 1070 | } |
|---|
| 1071 | |
|---|
| 1072 | handle->pathNode.paths[0].connector.sampleRate = pConnection->pSource->sampleRate; |
|---|
| 1073 | } |
|---|
| 1074 | |
|---|
| 1075 | static void BAPE_EqualizerStage_P_GenerateCoefficients_isr( |
|---|
| 1076 | BAPE_EqualizerStageHandle eqStage, |
|---|
| 1077 | BAPE_SRC_P_IIRCoeff *pCoeff) |
|---|
| 1078 | { |
|---|
| 1079 | unsigned i=0; |
|---|
| 1080 | int32_t geqdB[5]; |
|---|
| 1081 | int32_t b[3], a[3]; /* to hold b0, b1, b2, a1, a2 */ |
|---|
| 1082 | |
|---|
| 1083 | BDBG_ASSERT(NULL != eqStage); |
|---|
| 1084 | |
|---|
| 1085 | geqdB[0] = geqdB[1] = geqdB[2] = geqdB[3] = geqdB[4] = 0; |
|---|
| 1086 | |
|---|
| 1087 | for(i=0; i<BAPE_P_MAX_EQSTAGE_INSTANCES; i++) |
|---|
| 1088 | { |
|---|
| 1089 | if(NULL != eqStage->srcGroups[i]) |
|---|
| 1090 | { |
|---|
| 1091 | break; |
|---|
| 1092 | } |
|---|
| 1093 | } |
|---|
| 1094 | if(i >= BAPE_P_MAX_EQSTAGE_INSTANCES) |
|---|
| 1095 | { |
|---|
| 1096 | BDBG_ERR(("No valid SRC handle in EQ handle %u", eqStage)); |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | BDBG_MSG(("Equalizer Stage Type %d, Sample Rate %u",eqStage->settings.type, eqStage->sampleRate)); |
|---|
| 1100 | switch(eqStage->settings.type) |
|---|
| 1101 | { |
|---|
| 1102 | case BAPE_EqualizerStageType_eToneControl: |
|---|
| 1103 | |
|---|
| 1104 | /* Cut off Freq of Bass and Treble hardcoded to 100 and 10000 for |
|---|
| 1105 | now */ |
|---|
| 1106 | BDBG_MSG(("\n bassGain = %d trebleGain = %d \n bassFreq = %u trebleFreq = %u" |
|---|
| 1107 | "\n bassEqType = %d trebleEqType = %d \n bassBandwidthFreq = %u trebleBandwidthFreq = %u", |
|---|
| 1108 | eqStage->settings.modeSettings.toneControl.bassGain, |
|---|
| 1109 | eqStage->settings.modeSettings.toneControl.trebleGain, |
|---|
| 1110 | eqStage->settings.modeSettings.toneControl.bassFreq, |
|---|
| 1111 | eqStage->settings.modeSettings.toneControl.trebleFreq, |
|---|
| 1112 | eqStage->settings.modeSettings.toneControl.bassEqType, |
|---|
| 1113 | eqStage->settings.modeSettings.toneControl.trebleEqType, |
|---|
| 1114 | eqStage->settings.modeSettings.toneControl.bassBandwidthFreq, |
|---|
| 1115 | eqStage->settings.modeSettings.toneControl.trebleBandwidthFreq)); |
|---|
| 1116 | |
|---|
| 1117 | EQ_generate_tone_control ( |
|---|
| 1118 | eqStage->sampleRate, |
|---|
| 1119 | eqStage->settings.modeSettings.toneControl.bassGain, |
|---|
| 1120 | eqStage->settings.modeSettings.toneControl.trebleGain, |
|---|
| 1121 | eqStage->settings.modeSettings.toneControl.bassFreq, |
|---|
| 1122 | eqStage->settings.modeSettings.toneControl.trebleFreq, |
|---|
| 1123 | eqStage->settings.modeSettings.toneControl.bassEqType, |
|---|
| 1124 | eqStage->settings.modeSettings.toneControl.trebleEqType, |
|---|
| 1125 | eqStage->settings.modeSettings.toneControl.bassBandwidthFreq, |
|---|
| 1126 | eqStage->settings.modeSettings.toneControl.trebleBandwidthFreq, |
|---|
| 1127 | &pCoeff->b0[0], |
|---|
| 1128 | &pCoeff->b1[0], |
|---|
| 1129 | &pCoeff->b2[0], |
|---|
| 1130 | &pCoeff->a1[0], |
|---|
| 1131 | &pCoeff->a2[0] |
|---|
| 1132 | ); |
|---|
| 1133 | break; |
|---|
| 1134 | case BAPE_EqualizerStageType_eFiveBand: |
|---|
| 1135 | |
|---|
| 1136 | geqdB[0] = eqStage->settings.modeSettings.fiveBand.gain100Hz; |
|---|
| 1137 | geqdB[1] = eqStage->settings.modeSettings.fiveBand.gain300Hz; |
|---|
| 1138 | geqdB[2] = eqStage->settings.modeSettings.fiveBand.gain1000Hz; |
|---|
| 1139 | geqdB[3] = eqStage->settings.modeSettings.fiveBand.gain3000Hz; |
|---|
| 1140 | geqdB[4] = eqStage->settings.modeSettings.fiveBand.gain10000Hz; |
|---|
| 1141 | |
|---|
| 1142 | BDBG_MSG(("Gain at Frequencies: \n 100: %d \n 300: %d \n 1000: %d \n 3000: %d \n 10000: %d", |
|---|
| 1143 | geqdB[0],geqdB[1],geqdB[2],geqdB[3],geqdB[4])); |
|---|
| 1144 | |
|---|
| 1145 | EQ_generate_geq ( |
|---|
| 1146 | eqStage->sampleRate, |
|---|
| 1147 | geqdB, |
|---|
| 1148 | &pCoeff->b0[0], |
|---|
| 1149 | &pCoeff->b1[0], |
|---|
| 1150 | &pCoeff->b2[0], |
|---|
| 1151 | &pCoeff->a1[0], |
|---|
| 1152 | &pCoeff->a2[0] |
|---|
| 1153 | ); |
|---|
| 1154 | break; |
|---|
| 1155 | |
|---|
| 1156 | case BAPE_EqualizerStageType_eSevenBand: |
|---|
| 1157 | for (i=0;i<7;i++) |
|---|
| 1158 | { |
|---|
| 1159 | EQ_generate_peq( |
|---|
| 1160 | eqStage->settings.modeSettings.sevenBand.bandSettings[i].peak, |
|---|
| 1161 | eqStage->settings.modeSettings.sevenBand.bandSettings[i].q, |
|---|
| 1162 | eqStage->settings.modeSettings.sevenBand.bandSettings[i].gain, |
|---|
| 1163 | eqStage->sampleRate, |
|---|
| 1164 | 70, /* Percentage of Peak Edge to Peak Gain */ |
|---|
| 1165 | b, |
|---|
| 1166 | a |
|---|
| 1167 | ); |
|---|
| 1168 | pCoeff->b0[i] = b[0]; |
|---|
| 1169 | pCoeff->b1[i] = b[1]; |
|---|
| 1170 | pCoeff->b2[i] = b[2]; |
|---|
| 1171 | pCoeff->a1[i] = a[1]; |
|---|
| 1172 | pCoeff->a2[i] = a[2]; |
|---|
| 1173 | } |
|---|
| 1174 | break; |
|---|
| 1175 | |
|---|
| 1176 | case BAPE_EqualizerStageType_eSubsonic: |
|---|
| 1177 | |
|---|
| 1178 | EQ_subsonic_HPF( |
|---|
| 1179 | eqStage->sampleRate, |
|---|
| 1180 | eqStage->settings.modeSettings.subsonic.frequency, |
|---|
| 1181 | eqStage->settings.modeSettings.subsonic.filterType, |
|---|
| 1182 | eqStage->settings.modeSettings.subsonic.filterOrder, |
|---|
| 1183 | &pCoeff->b0[0], |
|---|
| 1184 | &pCoeff->b1[0], |
|---|
| 1185 | &pCoeff->b2[0], |
|---|
| 1186 | &pCoeff->a1[0], |
|---|
| 1187 | &pCoeff->a2[0] |
|---|
| 1188 | ); |
|---|
| 1189 | break; |
|---|
| 1190 | |
|---|
| 1191 | case BAPE_EqualizerStageType_eSubwoofer: |
|---|
| 1192 | |
|---|
| 1193 | EQ_subwoofer_LPF( |
|---|
| 1194 | eqStage->sampleRate, |
|---|
| 1195 | eqStage->settings.modeSettings.subwoofer.frequency, |
|---|
| 1196 | eqStage->settings.modeSettings.subwoofer.filterType, |
|---|
| 1197 | eqStage->settings.modeSettings.subwoofer.filterOrder, |
|---|
| 1198 | &pCoeff->b0[0], |
|---|
| 1199 | &pCoeff->b1[0], |
|---|
| 1200 | &pCoeff->b2[0], |
|---|
| 1201 | &pCoeff->a1[0], |
|---|
| 1202 | &pCoeff->a2[0] |
|---|
| 1203 | ); |
|---|
| 1204 | break; |
|---|
| 1205 | |
|---|
| 1206 | case BAPE_EqualizerStageType_eCustom: |
|---|
| 1207 | |
|---|
| 1208 | { |
|---|
| 1209 | BAPE_EqualizerCustomSettings *pcustomSettings; |
|---|
| 1210 | |
|---|
| 1211 | pcustomSettings = &(eqStage->settings.modeSettings.custom); |
|---|
| 1212 | if(pcustomSettings->numFilters > BAPE_EQUALIZER_MAX_CUSTOM_FILTERS) |
|---|
| 1213 | { |
|---|
| 1214 | BDBG_ERR(("Number of Custom EQ filters cannot be " |
|---|
| 1215 | "more than %d. No programming done.", |
|---|
| 1216 | BAPE_EQUALIZER_MAX_CUSTOM_FILTERS)); |
|---|
| 1217 | } |
|---|
| 1218 | |
|---|
| 1219 | for (i=0; i < pcustomSettings->numFilters; i++) |
|---|
| 1220 | { |
|---|
| 1221 | |
|---|
| 1222 | /* The 35230 SRC hardware has 28 bits of resolution for the coef |
|---|
| 1223 | in 3.25 format (28 bits + 4unused). Earlier (in 3548) though |
|---|
| 1224 | the total bits were 28, the format was 2.26. Hence the validity |
|---|
| 1225 | for the coeff range will be from 0xF0000000 - 0x0FFFFFFF */ |
|---|
| 1226 | if(((pcustomSettings->filterCoefficients[i].b0 < (int32_t) 0xF0000000) || |
|---|
| 1227 | (pcustomSettings->filterCoefficients[i].b0 > (int32_t) 0x0FFFFFFF))|| |
|---|
| 1228 | ((pcustomSettings->filterCoefficients[i].b1 < (int32_t) 0xF0000000) || |
|---|
| 1229 | (pcustomSettings->filterCoefficients[i].b1 > (int32_t) 0x0FFFFFFF))|| |
|---|
| 1230 | ((pcustomSettings->filterCoefficients[i].b2 < (int32_t) 0xF0000000) || |
|---|
| 1231 | (pcustomSettings->filterCoefficients[i].b2 > (int32_t) 0x0FFFFFFF))|| |
|---|
| 1232 | ((pcustomSettings->filterCoefficients[i].a1 < (int32_t) 0xF0000000) || |
|---|
| 1233 | (pcustomSettings->filterCoefficients[i].a1 > (int32_t) 0x0FFFFFFF))|| |
|---|
| 1234 | ((pcustomSettings->filterCoefficients[i].a2 < (int32_t) 0xF0000000) || |
|---|
| 1235 | (pcustomSettings->filterCoefficients[i].a2 > (int32_t) 0x0FFFFFFF))) |
|---|
| 1236 | { |
|---|
| 1237 | BDBG_ERR(("One or more of Custom EQ settings are out of bounds." |
|---|
| 1238 | "No programming done.")); |
|---|
| 1239 | } |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | for (i=0; i < pcustomSettings->numFilters; i++) |
|---|
| 1243 | { |
|---|
| 1244 | /* User coeff in 2.26 --> SRC-EQ in 35230 is in 3.25 format |
|---|
| 1245 | Hence divide by 2 */ |
|---|
| 1246 | pCoeff->b0[i] = pcustomSettings->filterCoefficients[i].b0/2; |
|---|
| 1247 | pCoeff->b1[i] = pcustomSettings->filterCoefficients[i].b1/2; |
|---|
| 1248 | pCoeff->b2[i] = pcustomSettings->filterCoefficients[i].b2/2; |
|---|
| 1249 | pCoeff->a1[i] = pcustomSettings->filterCoefficients[i].a1/2; |
|---|
| 1250 | pCoeff->a2[i] = pcustomSettings->filterCoefficients[i].a2/2; |
|---|
| 1251 | } |
|---|
| 1252 | } |
|---|
| 1253 | break; |
|---|
| 1254 | |
|---|
| 1255 | default: |
|---|
| 1256 | return; |
|---|
| 1257 | } |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | static void BAPE_EqualizerStage_P_UpdateCoefficients_isr( |
|---|
| 1261 | BAPE_EqualizerStageHandle eqStage, |
|---|
| 1262 | BAPE_SRC_P_IIRCoeff *pCoeff) |
|---|
| 1263 | { |
|---|
| 1264 | unsigned i, *pStepSize = NULL; |
|---|
| 1265 | |
|---|
| 1266 | if((BAPE_EqualizerStageType_eSevenBand != eqStage->settings.type) && |
|---|
| 1267 | (BAPE_EqualizerStageType_eCustom != eqStage->settings.type)) |
|---|
| 1268 | { |
|---|
| 1269 | /* Divide by 4 the first Bi-Quad */ |
|---|
| 1270 | pCoeff->b0[0] /= (-4); |
|---|
| 1271 | pCoeff->b1[0] /= (-4); |
|---|
| 1272 | pCoeff->b2[0] /= (-4); |
|---|
| 1273 | |
|---|
| 1274 | /* Multiply by 4 the last Bi-Quad */ |
|---|
| 1275 | pCoeff->b0[7] = 0x8000000; |
|---|
| 1276 | pCoeff->b1[7] = 0; |
|---|
| 1277 | pCoeff->b2[7] = 0; |
|---|
| 1278 | pCoeff->a1[7] = 0; |
|---|
| 1279 | pCoeff->a2[7] = 0; |
|---|
| 1280 | } |
|---|
| 1281 | |
|---|
| 1282 | /* Program Coefficients for all Paths(SRCs) that have this EQ stage operation. |
|---|
| 1283 | In future if Coefficient memory is shared, control the programming here, |
|---|
| 1284 | i.e., if Coefficient memory is updated then program only SRC link to it */ |
|---|
| 1285 | if(eqStage->settings.rampSettings.enable) |
|---|
| 1286 | { |
|---|
| 1287 | pStepSize = &(eqStage->settings.rampSettings.stepSize); |
|---|
| 1288 | } |
|---|
| 1289 | for(i=0; i<BAPE_P_MAX_EQSTAGE_INSTANCES; i++) |
|---|
| 1290 | { |
|---|
| 1291 | if(NULL != eqStage->srcGroups[i]) |
|---|
| 1292 | { |
|---|
| 1293 | BAPE_SrcGroup_P_UpdateCoefficients_isr(eqStage->srcGroups[i], pCoeff, pStepSize); |
|---|
| 1294 | } |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | } |
|---|
| 1298 | |
|---|
| 1299 | #else |
|---|
| 1300 | |
|---|
| 1301 | /*************************************************************************** |
|---|
| 1302 | Summary: |
|---|
| 1303 | Get default open settings for an equalizer stage |
|---|
| 1304 | ***************************************************************************/ |
|---|
| 1305 | void BAPE_EqualizerStage_GetDefaultSettings( |
|---|
| 1306 | BAPE_EqualizerStageType type, |
|---|
| 1307 | BAPE_EqualizerStageSettings *pSettings /* [out] */ |
|---|
| 1308 | ) |
|---|
| 1309 | { |
|---|
| 1310 | BSTD_UNUSED(type); |
|---|
| 1311 | BSTD_UNUSED(pSettings); |
|---|
| 1312 | } |
|---|
| 1313 | |
|---|
| 1314 | BERR_Code BAPE_EqualizerStage_Create( |
|---|
| 1315 | BAPE_Handle deviceHandle, |
|---|
| 1316 | const BAPE_EqualizerStageSettings *pSettings, |
|---|
| 1317 | BAPE_EqualizerStageHandle *pHandle /* [out] */ |
|---|
| 1318 | ) |
|---|
| 1319 | { |
|---|
| 1320 | BSTD_UNUSED(deviceHandle); |
|---|
| 1321 | BSTD_UNUSED(pSettings); |
|---|
| 1322 | BSTD_UNUSED(pHandle); |
|---|
| 1323 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1324 | } |
|---|
| 1325 | |
|---|
| 1326 | void BAPE_EqualizerStage_Destroy( |
|---|
| 1327 | BAPE_EqualizerStageHandle handle |
|---|
| 1328 | ) |
|---|
| 1329 | { |
|---|
| 1330 | BSTD_UNUSED(handle); |
|---|
| 1331 | } |
|---|
| 1332 | |
|---|
| 1333 | void BAPE_EqualizerStage_GetSettings( |
|---|
| 1334 | BAPE_EqualizerStageHandle handle, |
|---|
| 1335 | BAPE_EqualizerStageSettings *pSettings /* [out] */ |
|---|
| 1336 | ) |
|---|
| 1337 | { |
|---|
| 1338 | BSTD_UNUSED(handle); |
|---|
| 1339 | BSTD_UNUSED(pSettings); |
|---|
| 1340 | } |
|---|
| 1341 | |
|---|
| 1342 | BERR_Code BAPE_EqualizerStage_SetSettings( |
|---|
| 1343 | BAPE_EqualizerStageHandle handle, |
|---|
| 1344 | const BAPE_EqualizerStageSettings *pSettings |
|---|
| 1345 | ) |
|---|
| 1346 | { |
|---|
| 1347 | BSTD_UNUSED(handle); |
|---|
| 1348 | BSTD_UNUSED(pSettings); |
|---|
| 1349 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1350 | } |
|---|
| 1351 | |
|---|
| 1352 | void BAPE_Equalizer_GetDefaultSettings( |
|---|
| 1353 | BAPE_EqualizerSettings *pSettings /* [out] */ |
|---|
| 1354 | ) |
|---|
| 1355 | { |
|---|
| 1356 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 1357 | BKNI_Memset(pSettings, 0, sizeof(BAPE_EqualizerSettings)); |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | BERR_Code BAPE_Equalizer_Create( |
|---|
| 1361 | BAPE_Handle deviceHandle, |
|---|
| 1362 | const BAPE_EqualizerSettings *pSettings, |
|---|
| 1363 | BAPE_EqualizerHandle *pHandle /* [out] */ |
|---|
| 1364 | ) |
|---|
| 1365 | { |
|---|
| 1366 | BSTD_UNUSED(deviceHandle); |
|---|
| 1367 | BSTD_UNUSED(pSettings); |
|---|
| 1368 | BSTD_UNUSED(pHandle); |
|---|
| 1369 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1370 | } |
|---|
| 1371 | |
|---|
| 1372 | void BAPE_Equalizer_Destroy( |
|---|
| 1373 | BAPE_EqualizerHandle handle |
|---|
| 1374 | ) |
|---|
| 1375 | { |
|---|
| 1376 | BSTD_UNUSED(handle); |
|---|
| 1377 | } |
|---|
| 1378 | BERR_Code BAPE_Equalizer_SetStages( |
|---|
| 1379 | BAPE_EqualizerHandle handle, |
|---|
| 1380 | BAPE_EqualizerStageHandle *pStages, |
|---|
| 1381 | unsigned numStages |
|---|
| 1382 | ) |
|---|
| 1383 | { |
|---|
| 1384 | BSTD_UNUSED(handle); |
|---|
| 1385 | BSTD_UNUSED(pStages); |
|---|
| 1386 | BSTD_UNUSED(numStages); |
|---|
| 1387 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1388 | } |
|---|
| 1389 | |
|---|
| 1390 | void BAPE_Equalizer_ClearStages( |
|---|
| 1391 | BAPE_EqualizerHandle handle |
|---|
| 1392 | ) |
|---|
| 1393 | { |
|---|
| 1394 | BSTD_UNUSED(handle); |
|---|
| 1395 | } |
|---|
| 1396 | |
|---|
| 1397 | BERR_Code BAPE_Equalizer_AddInput( |
|---|
| 1398 | BAPE_EqualizerHandle handle, |
|---|
| 1399 | BAPE_Connector input |
|---|
| 1400 | ) |
|---|
| 1401 | { |
|---|
| 1402 | BSTD_UNUSED(handle); |
|---|
| 1403 | BSTD_UNUSED(input); |
|---|
| 1404 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1405 | } |
|---|
| 1406 | |
|---|
| 1407 | BERR_Code BAPE_Equalizer_RemoveInput( |
|---|
| 1408 | BAPE_EqualizerHandle handle, |
|---|
| 1409 | BAPE_Connector input |
|---|
| 1410 | ) |
|---|
| 1411 | { |
|---|
| 1412 | BSTD_UNUSED(handle); |
|---|
| 1413 | BSTD_UNUSED(input); |
|---|
| 1414 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1415 | } |
|---|
| 1416 | |
|---|
| 1417 | BERR_Code BAPE_Equalizer_RemoveAllInputs( |
|---|
| 1418 | BAPE_EqualizerHandle handle |
|---|
| 1419 | ) |
|---|
| 1420 | { |
|---|
| 1421 | BSTD_UNUSED(handle); |
|---|
| 1422 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 1423 | } |
|---|
| 1424 | |
|---|
| 1425 | void BAPE_Equalizer_GetConnector( |
|---|
| 1426 | BAPE_EqualizerHandle handle, |
|---|
| 1427 | BAPE_Connector *pConnector /* [out] */ |
|---|
| 1428 | ) |
|---|
| 1429 | { |
|---|
| 1430 | BSTD_UNUSED(handle); |
|---|
| 1431 | BSTD_UNUSED(pConnector); |
|---|
| 1432 | } |
|---|
| 1433 | #endif |
|---|
| 1434 | |
|---|