source: svn/newcon3bcm2_21bu/magnum/portinginterface/ape/7552/bape_tru_volume.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 30.0 KB
Line 
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: bape_tru_volume.c $
39* $brcm_Revision: Hydra_Software_Devel/13 $
40* $brcm_Date: 3/2/12 10:25a $
41*
42* API Description:
43*   API name: TruVolume
44*    Specific APIs related to SRS TruVolume (formerly Volume IQ) Audio Processing
45*
46* Revision History:
47*
48* $brcm_Log: /magnum/portinginterface/ape/7422/bape_tru_volume.c $
49*
50* Hydra_Software_Devel/13   3/2/12 10:25a jgarrett
51* SWDTV-6761: Fixing reference level mapping
52*
53* Hydra_Software_Devel/12   7/15/11 5:51p jgarrett
54* SWDTV-6761: Adding StudioSound API
55*
56* Hydra_Software_Devel/11   4/29/11 11:00a jgarrett
57* SW7422-368: Switching to new GetDefaultSettings routines
58*
59* Hydra_Software_Devel/10   4/18/11 10:09p jgarrett
60* SW7425-361, SW7422-411: Refactoring DSP branch decisions.  Fixed user
61* params for input/output/reference gains
62*
63* Hydra_Software_Devel/9   4/16/11 12:32p jgarrett
64* SW7425-371: Removing tabs
65*
66* Hydra_Software_Devel/8   4/16/11 12:23p jgarrett
67* SW7425-371: Removing tab characters
68*                                                                                     
69* Hydra_Software_Devel/7   4/15/11 4:29p piyushg
70* SW7422-411: Disable SRS StudioSound processing for TruVolume.
71*
72* Hydra_Software_Devel/6   4/14/11 7:18p piyushg
73* SW7422-411: Map DSP settings between APE and the base module
74*
75* Hydra_Software_Devel/5   3/11/11 12:20p jgarrett
76* SW7422-146: Enabling PPM Correction
77*
78* Hydra_Software_Devel/4   3/1/11 5:13p jgarrett
79* SW7422-146: Fixing post-processing output modes
80*
81* Hydra_Software_Devel/3   2/28/11 4:50p jgarrett
82* SW7422-146: Adding TruVolume
83*
84* Hydra_Software_Devel/2   2/22/11 5:44p jgarrett
85* SW7422-146: Implemented type renaming based on filter graph review
86* comments
87*
88* Hydra_Software_Devel/1   1/12/11 4:24p jgarrett
89* SW7422-146: Adding additional APIs
90*
91***************************************************************************/
92
93#include "bape.h"
94#include "bape_priv.h"
95#include "bdsp_raaga.h"
96
97BDBG_MODULE(bape_tru_volume);
98
99BDBG_OBJECT_ID(BAPE_TruVolume);
100
101typedef struct BAPE_TruVolume
102{
103    BDBG_OBJECT(BAPE_TruVolume)
104    BAPE_PathNode node;
105    BAPE_TruVolumeSettings settings;
106    BAPE_Connector input;
107} BAPE_TruVolume;
108
109static BERR_Code BAPE_TruVolume_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector);
110static BERR_Code BAPE_TruVolume_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
111static BERR_Code BAPE_TruVolume_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
112static BERR_Code BAPE_TruVolume_P_ApplyTruVolumeSettings(BAPE_TruVolumeHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId);
113static void BAPE_TruVolume_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
114static void BAPE_TruVolume_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector);
115
116/***************************************************************************
117Summary:
118    Get default settings for an SRS TruVolume stage
119***************************************************************************/
120void BAPE_TruVolume_GetDefaultSettings(
121    BAPE_TruVolumeSettings *pSettings   /* [out] default settings */
122    )
123{
124    BDSP_Raaga_Audio_TruVolumeUserConfig dspSettings;
125    unsigned i, j;
126
127    BDBG_ASSERT(NULL != pSettings);
128    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
129    BDSP_Raaga_GetDefaultAudioProcessingSettings(BDSP_AudioProcessing_eSrsTruVolume, 
130                                                 (void *)&dspSettings, 
131                                                 sizeof(BDSP_Raaga_Audio_TruVolumeUserConfig)
132                                                 );
133
134    pSettings->enabled = dspSettings.i32TruVolume_enable?true:false;
135
136    switch (dspSettings.i32blockSize)
137    {
138    case 256:
139        pSettings->blockSize = BAPE_TruVolumeBlockSize_e256;
140        break;
141    case 512:
142        pSettings->blockSize = BAPE_TruVolumeBlockSize_e512;
143        break;
144    case 768:
145        pSettings->blockSize = BAPE_TruVolumeBlockSize_e768;
146        break;
147    case 1024:
148        pSettings->blockSize = BAPE_TruVolumeBlockSize_e1024;
149        break;
150    default:
151        pSettings->blockSize = BAPE_TruVolumeBlockSize_eMax;
152        break;
153    }
154
155    pSettings->enableNormalGain = dspSettings.i32mEnable?true:false;
156    pSettings->inputGain = 100;
157    BDBG_ASSERT(dspSettings.i32mInputGain == 0x00040000);
158    pSettings->outputGain = 50;
159    BDBG_ASSERT(dspSettings.i32mOutputGain == 0x00020000);
160    pSettings->bypassGain = 100;
161    BDBG_ASSERT(0x007fffff == dspSettings.i32mBypassGain);
162    pSettings->referenceLevel = dspSettings.i32mReferenceLevel;
163
164    switch (dspSettings.i32mMode)
165    {
166    case 0:
167        pSettings->mode = BAPE_TruVolumeMode_eLight;
168        break;
169    case 1:
170        pSettings->mode = BAPE_TruVolumeMode_eNormal;
171        break;
172    case 2:
173        pSettings->mode = BAPE_TruVolumeMode_eHeavy;
174        break;
175    default:
176        pSettings->mode = BAPE_TruVolumeMode_eMax;
177        break;
178    }
179
180    switch (dspSettings.i32mSize)
181    {
182    case 0:
183        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e20Hz;
184        break;
185    case 1:
186        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e40Hz;
187        break;
188    case 2:
189        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e110Hz;
190        break;
191    case 3:
192        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e200Hz;
193        break;
194    case 4:
195        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e315Hz;
196        break;
197    case 5:
198        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_e410Hz;
199        break;
200    default:
201        pSettings->speakerResolution = BAPE_TruVolumeSpeakerResolution_eMax;
202        break;
203    }
204
205    pSettings->maxGain = 64;
206    BDBG_ASSERT(0x00080000 == dspSettings.i32mMaxGain);
207    pSettings->enableDcNotchFilter = dspSettings.i32EnableDCNotchFilter?true:false;
208    pSettings->enableNoiseManager = dspSettings.i32mNoiseManager?true:false;
209    pSettings->noiseManagerThreshold = 20;
210    BDBG_ASSERT(0x000ccccd == dspSettings.i32mNoiseManagerThreshold);
211    pSettings->enableNormalizer = dspSettings.i32mNormalizerEnable?true:false;
212    pSettings->calibrate = 100;
213    BDBG_ASSERT(0x8000 == dspSettings.i32mCalibrate);
214
215    /* Top-level HPF settings */
216    pSettings->highPassFilter.enabled = (dspSettings.sHighPassFilterConfig.ui32mEnable)?true:false;
217    switch ( dspSettings.sHighPassFilterConfig.ui32CoefGenMode )
218    {
219    default:
220        BDBG_WRN(("Unrecognized filter coefficient gen mode in default truvolume settings."));
221        /* fall through */
222    case 0:
223        pSettings->highPassFilter.coefficientMode = BAPE_SrsFilterCoefficientMode_eUser;       
224        break;
225    case 1:
226        pSettings->highPassFilter.coefficientMode = BAPE_SrsFilterCoefficientMode_eSpecification;
227        break;
228    }
229   
230    /* User Coefs */
231    BDBG_CASSERT((sizeof(dspSettings.sHighPassFilterConfig.sFilterCoefHpf)/sizeof(BDSP_Raaga_FilterCoefHpf)) == 3);
232    for ( i = 0; i < 3; i++ )
233    {
234        pSettings->highPassFilter.coefficientSettings.user[i].filterOrder = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].ui32Order;
235        BDBG_CASSERT((sizeof(dspSettings.sHighPassFilterConfig.sFilterCoefHpf[0].sFilterCoefHpfTdf2)/sizeof(BDSP_Raaga_FilterCoefHpfTdf2)) == 3);
236        for ( j = 0; j < 3; j++ )
237        {
238            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].scale = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32Scale;
239            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB0 = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB0;
240            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB1 = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB1;
241            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB2 = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB2;
242            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientA1 = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB1;
243            pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientA2 = dspSettings.sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientA2;
244        }
245    }
246
247    /* Specification */
248    pSettings->highPassFilter.coefficientSettings.specification.cutoffFrequency = dspSettings.sHighPassFilterConfig.sFilterSpecHpf.ui32CutoffFrequency;
249    pSettings->highPassFilter.coefficientSettings.specification.filterOrder = dspSettings.sHighPassFilterConfig.sFilterSpecHpf.ui32Order;
250}
251
252/***************************************************************************
253Summary:
254    Open an SRS TruVolume stage
255***************************************************************************/
256BERR_Code BAPE_TruVolume_Create(
257                               BAPE_Handle deviceHandle,
258                               const BAPE_TruVolumeSettings *pSettings,
259                               BAPE_TruVolumeHandle *pHandle
260                               )
261{
262    BAPE_TruVolumeHandle handle;
263
264    BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device);
265    BDBG_ASSERT(NULL != pSettings);
266    BDBG_ASSERT(NULL != pHandle);
267
268
269    handle = BKNI_Malloc(sizeof(BAPE_TruVolume));
270    if ( NULL == handle )
271    {
272        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
273    }
274    BKNI_Memset(handle, 0, sizeof(BAPE_TruVolume));
275    BDBG_OBJECT_SET(handle, BAPE_TruVolume);
276    handle->settings = *pSettings;
277    BAPE_P_InitPathNode(&handle->node, BAPE_PathNodeType_ePostProcessor, BAPE_PostProcessorType_eTruVolume, 1, deviceHandle, handle);
278    handle->node.pName = "TruVolume";
279    handle->node.paths[0].connector.numChannelPairs = 1; /* Only output stereo */
280    handle->node.paths[0].connector.useBufferPool = true;   
281    handle->node.paths[0].connector.dataSource = BAPE_DataSource_eDspBuffer;   
282
283    /* Generic Routines */
284    handle->node.allocatePathToOutput = BAPE_DSP_P_AllocatePathToOutput;
285    handle->node.configPathToOutput = BAPE_DSP_P_ConfigPathToOutput;
286    handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput;
287    handle->node.startPathToOutput = BAPE_DSP_P_StartPathToOutput;
288    handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput;
289
290    /* TruVolume Specifics */
291    handle->node.connectorSupported = BAPE_TruVolume_P_ConnectorSupported;
292    handle->node.allocatePathFromInput = BAPE_TruVolume_P_AllocatePathFromInput;
293    handle->node.configPathFromInput = BAPE_TruVolume_P_ConfigPathFromInput;
294    handle->node.stopPathFromInput = BAPE_TruVolume_P_StopPathFromInput;
295    handle->node.removeInput = BAPE_TruVolume_P_RemoveInputCallback;
296
297    *pHandle = handle;
298    return BERR_SUCCESS;
299}
300
301
302/***************************************************************************
303Summary:
304    Close an SRS TruVolume stage
305   
306Description:
307    Input to the stage must be removed prior to closing.
308***************************************************************************/
309void BAPE_TruVolume_Destroy(
310                           BAPE_TruVolumeHandle handle
311                           )
312{
313    bool running;
314    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
315    running = (handle->node.paths[0].connector.task != NULL)?true:false;
316    BDBG_ASSERT(false == running);
317    BDBG_ASSERT(NULL == handle->input);
318    BDBG_OBJECT_DESTROY(handle, BAPE_TruVolume);
319    BKNI_Free(handle);
320}
321
322/***************************************************************************
323Summary:
324    Get Settings for an SRS TruVolume stage
325***************************************************************************/
326void BAPE_TruVolume_GetSettings(
327                               BAPE_TruVolumeHandle handle,
328                               BAPE_TruVolumeSettings *pSettings    /* [out] Settings */
329                               )
330{
331    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
332    BDBG_ASSERT(NULL != pSettings);
333    *pSettings = handle->settings;
334}
335
336
337/***************************************************************************
338Summary:
339    Set Settings for an SRS TruVolume stage
340***************************************************************************/
341BERR_Code BAPE_TruVolume_SetSettings(
342                                    BAPE_TruVolumeHandle handle,
343                                    const BAPE_TruVolumeSettings *pSettings
344                                    )
345{
346    BERR_Code errCode;
347    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
348    BDBG_ASSERT(NULL != pSettings);
349
350    /* Start time will always call this routine, don't copy the settings if we don't need to */
351    if ( pSettings != &handle->settings )
352    {
353        handle->settings = *pSettings;
354    }
355
356    if ( handle->node.paths[0].connector.task != NULL )
357    {
358        errCode = BAPE_TruVolume_P_ApplyTruVolumeSettings(handle, 
359                                                          handle->node.paths[0].connector.task, 
360                                                          handle->node.paths[0].connector.branchId, 
361                                                          handle->node.paths[0].connector.stageId);
362        if ( errCode )
363        {
364            return BERR_TRACE(errCode);
365        }
366    }
367
368    return BERR_SUCCESS;
369}
370
371
372/***************************************************************************
373Summary:
374    Get the audio connector for an SRS TruVolume stage
375***************************************************************************/
376void BAPE_TruVolume_GetConnector(
377                                BAPE_TruVolumeHandle handle,
378                                BAPE_Connector *pConnector
379                                )
380{
381    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
382    BDBG_ASSERT(NULL != pConnector);
383    *pConnector = &handle->node.paths[0].connector;
384}
385
386
387/***************************************************************************
388Summary:
389Add an input to this processing stage
390***************************************************************************/
391BERR_Code BAPE_TruVolume_AddInput(
392                                 BAPE_TruVolumeHandle handle,
393                                 BAPE_Connector input
394                                 )
395{
396    BERR_Code errCode;
397    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
398    BDBG_OBJECT_ASSERT(input, BAPE_PathConnector);
399    if ( NULL != handle->input )
400    {
401        BDBG_ERR(("Can not have more than one input"));
402        return BERR_TRACE(BERR_NOT_SUPPORTED);
403    }
404    errCode = BAPE_PathNode_P_AddInput(&handle->node, input);
405    if ( errCode )
406    {
407        return BERR_TRACE(errCode);
408    }
409    handle->input = input;
410    return BERR_SUCCESS;
411}
412
413
414/***************************************************************************
415Summary:
416Remove an input from this processing stage
417***************************************************************************/
418BERR_Code BAPE_TruVolume_RemoveInput(
419                                    BAPE_TruVolumeHandle handle,
420                                    BAPE_Connector input
421                                    )
422{
423    BERR_Code errCode;
424    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
425    BDBG_OBJECT_ASSERT(input, BAPE_PathConnector);
426    if ( input != handle->input )
427    {
428        BDBG_ERR(("Input %s %s (%#x) is not connected", input->pParent->pName, input->pName, input));
429        return BERR_TRACE(BERR_INVALID_PARAMETER);
430    }
431    errCode = BAPE_PathNode_P_RemoveInput(&handle->node, input);
432    if ( errCode )
433    {
434        return BERR_TRACE(errCode);
435    }
436    handle->input = NULL;
437    return BERR_SUCCESS;
438}
439
440
441/***************************************************************************
442Summary:
443Remove all inputs from this processing stage
444***************************************************************************/
445BERR_Code BAPE_TruVolume_RemoveAllInputs(
446                                        BAPE_TruVolumeHandle handle
447                                        )
448{
449    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
450    if ( handle->input )
451    {
452        return BAPE_TruVolume_RemoveInput(handle, handle->input);
453    }
454    return BERR_SUCCESS;
455}
456
457static BERR_Code BAPE_TruVolume_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector)
458{
459    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
460    BDBG_OBJECT_ASSERT(pConnector, BAPE_PathConnector);
461    if ( pConnector->dataSource == BAPE_DataSource_eDspBuffer &&
462         pConnector->numChannelPairs == 1 &&
463         !pConnector->compressed )
464    {
465        return BERR_SUCCESS;
466    }
467    else
468    {
469        BDBG_ERR(("Only stereo DSP input is supported"));
470        return BERR_TRACE(BERR_INVALID_PARAMETER);
471    }
472}
473
474static BERR_Code BAPE_TruVolume_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
475{
476    BERR_Code errCode;
477    BAPE_TruVolumeHandle handle;
478    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
479    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
480    BDBG_ASSERT(NULL != pConnection->pSource->pTaskCreateSettings);
481    handle = pNode->pHandle;
482    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
483    /* Add stage to CIT and propagate task settings */
484    errCode = BAPE_DSP_P_AddProcessingStage(pConnection->pSource->pTaskCreateSettings, pConnection->pSource->branchId, pConnection->pSource->stageId, 
485                                            BAPE_DSP_P_GetDataTypeFromConnector(handle->input), 
486                                            BDSP_AudioProcessing_eSrsTruVolume,
487                                            false,
488                                            &pNode->paths[0].connector.branchId, &pNode->paths[0].connector.stageId);
489    if ( errCode )
490    {
491        return BERR_TRACE(errCode);
492    }
493    pNode->paths[0].connector.pTaskCreateSettings = pConnection->pSource->pTaskCreateSettings;
494    return BERR_SUCCESS;
495}
496
497static BERR_Code BAPE_TruVolume_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
498{
499    BERR_Code errCode;
500    BAPE_TruVolumeHandle handle;
501    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
502    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
503    BDBG_ASSERT(NULL != pConnection->pSource->task);
504
505    handle = pNode->pHandle;
506    BDBG_OBJECT_ASSERT(handle, BAPE_TruVolume);
507    pNode->paths[0].connector.task = pConnection->pSource->task;
508    errCode = BAPE_TruVolume_P_ApplyTruVolumeSettings(handle, 
509                                                      handle->node.paths[0].connector.task, 
510                                                      handle->node.paths[0].connector.branchId, 
511                                                      handle->node.paths[0].connector.stageId);
512    if ( errCode )
513    {
514        return BERR_TRACE(errCode);
515    }
516
517    return BERR_SUCCESS;   
518}
519
520BERR_Code BAPE_TruVolume_P_ConvertSettingsToDsp(
521    const BAPE_TruVolumeSettings *pSettings, 
522    BDSP_Raaga_Audio_TruVolumeUserConfig *pUserConfig
523    )
524{
525    unsigned i, j;
526
527    BDBG_ASSERT(NULL != pSettings);
528    BDBG_ASSERT(NULL != pUserConfig);
529
530    BDBG_MSG(("BlockSize was %u", pUserConfig->i32blockSize));
531    switch (pSettings->blockSize)
532    {
533    case BAPE_TruVolumeBlockSize_e256:
534        pUserConfig->i32blockSize = 256;
535        break;
536    case BAPE_TruVolumeBlockSize_e512:
537        pUserConfig->i32blockSize = 512;
538        break;
539    case BAPE_TruVolumeBlockSize_e768:
540        pUserConfig->i32blockSize = 768;
541        break;
542    case BAPE_TruVolumeBlockSize_e1024:
543        pUserConfig->i32blockSize = 1024;
544        break;
545    default:
546        BDBG_MSG(("Incorrect value for TruVolume Blocksize. Possible values are 256, 512, 768, 1024"));
547        break;
548    }
549    BDBG_MSG(("BlockSize now %u", pUserConfig->i32blockSize));
550    BDBG_MSG(("i32EnableDCNotchFilter was %u", pUserConfig->i32EnableDCNotchFilter));
551    pUserConfig->i32EnableDCNotchFilter = pSettings->enableDcNotchFilter?1:0;
552    BDBG_MSG(("i32EnableDCNotchFilter now %u", pUserConfig->i32EnableDCNotchFilter));
553    BDBG_MSG(("i32mBypassGain was %u", pUserConfig->i32mBypassGain));
554    pUserConfig->i32mBypassGain = BAPE_P_FloatToQ923(pSettings->bypassGain, 100);
555    BDBG_MSG(("i32mBypassGain now %u", pUserConfig->i32mBypassGain));
556    BDBG_MSG(("i32mCalibrate was %u", pUserConfig->i32mCalibrate));
557    pUserConfig->i32mCalibrate = BAPE_P_FloatToQ815(pSettings->calibrate, 25600);
558    BDBG_MSG(("i32mCalibrate now %u", pUserConfig->i32mCalibrate));
559    BDBG_MSG(("i32mEnable was %u", pUserConfig->i32mEnable));
560    pUserConfig->i32mEnable = pSettings->enableNormalGain?1:0;
561    BDBG_MSG(("i32mEnable now %u", pUserConfig->i32mEnable));
562    BDBG_MSG(("i32mInputGain was %u", pUserConfig->i32mInputGain));
563    pUserConfig->i32mInputGain = BAPE_P_FloatToQ518(pSettings->inputGain, 3200);
564    BDBG_MSG(("i32mInputGain now %u", pUserConfig->i32mInputGain));
565    BDBG_MSG(("i32mMaxGain was %u", pUserConfig->i32mMaxGain));
566    pUserConfig->i32mMaxGain = BAPE_P_FloatToQ923(pSettings->maxGain, 1024); /* Verify. RAP uses 1024, its 100 in APE. Which one is correct?? */
567    BDBG_MSG(("i32mMaxGain now %u", pUserConfig->i32mMaxGain));
568    BDBG_MSG(("i32mMode was %u", pUserConfig->i32mMode));
569    switch (pSettings->mode)
570    {
571    case BAPE_TruVolumeMode_eLight:
572        pUserConfig->i32mMode = 0;
573        break;
574    case BAPE_TruVolumeMode_eNormal:
575        pUserConfig->i32mMode = 1;
576        break;
577    case BAPE_TruVolumeMode_eHeavy:
578        pUserConfig->i32mMode = 2;
579        break;
580    default:
581        BDBG_WRN(("Incorrect value for TruVolume Mode. Possible values are 0, 1, 2"));
582        break;
583    }
584    BDBG_MSG(("i32mMode now %u", pUserConfig->i32mMode));
585    BDBG_MSG(("i32mNoiseManager was %u", pUserConfig->i32mNoiseManager));
586    pUserConfig->i32mNoiseManager = pSettings->enableNoiseManager?1:0;
587    BDBG_MSG(("i32mNoiseManager now %u", pUserConfig->i32mNoiseManager));
588    BDBG_MSG(("i32mNoiseManagerThreshold was %u", pUserConfig->i32mNoiseManagerThreshold));
589    pUserConfig->i32mNoiseManagerThreshold = BAPE_P_FloatToQ923(pSettings->noiseManagerThreshold, 200);;
590    BDBG_MSG(("i32mNoiseManagerThreshold now %u", pUserConfig->i32mNoiseManagerThreshold));
591    BDBG_MSG(("i32mNormalizerEnable was %u", pUserConfig->i32mNormalizerEnable));
592    pUserConfig->i32mNormalizerEnable = pSettings->enableNormalizer?1:0;
593    BDBG_MSG(("i32mNormalizerEnable now %u", pUserConfig->i32mNormalizerEnable));
594    BDBG_MSG(("i32mOutputGain was %u", pUserConfig->i32mOutputGain));
595    pUserConfig->i32mOutputGain = BAPE_P_FloatToQ518(pSettings->outputGain, 3200);
596    BDBG_MSG(("i32mOutputGain now %u", pUserConfig->i32mOutputGain));
597    BDBG_MSG(("i32mReferenceLevel was %u", pUserConfig->i32mReferenceLevel));
598    pUserConfig->i32mReferenceLevel = pSettings->referenceLevel;
599    BDBG_MSG(("i32mReferenceLevel now %u", pUserConfig->i32mReferenceLevel));
600    BDBG_MSG(("i32mSize was %u", pUserConfig->i32mSize));
601    switch (pSettings->speakerResolution)
602    {
603    case BAPE_TruVolumeSpeakerResolution_e20Hz:
604        pUserConfig->i32mSize = 0;
605        break;
606    case BAPE_TruVolumeSpeakerResolution_e40Hz:
607        pUserConfig->i32mSize = 1;
608        break;
609    case BAPE_TruVolumeSpeakerResolution_e110Hz:
610        pUserConfig->i32mSize = 2;
611        break;
612    case BAPE_TruVolumeSpeakerResolution_e200Hz:
613        pUserConfig->i32mSize = 3;
614        break;
615    case BAPE_TruVolumeSpeakerResolution_e315Hz:
616        pUserConfig->i32mSize = 4;
617        break;
618    case BAPE_TruVolumeSpeakerResolution_e410Hz:
619        pUserConfig->i32mSize = 5;
620        break;
621    default:
622        BDBG_WRN(("Incorrect value for TruVolume Resolution. Possible values are 0, 1, 2, 3, 4, 5"));
623        break;
624    }
625    BDBG_MSG(("i32mSize now %u", pUserConfig->i32mSize));
626    BDBG_MSG(("i32nchans was %u", pUserConfig->i32nchans));
627    pUserConfig->i32nchans = 2;
628    BDBG_MSG(("i32nchans now %u", pUserConfig->i32nchans));
629    BDBG_MSG(("i32TruVolume_enable was %u", pUserConfig->i32TruVolume_enable));
630    pUserConfig->i32TruVolume_enable = pSettings->enabled?1:0;
631    BDBG_MSG(("i32TruVolume_enable now %u", pUserConfig->i32TruVolume_enable));
632
633    /* Top-level HPF settings */
634    pUserConfig->sHighPassFilterConfig.ui32mEnable = (pSettings->highPassFilter.enabled)?true:false;
635    switch ( pSettings->highPassFilter.coefficientMode )
636    {
637    default:
638        BDBG_WRN(("Unrecognized filter coefficient gen mode in truvolume settings."));
639        /* fall through */
640    case BAPE_SrsFilterCoefficientMode_eUser:
641        pUserConfig->sHighPassFilterConfig.ui32CoefGenMode = 0;
642        break;
643    case BAPE_SrsFilterCoefficientMode_eSpecification:
644        pUserConfig->sHighPassFilterConfig.ui32CoefGenMode = 1;
645        break;
646    }
647
648    /* User Coefs */
649    BDBG_CASSERT((sizeof(pUserConfig->sHighPassFilterConfig.sFilterCoefHpf)/sizeof(BDSP_Raaga_FilterCoefHpf)) == 3);
650    for ( i = 0; i < 3; i++ )
651    {
652        pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].ui32Order = pSettings->highPassFilter.coefficientSettings.user[i].filterOrder;
653        BDBG_CASSERT((sizeof(pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[0].sFilterCoefHpfTdf2)/sizeof(BDSP_Raaga_FilterCoefHpfTdf2)) == 3);
654        for ( j = 0; j < 3; j++ )
655        {
656            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32Scale = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].scale;
657            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB0 = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB0;
658            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB1 = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB1;
659            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB2 = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientB2;
660            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientB1 = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientA1;
661            pUserConfig->sHighPassFilterConfig.sFilterCoefHpf[i].sFilterCoefHpfTdf2[j].i32FilterCoefficientA2 = pSettings->highPassFilter.coefficientSettings.user[i].coefficients[j].coefficientA2;
662        }
663    }
664
665    /* Specification */
666    pUserConfig->sHighPassFilterConfig.sFilterSpecHpf.ui32CutoffFrequency = pSettings->highPassFilter.coefficientSettings.specification.cutoffFrequency;
667    pUserConfig->sHighPassFilterConfig.sFilterSpecHpf.ui32Order = pSettings->highPassFilter.coefficientSettings.specification.filterOrder;
668   
669    return BERR_SUCCESS;   
670}
671
672static BERR_Code BAPE_TruVolume_P_ApplyTruVolumeSettings(BAPE_TruVolumeHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId)
673{
674    BERR_Code errCode;
675    BDSP_Raaga_Audio_TruVolumeUserConfig userConfig;
676
677    errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig));
678    if ( errCode )
679    {
680        return BERR_TRACE(errCode);
681    }
682
683    userConfig.sTopLevelConfig.i32mEnable = false;  /* Disable studio sound */
684    errCode = BAPE_TruVolume_P_ConvertSettingsToDsp(&handle->settings, &userConfig);
685    if ( errCode )
686    {
687        return BERR_TRACE(errCode);
688    }
689
690    errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig));
691    if ( errCode )
692    {
693        return BERR_TRACE(errCode);
694    }
695
696    return BERR_SUCCESS;
697}
698
699static void BAPE_TruVolume_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
700{
701    /* Invalidate task handle */
702    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
703    BSTD_UNUSED(pConnection);
704    pNode->paths[0].connector.task = NULL;
705}
706
707static void BAPE_TruVolume_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector)
708{
709    (void)BAPE_TruVolume_RemoveInput(pNode->pHandle, pConnector);
710}
711
712
Note: See TracBrowser for help on using the repository browser.