source: svn/newcon3bcm2_21bu/magnum/portinginterface/ape/7552/bape_rf_encoder.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: 25.3 KB
Line 
1/***************************************************************************
2*     (c)2004-2010 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_rf_encoder.c $
39* $brcm_Revision: Hydra_Software_Devel/3 $
40* $brcm_Date: 8/29/11 4:24p $
41*
42* API Description:
43*   API name: RfEncoder
44*    Specific APIs related to RF Audio Encoding
45*
46* Revision History:
47*
48* $brcm_Log: /magnum/portinginterface/ape/7422/bape_rf_encoder.c $
49*
50* Hydra_Software_Devel/3   8/29/11 4:24p jgarrett
51* SW7425-724: Changing SFIFO configuration to mono 32-bit instead of
52* stereo 16-bit
53*
54* Hydra_Software_Devel/2   8/26/11 11:41a jgarrett
55* SW7425-742: Incorporating API review feedback
56*
57* Hydra_Software_Devel/1   8/24/11 11:53a jgarrett
58* SW7425-724: Adding RF Audio Encoder
59*
60***************************************************************************/
61
62#include "bape.h"
63#include "bape_priv.h"
64#include "bdsp_raaga.h"
65
66BDBG_MODULE(bape_rf_encoder);
67
68BDBG_OBJECT_ID(BAPE_RfEncoder);
69typedef struct BAPE_RfEncoder
70{
71    BDBG_OBJECT(BAPE_RfEncoder)
72    BAPE_PathNode node;   
73    BAPE_RfEncoderSettings  settings;
74    BAPE_BtscEncodeSettings btscSettings;
75    BAPE_Connector input;
76} BAPE_RfEncoder;
77
78static const char *BAPE_RfEncoder_P_GetName(BAPE_RfAudioEncoding encoding);
79static BDSP_AudioProcessing BAPE_RfEncoder_P_GetType(BAPE_RfAudioEncoding encoding);
80static BERR_Code BAPE_RfEncoder_P_ApplyDspSettings(BAPE_RfEncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId);
81static BERR_Code BAPE_RfEncoder_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector);
82static BERR_Code BAPE_RfEncoder_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
83static BERR_Code BAPE_RfEncoder_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
84static void BAPE_RfEncoder_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
85static void BAPE_RfEncoder_P_GetDefaultEncodingSettings(BAPE_RfEncoderHandle handle);
86static void BAPE_RfEncoder_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector);
87static void BAPE_RfEncoder_P_InputSampleRateChange_isr(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection);
88static BERR_Code BAPE_RfEncoder_P_ConfigPathToOutput(BAPE_PathNode *pNode, BAPE_PathConnection *pConnection);
89
90/***************************************************************************
91Summary:
92    Get default settings for an Audio Encoder stage
93***************************************************************************/
94void BAPE_RfEncoder_GetDefaultSettings(
95    BAPE_RfEncoderSettings *pSettings   /* [out] default settings */
96    )
97{
98    BDBG_ASSERT(NULL != pSettings);
99    pSettings->encoding = BAPE_RfAudioEncoding_eBtsc;
100}
101
102/***************************************************************************
103Summary:
104    Open an Audio Encoder stage
105***************************************************************************/
106BERR_Code BAPE_RfEncoder_Create(
107    BAPE_Handle deviceHandle,
108    const BAPE_RfEncoderSettings *pSettings,
109    BAPE_RfEncoderHandle *pHandle             /* [out] */
110    )
111{
112    BAPE_RfEncoderHandle handle;
113
114    BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device);
115    BDBG_ASSERT(NULL != pSettings);
116    BDBG_ASSERT(NULL != pHandle);
117
118    handle = BKNI_Malloc(sizeof(BAPE_RfEncoder));
119    if ( NULL == handle )
120    {
121        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
122    }
123    BKNI_Memset(handle, 0, sizeof(BAPE_RfEncoder));
124    BDBG_OBJECT_SET(handle, BAPE_RfEncoder);
125    BAPE_P_InitPathNode(&handle->node, BAPE_PathNodeType_eRfEncoder, pSettings->encoding, 1, deviceHandle, handle);
126    handle->node.pName = BAPE_RfEncoder_P_GetName(pSettings->encoding);
127    handle->node.paths[0].connector.numChannelPairs = 1;
128    handle->node.paths[0].connector.useBufferPool = true;   
129    handle->node.paths[0].connector.compressed = true;   
130    handle->node.paths[0].connector.dataSource = BAPE_DataSource_eDspBuffer;   
131    handle->node.paths[0].connector.codec = BAVC_AudioCompressionStd_eMax;      /* Not a BAVC_AudioCompressionStd */
132
133    /* Generic Routines */
134    handle->node.allocatePathToOutput = BAPE_DSP_P_AllocatePathToOutput;
135    handle->node.configPathToOutput = BAPE_RfEncoder_P_ConfigPathToOutput;
136    handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput;
137    handle->node.startPathToOutput = BAPE_DSP_P_StartPathToOutput;
138    handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput;
139
140    /* RF Encoder Specifics */
141    handle->node.connectorSupported = BAPE_RfEncoder_P_ConnectorSupported;
142    handle->node.allocatePathFromInput = BAPE_RfEncoder_P_AllocatePathFromInput;
143    handle->node.configPathFromInput = BAPE_RfEncoder_P_ConfigPathFromInput;
144    handle->node.stopPathFromInput = BAPE_RfEncoder_P_StopPathFromInput;
145    handle->node.removeInput = BAPE_RfEncoder_P_RemoveInputCallback;
146    handle->node.inputSampleRateChange_isr = BAPE_RfEncoder_P_InputSampleRateChange_isr;
147
148    /* Init encoding settings */
149    BKNI_Memcpy(&handle->settings, pSettings, sizeof(BAPE_RfEncoderSettings));
150    BAPE_RfEncoder_P_GetDefaultEncodingSettings(handle);
151
152    *pHandle = handle;
153    return BERR_SUCCESS;
154}
155
156/***************************************************************************
157Summary:
158    Close an RF Audio Encoder stage
159   
160Description:
161    Input to the stage must be removed prior to closing.
162***************************************************************************/
163void BAPE_RfEncoder_Destroy(
164    BAPE_RfEncoderHandle handle
165    )
166{
167    bool running;
168    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
169    running = (handle->node.paths[0].connector.task != NULL)?true:false;
170    BDBG_ASSERT(false == running);
171    BDBG_ASSERT(NULL == handle->input);
172    BDBG_OBJECT_DESTROY(handle, BAPE_RfEncoder);
173    BKNI_Free(handle);
174}
175
176
177/***************************************************************************
178Summary:
179    Get Settings for an Audio Encoder stage
180***************************************************************************/
181void BAPE_RfEncoder_GetSettings(
182    BAPE_RfEncoderHandle handle,
183    BAPE_RfEncoderSettings *pSettings    /* [out] Settings */
184    )
185{
186    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
187    BDBG_ASSERT(NULL != pSettings);
188    *pSettings = handle->settings;
189}
190
191
192/***************************************************************************
193Summary:
194    Set Settings for an Audio Encoder stage
195***************************************************************************/
196BERR_Code BAPE_RfEncoder_SetSettings(
197    BAPE_RfEncoderHandle handle,
198    const BAPE_RfEncoderSettings *pSettings
199    )
200{
201    bool running;
202    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
203    BDBG_ASSERT(NULL != pSettings);
204    running = (handle->node.paths[0].connector.task != NULL)?true:false;
205    if ( running && pSettings->encoding != handle->settings.encoding )
206    {
207        BDBG_ERR(("Can not change encoding while running."));
208        return BERR_TRACE(BERR_NOT_SUPPORTED);
209    }
210    handle->settings = *pSettings;
211    handle->node.subtype = pSettings->encoding;
212    return BERR_SUCCESS;
213}
214
215/***************************************************************************
216Summary:
217    Get Encoding-Specific Settings for an Audio Encoder stage
218***************************************************************************/
219void BAPE_RfEncoder_GetEncodingSettings(
220    BAPE_RfEncoderHandle handle,
221    BAPE_RfAudioEncoding encoding,               /* The encoding for which you are retrieving settings. */
222    BAPE_RfEncoderEncodingSettings *pSettings    /* [out] Settings */
223    )
224{
225    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
226    BDBG_ASSERT(NULL != pSettings);
227   
228    pSettings->encoding = encoding;
229    switch ( encoding )
230    {
231    case BAPE_RfAudioEncoding_eBtsc:
232        pSettings->encodingSettings.btsc = handle->btscSettings;
233        break;
234    default:
235        break;
236    }
237}
238
239/***************************************************************************
240Summary:
241    Set Encoding-Specific Settings for an Audio Encoder stage
242***************************************************************************/
243BERR_Code BAPE_RfEncoder_SetEncodingSettings(
244    BAPE_RfEncoderHandle handle,
245    const BAPE_RfEncoderEncodingSettings *pSettings
246    )
247{
248    bool running, encodingsEqual = false;
249    BERR_Code errCode;
250    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
251    BDBG_ASSERT(NULL != pSettings);
252    running = (handle->node.paths[0].connector.task != NULL)?true:false;
253
254    if ( pSettings->encoding == handle->settings.encoding )
255    {
256        encodingsEqual = true;
257    }
258    switch ( pSettings->encoding )
259    {
260    case BAPE_RfAudioEncoding_eBtsc:
261        handle->btscSettings = pSettings->encodingSettings.btsc;
262        break;
263    default:
264        BDBG_ERR(("Unsupported RF audio encoding %u", pSettings->encoding));
265        return BERR_TRACE(BERR_NOT_SUPPORTED);
266        break;
267    }
268
269    if ( running && encodingsEqual )
270    {
271        errCode = BAPE_RfEncoder_P_ApplyDspSettings(handle, 
272                                                  handle->node.paths[0].connector.task, 
273                                                  handle->node.paths[0].connector.branchId, 
274                                                  handle->node.paths[0].connector.stageId);
275        if ( errCode )
276        {
277            return BERR_TRACE(errCode);
278        }
279    }
280
281    return BERR_SUCCESS;
282}
283
284/***************************************************************************
285Summary:
286    Get the audio connector for an Audio Encoder stage
287***************************************************************************/
288void BAPE_RfEncoder_GetConnector(
289    BAPE_RfEncoderHandle handle,
290    BAPE_Connector *pConnector   /* [out] */
291    )
292{
293    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
294    BDBG_ASSERT(NULL != pConnector);
295    *pConnector = &handle->node.paths[0].connector;
296}
297
298/***************************************************************************
299Summary:
300Add an input to this processing stage
301***************************************************************************/
302BERR_Code BAPE_RfEncoder_AddInput(
303    BAPE_RfEncoderHandle handle,
304    BAPE_Connector input
305    )
306{
307    BERR_Code errCode;
308    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
309    BDBG_OBJECT_ASSERT(input, BAPE_PathConnector);
310    if ( NULL != handle->input )
311    {
312        BDBG_ERR(("Can not have more than one input"));
313        return BERR_TRACE(BERR_NOT_SUPPORTED);
314    }
315    errCode = BAPE_PathNode_P_AddInput(&handle->node, input);
316    if ( errCode )
317    {
318        return BERR_TRACE(errCode);
319    }
320    handle->input = input;
321    return BERR_SUCCESS;
322}
323
324/***************************************************************************
325Summary:
326Remove an input from this processing stage
327***************************************************************************/
328BERR_Code BAPE_RfEncoder_RemoveInput(
329    BAPE_RfEncoderHandle handle,
330    BAPE_Connector input
331    )
332{
333    BERR_Code errCode;
334    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
335    BDBG_OBJECT_ASSERT(input, BAPE_PathConnector);
336    if ( input != handle->input )
337    {
338        BDBG_ERR(("Input %s %s (%#x) is not connected", input->pParent->pName, input->pName, input));
339        return BERR_TRACE(BERR_INVALID_PARAMETER);
340    }
341    errCode = BAPE_PathNode_P_RemoveInput(&handle->node, input);
342    if ( errCode )
343    {
344        return BERR_TRACE(errCode);
345    }
346    handle->input = NULL;
347    return BERR_SUCCESS;
348}
349
350/***************************************************************************
351Summary:
352Remove all inputs from this processing stage
353***************************************************************************/
354BERR_Code BAPE_RfEncoder_RemoveAllInputs(
355    BAPE_RfEncoderHandle handle
356    )
357{
358    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
359    if ( handle->input )
360    {
361        return BAPE_RfEncoder_RemoveInput(handle, handle->input);
362    }
363    return BERR_SUCCESS;
364}
365
366static const char *BAPE_RfEncoder_P_GetName(BAPE_RfAudioEncoding encoding)
367{
368    switch ( encoding )
369    {
370    case BAPE_RfAudioEncoding_eBtsc:
371        return "BTSC";
372    default:
373        return "Unknown";
374    }
375}
376
377static BDSP_AudioProcessing BAPE_RfEncoder_P_GetType(BAPE_RfAudioEncoding encoding)
378{
379    switch ( encoding )
380    {
381    case BAPE_RfAudioEncoding_eBtsc:
382        return BDSP_AudioProcessing_eBtscEncoder;
383    default:
384        return BDSP_AudioProcessing_eMax;
385    }
386}
387
388static BERR_Code BAPE_RfEncoder_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector)
389{
390    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
391    BDBG_OBJECT_ASSERT(pConnector, BAPE_PathConnector);
392    /* Only stereo DSP input is supported */
393    if ( pConnector->dataSource == BAPE_DataSource_eDspBuffer &&
394         pConnector->numChannelPairs == 1 &&
395         !pConnector->compressed )
396    {
397        return BERR_SUCCESS;
398    }
399    else
400    {
401        BDBG_ERR(("Only Stereo PCM DSP input is supported"));
402        return BERR_TRACE(BERR_INVALID_PARAMETER);
403    }
404}
405
406static BERR_Code BAPE_RfEncoder_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
407{
408    BERR_Code errCode;
409    BAPE_RfEncoderHandle handle;
410    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
411    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
412    BDBG_ASSERT(NULL != pConnection->pSource->pTaskCreateSettings);
413    handle = pNode->pHandle;
414    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
415
416    /* Add stage to CIT and propagate task settings */
417    errCode = BAPE_DSP_P_AddProcessingStage(pConnection->pSource->pTaskCreateSettings, pConnection->pSource->branchId, pConnection->pSource->stageId, 
418                                            BAPE_DSP_P_GetDataTypeFromConnector(handle->input),
419                                            BAPE_RfEncoder_P_GetType(handle->settings.encoding),
420                                            false,
421                                            &pNode->paths[0].connector.branchId, &pNode->paths[0].connector.stageId);
422    if ( errCode )
423    {
424        return BERR_TRACE(errCode);
425    }
426    pNode->paths[0].connector.pTaskCreateSettings = pConnection->pSource->pTaskCreateSettings;
427    return BERR_SUCCESS;
428}
429
430static BERR_Code BAPE_RfEncoder_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
431{
432    BERR_Code errCode;
433    BAPE_RfEncoderHandle handle;
434    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
435    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
436    BDBG_ASSERT(NULL != pConnection->pSource->task);
437    handle = pNode->pHandle;
438    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
439    pNode->paths[0].connector.task = pConnection->pSource->task;
440    errCode = BAPE_RfEncoder_P_ApplyDspSettings(handle, 
441                                                handle->node.paths[0].connector.task, 
442                                                handle->node.paths[0].connector.branchId, 
443                                                handle->node.paths[0].connector.stageId);
444    if ( errCode )
445    {
446        return BERR_TRACE(errCode);
447    }
448    return BERR_SUCCESS;   
449}
450
451static void BAPE_RfEncoder_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
452{
453    /* Invalidate task handle */
454    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
455    BSTD_UNUSED(pConnection);
456    pNode->paths[0].connector.task = NULL;
457}
458
459static BERR_Code BAPE_RfEncoder_P_ApplyBtscSettings(BAPE_RfEncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId)
460{
461    BERR_Code errCode;
462    BDSP_Raaga_BtscEncoderSettings userConfig;
463
464    errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig));
465    if ( errCode )
466    {
467        return BERR_TRACE(errCode);
468    }
469
470    BAPE_DSP_P_SET_VARIABLE(userConfig, eUseDeEmphasizedSourceSignals, handle->btscSettings.useDeEmphasizedSourceSignals ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
471    BAPE_DSP_P_SET_VARIABLE(userConfig, eEquivalenMode75MicroSec, handle->btscSettings.equivalentMode75us ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
472    BAPE_DSP_P_SET_VARIABLE(userConfig, eOpFreqDevCtrl, handle->btscSettings.fmDeviationControl ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
473
474    BAPE_DSP_P_SET_VARIABLE(userConfig, ui32AttenuationFactor, BAPE_P_FloatToQ131(handle->btscSettings.volume, BAPE_VOLUME_NORMAL));
475    BAPE_DSP_P_SET_VARIABLE(userConfig, ui32SRDCalibrationFactor, handle->btscSettings.srdCalibrationFactor);
476   
477    BAPE_DSP_P_SET_VARIABLE(userConfig, eMainChannelPreEmphasisOn, handle->btscSettings.mainChannel.preemphasis ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
478    BAPE_DSP_P_SET_VARIABLE(userConfig, eMainChannelPreEmphasisOn, handle->btscSettings.mainChannel.fmDeviationControl ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
479
480    BAPE_DSP_P_SET_VARIABLE(userConfig, eClipDiffChannelData, handle->btscSettings.diffChannel.clipping ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
481    BAPE_DSP_P_SET_VARIABLE(userConfig, eDiffChannelPreEmphasisOn, handle->btscSettings.diffChannel.preemphasis ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
482    BAPE_DSP_P_SET_VARIABLE(userConfig, eDiffChanFreqDevCtrl, handle->btscSettings.diffChannel.fmDeviationControl ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
483
484    BAPE_DSP_P_SET_VARIABLE(userConfig, eFreqGeneration, handle->btscSettings.testTone.enabled ? BDSP_AF_P_eEnable : BDSP_AF_P_eDisable);
485    BAPE_DSP_P_SET_VARIABLE(userConfig, i32Frequency, handle->btscSettings.testTone.frequency);
486   
487    errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig));
488    if ( errCode )
489    {
490        return BERR_TRACE(errCode);
491    }
492
493    return BERR_SUCCESS;
494}
495
496static void BAPE_RfEncoder_P_GetDefaultBtscSettings(BAPE_RfEncoderHandle handle)
497{
498    BDSP_Raaga_BtscEncoderSettings userConfig;
499
500    BERR_TRACE(BDSP_Raaga_GetDefaultAudioProcessingSettings(BDSP_AudioProcessing_eBtscEncoder, &userConfig, sizeof(userConfig)));
501   
502    handle->btscSettings.useDeEmphasizedSourceSignals = (userConfig.eUseDeEmphasizedSourceSignals == BDSP_AF_P_eEnable) ? true : false;
503    handle->btscSettings.equivalentMode75us = (userConfig.eEquivalenMode75MicroSec == BDSP_AF_P_eEnable) ? true : false;
504    handle->btscSettings.fmDeviationControl = (userConfig.eOpFreqDevCtrl == BDSP_AF_P_eEnable) ? true : false;
505   
506    handle->btscSettings.volume = BAPE_VOLUME_NORMAL;
507    BDBG_ASSERT(userConfig.ui32AttenuationFactor == 0x7fffffff);
508    handle->btscSettings.srdCalibrationFactor = userConfig.ui32SRDCalibrationFactor;
509   
510    handle->btscSettings.mainChannel.preemphasis = (userConfig.eMainChannelPreEmphasisOn == BDSP_AF_P_eEnable) ? true : false;
511    handle->btscSettings.mainChannel.fmDeviationControl = (userConfig.eSumChanFreqDevCtrl == BDSP_AF_P_eEnable) ? true : false;
512
513    handle->btscSettings.diffChannel.clipping = (userConfig.eClipDiffChannelData == BDSP_AF_P_eEnable) ? true : false;
514    handle->btscSettings.diffChannel.preemphasis = (userConfig.eDiffChannelPreEmphasisOn == BDSP_AF_P_eEnable) ? true : false;
515    handle->btscSettings.diffChannel.fmDeviationControl = (userConfig.eDiffChanFreqDevCtrl == BDSP_AF_P_eEnable) ? true : false;
516   
517    handle->btscSettings.testTone.enabled = (userConfig.eFreqGeneration == BDSP_AF_P_eEnable) ? true : false;
518    handle->btscSettings.testTone.frequency = (unsigned)userConfig.i32Frequency;
519}
520
521static BERR_Code BAPE_RfEncoder_P_ApplyDspSettings(BAPE_RfEncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId)
522{
523    BDSP_AudioProcessing encodeType;
524    BDBG_OBJECT_ASSERT(handle, BAPE_RfEncoder);
525    BDBG_ASSERT(NULL != task);
526    encodeType = BAPE_RfEncoder_P_GetType(handle->settings.encoding);
527    switch ( encodeType )
528    {
529    case BDSP_AudioProcessing_eBtscEncoder:
530        return BAPE_RfEncoder_P_ApplyBtscSettings(handle, task, branchId, stageId);
531    default:
532        return BERR_SUCCESS;
533    }
534}
535
536static void BAPE_RfEncoder_P_GetDefaultEncodingSettings(BAPE_RfEncoderHandle handle)
537{
538    BAPE_RfEncoder_P_GetDefaultBtscSettings(handle);
539}
540
541static void BAPE_RfEncoder_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector)
542{
543    (void)BAPE_RfEncoder_RemoveInput(pNode->pHandle, pConnector);
544}
545
546static void BAPE_RfEncoder_P_InputSampleRateChange_isr(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection)
547{
548    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
549    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
550       
551    BDBG_MSG(("Input sample rate changed to %u Hz.  Output rate is %u Hz.", pConnection->pSource->sampleRate, 4*pConnection->pSource->sampleRate));
552
553    pNode->paths[0].connector.sampleRate = 4*pConnection->pSource->sampleRate;
554    BAPE_Connector_P_SampleRateChange_isr(&pNode->paths[0].connector);   
555}
556
557static BERR_Code BAPE_RfEncoder_P_ConfigPathToOutput(
558    BAPE_PathNode *pNode,
559    BAPE_PathConnection *pConnection
560    )
561{
562    BAPE_PathConnector *pSource;
563    BAPE_Handle deviceHandle;
564    BAPE_PathNode *pSink;
565    BERR_Code errCode;
566    unsigned i;
567
568    BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode);
569    BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection);
570    BDBG_OBJECT_ASSERT(pConnection->pSource, BAPE_PathConnector);
571    BDBG_OBJECT_ASSERT(pConnection->pSink, BAPE_PathNode);
572
573    deviceHandle = pNode->deviceHandle;
574    pSource = pConnection->pSource;
575    pSink = pConnection->pSink;
576
577    if ( pSink->type == BAPE_PathNodeType_eMixer && pSink->subtype == BAPE_MixerType_eDsp )
578    {
579        BDBG_ERR(("RF Encoder can not be connected to a DSP mixer."));
580        return BERR_TRACE(BERR_NOT_SUPPORTED);
581    }
582    else if ( pSink->type == BAPE_PathNodeType_eEqualizer )
583    {
584        BDBG_ERR(("RF Encoder can not be connected to an equalizer."));
585        return BERR_TRACE(BERR_NOT_SUPPORTED);
586    }
587    else if ( pSink->type == BAPE_PathNodeType_eMixer )
588    {
589        BAPE_SfifoGroupSettings sfifoSettings;
590        /* Dropping into the FMM - need to config SFIFO's.  DSP does not use master/slave, it will instead reuse ringbuffers in multiple
591           master SFIFOs */
592        BAPE_SfifoGroup_P_GetSettings(pConnection->sfifoGroup, &sfifoSettings);
593        sfifoSettings.highPriority = false; /* TODO: How to handle this on the fly? */
594        sfifoSettings.reverseEndian = false;
595        sfifoSettings.signedData = true;
596        sfifoSettings.wrpointEnabled = true;
597        sfifoSettings.stereoData = false;       /* RF Encoded data is output as mono to the SFIFO and not stereo */
598        sfifoSettings.sampleRepeatEnabled = false;
599        sfifoSettings.interleaveData = true;
600        sfifoSettings.dataWidth = 32;
601        /* Setup buffers from pool */
602        for ( i = 0; i < pSource->numChannelPairs; i++ )
603        {
604            unsigned bufferId = 2*i;
605            BAPE_BufferNode *pBuffer = pSource->pBuffers[i];
606            BDBG_ASSERT(NULL != pBuffer);
607            sfifoSettings.bufferInfo[bufferId].base = pBuffer->offset;
608            sfifoSettings.bufferInfo[bufferId].length = pBuffer->bufferSize;
609            sfifoSettings.bufferInfo[bufferId].wrpoint = pBuffer->offset+pBuffer->bufferSize-1;
610            bufferId++;
611            sfifoSettings.bufferInfo[bufferId].base = 0;
612            sfifoSettings.bufferInfo[bufferId].length = 0;
613            sfifoSettings.bufferInfo[bufferId].wrpoint = 0;
614        }
615
616        errCode = BAPE_SfifoGroup_P_SetSettings(pConnection->sfifoGroup, &sfifoSettings);
617        if ( errCode )
618        {
619            return BERR_TRACE(errCode);
620        }
621    }
622
623    return BERR_SUCCESS;
624}
Note: See TracBrowser for help on using the repository browser.