aud.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:14k
- /*****************************************************************************
- File name: aud.c
- Description: Audio setup and starting
- COPYRIGHT (C) 2004 STMicroelectronics
- *****************************************************************************/
- /* Includes --------------------------------------------------------------- */
- #include <string.h>
- #include "stlite.h"
- #include "stdevice.h"
- #include "stsys.h"
- #include "sttbx.h"
- #include "section.h" /* memory partitions */
- #include "errors.h"
- #include "evt.h"
- #include "avmem.h"
- #include "clkrv.h"
- #include "aud.h"
- #include "stpti_hal.h"
- #include "avslot.h"
- /* Private Types ------------------------------------------------------ */
- /* Private Constants -------------------------------------------------- */
- /* Private Variables -------------------------------------------------- */
- /* Private Macros ----------------------------------------------------- */
- #define AUDIO_DEFAULT_PTI_INSTANCE 0
- /* Private Function prototypes ---------------------------------------- */
- /* Global Variables --------------------------------------------------- */
- STAUD_Handle_t AUD_Handle;
- ST_DeviceName_t AUD_DeviceName="AUDIO";
- /* Functions ---------------------------------------------------------- */
- /* Functions ---------------------------------------------------------- */
- /* INTERFACE OBJECT: WRAPPER FCT TO LINK PTI AND VIDEO */
- /*-------------------------------------------------------------------------
- * Function: AUD_GetPESBuffWritePtr
- * Decription: Gets the PES Buffer Write Pointer from PTI
- * Input : PTI Buffer Handle
- * Output :
- * Return : Error code and the Audio Input Buffer Address
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t AUD_GetPESBuffWritePtr(void * const Handle_p, void ** const Address_p)
- {
- ST_ErrorCode_t Err;
- /* just cast the handle */
- Err = STPTI_BufferGetWritePointer((STPTI_Buffer_t)Handle_p,Address_p);
- return(Err);
- }
- /*-------------------------------------------------------------------------
- * Function: AUD_SetPESBuffReadPtrFct
- * Decription: Sets the PTI Read Pointer.
- * Input : PTI Buffer Handle and the Audio Buffer Address
- * Output :
- * Return : Error code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t AUD_SetPESBuffReadPtrFct(void * const Handle_p, void * const Address_p)
- {
- ST_ErrorCode_t Err;
- /* just cast the handle */
- Err = STPTI_BufferSetReadPointer((STPTI_Buffer_t)Handle_p,Address_p);
- if ( Err != ST_NO_ERROR )
- {
- STTBX_Print(( "PTI_BufferSetReadPointer()Failed %sn", KB_ErrorGetText(Err)));
- }
- return(Err);
- }
- /*-------------------------------------------------------------------------
- * Function : AUD_Setup
- * Initialise Audio
- * Input : service mode
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t AUD_Setup(KB_ServiceMode SERVICE_Mode)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STAUD_InitParams_t STAUD_InitParams;
- STAUD_OpenParams_t STAUD_OpenParams;
- STAUD_BroadcastProfile_t STAUD_BroadcastProfile;
- ST_ErrorCode = KB_ServiceAUDInitPara(SERVICE_Mode, &STAUD_InitParams, &STAUD_BroadcastProfile);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- return( ST_ErrorCode );
- }
- STAUD_InitParams.DeviceType = AUD_DEVICE_TYPE ;
- STAUD_InitParams.InterfaceType = AUD_INTERFACE_TYPE;
- STAUD_InitParams.CDInterfaceType = AUD_CD_INTERFACE_TYPE;
- STAUD_InitParams.CD2InterfaceType = AUD_CD2_INTERFACE_TYPE;
- STAUD_InitParams.CD1BufferAddress_p = NULL;
- STAUD_InitParams.CD1BufferSize = 0;
- STAUD_InitParams.CD2BufferAddress_p = NULL;
- STAUD_InitParams.CD2BufferSize = 0;
- STAUD_InitParams.InternalPLL = TRUE;
- STAUD_InitParams.DACClockToFsRatio = AUD_CLOCKRATIO;
- STAUD_InitParams.PCMOutParams.InvertWordClock = AUD_PCMPARAM_INVWORD;
- STAUD_InitParams.PCMOutParams.Format = AUD_PCMPARAM_FORMAT;
- STAUD_InitParams.PCMOutParams.InvertBitClock = FALSE;
- STAUD_InitParams.PCMOutParams.Precision = AUD_DAC_DATA_PRECISION;
- STAUD_InitParams.PCMOutParams.Alignment = AUD_DAC_DATA_ALIGNMENT;
- STAUD_InitParams.PCMOutParams.MSBFirst = FALSE;
- STAUD_InitParams.MaxOpen = 1;
- STAUD_InitParams.CPUPartition_p = SystemPartition;
- STAUD_InitParams.AVMEMPartition = g_KBAvmemPartitionHandle[0];
- STAUD_InitParams.InterruptNumber = AUDIO_INTERRUPT;
- STAUD_InitParams.InterruptLevel = AUDIO_INTERRUPT_LEVEL;
- STAUD_InitParams.CD1InterruptNumber = AUD_CD1_INTERRUPT_NUMBER;
- STAUD_InitParams.PCMInterruptNumber = AUD_PCM_INTERRUPT_NUMBER;
- STAUD_InitParams.CD1InterruptLevel = AUDIO_INTERRUPT_LEVEL;
- STAUD_InitParams.PCMInterruptLevel = AUDIO_INTERRUPT_LEVEL;
- /* Configure interface to AUDIO registers */
- STAUD_InitParams.InterfaceParams.EMIParams.BaseAddress_p = (void *)AUDIO_BASE_ADDRESS;
- STAUD_InitParams.InterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
- /* Configure interface to ADSC registers */
- STAUD_InitParams.CDInterfaceParams.EMIParams.BaseAddress_p = (void *)AUD_CD_INTERFACE_BASE_ADDRESS;
- STAUD_InitParams.CDInterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
- STAUD_InitParams.CD2InterfaceParams.EMIParams.BaseAddress_p = (void *)AUD_CD2_INTERFACE_BASE_ADDRESS;
- STAUD_InitParams.CD2InterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
- STAUD_InitParams.ClockGeneratorBaseAddress_p = (void *)CKG_BASE_ADDRESS;
- STAUD_InitParams.PCM1QueueSize = AUD_PCM1_QUEUE_SIZE;
- /* For AC3 Support */
- #ifdef AC3_DECODE
- STAUD_InitParams.SPDIFMode = AC3_OVER_SPDIF;
- #else
- STAUD_InitParams.SPDIFMode = PCM_OVER_SPDIF;
- #endif
- STAUD_InitParams.PCMMode = PCM_ON;
- strcpy(STAUD_InitParams.EvtHandlerName, "EVT" );
- strcpy(STAUD_InitParams.ClockRecoveryName, g_KBCLKRVDeviceName );
- STTBX_Print(("AUD_Setup(%s)=", AUD_DeviceName ));
- ST_ErrorCode = STAUD_Init(AUD_DeviceName, &STAUD_InitParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- STTBX_Print(("%sn", STAUD_GetRevision() ));
- STAUD_OpenParams.SyncDelay = 0;
- STTBX_Print(("AUD_Open="));
- ST_ErrorCode = STAUD_Open(AUD_DeviceName,&STAUD_OpenParams, &AUD_Handle);
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- ST_ErrorCode = STAUD_DRSetBroadcastProfile(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, STAUD_BroadcastProfile);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("AUD_DRSetBroadcastProfile=%sn", KB_ErrorGetText(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- #if 0
- STAUD_SpeakerEnable.Left = TRUE;
- STAUD_SpeakerEnable.Right = TRUE;
- STAUD_SpeakerEnable.LeftSurround = AUD_SPKR_LEFTSURROUND;
- STAUD_SpeakerEnable.RightSurround = AUD_SPKR_RIGHTSURROUND;
- STAUD_SpeakerEnable.Center = AUD_SPKR_CENTER;
- STAUD_SpeakerEnable.Subwoofer = AUD_SPKR_SUBWOOFER;
- ST_ErrorCode = STAUD_OPSetSpeakerEnable(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &STAUD_SpeakerEnable);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("AUD_OPSetSpeakerEnable=%sn", KB_ErrorGetText(ST_ErrorCode) ));
- }
- #endif
- #if 0 //TMTM comment off
- /* Link corresponding Audio and PTI */
- STTBX_Print(("AUD_Link(%d)=", AUDIO_DEFAULT_PTI_INSTANCE));
- ST_ErrorCode = AUD_Link( AUDIO_DEFAULT_PTI_INSTANCE );
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
- #else
- /* Link corresponding Audio and PTI */
- STTBX_Print(("AUD_Link(%d)=", AUDIO_DEFAULT_PTI_INSTANCE));
- ST_ErrorCode = PTI_LinkAudio( AUDIO_DEFAULT_PTI_INSTANCE );
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
- #endif
- return( ST_ErrorCode );
- }
- /*-------------------------------------------------------------------------
- * Function : AUD_Link
- * Link the correspoding PTI to Video
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t PTI_LinkAudio (U32 PTIInst)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STAUD_BufferParams_t BufferParams;
- #ifdef AC3_DECODE
- ST_ErrorCode = STAUD_IPGetInputBufferParamsCompressed(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &BufferParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("AUD_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #else
- ST_ErrorCode = STAUD_IPGetInputBufferParams(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &BufferParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("AUD_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #endif
- ST_ErrorCode = STPTI_BufferAllocateManual( g_KB_PTIHandleMultiple[PTIInst],
- BufferParams.BufferBaseAddr_p, BufferParams.BufferSize,
- 1, &PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferAllocateManual=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- /* No cd-fifo: Initialise the link between pti and audio */
- ST_ErrorCode = STPTI_SlotLinkToBuffer(PTI_SlotHandle_Multiple[PTIInst][SLOTAUD], PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_SlotLinkToBuffer=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferSetOverflowControl(PTI_AudioBufferHandle, TRUE);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferSetOverflowControl=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #ifdef AC3_DECODE
- ST_ErrorCode = STAUD_IPSetDataInputInterfaceCompressed(AUD_Handle,
- STAUD_OBJECT_DECODER_COMPRESSED1,
- AUD_GetPESBuffWritePtr,
- AUD_SetPESBuffReadPtrFct,
- (void *)PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("AUD_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #else
- ST_ErrorCode = STAUD_IPSetDataInputInterface(AUD_Handle,
- STAUD_OBJECT_DECODER_COMPRESSED1,
- AUD_GetPESBuffWritePtr,
- AUD_SetPESBuffReadPtrFct,
- (void *)PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("AUD_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #endif
- return (ST_ErrorCode);
- }
- /*-------------------------------------------------------------------------
- * Function : AUD_Unlink
- * Unlink the correspoding PTI to Video
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t PTI_UnlinkAudio(U32 PTIInst)
- {
- ST_ErrorCode_t ST_ErrorCode;
- #if 0
- ST_ErrorCode = STAUD_DeleteDataInputInterface(AUD_Handle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("AUD_DeleteDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- #endif
- ST_ErrorCode = STPTI_BufferFlush(PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferFlush=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_SlotUnLink(PTI_SlotHandle_Multiple[PTIInst][SLOTAUD]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_SlotUnLink=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferDeallocate(PTI_AudioBufferHandle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferDeallocate=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- return (ST_ErrorCode);
- }
- /*-------------------------------------------------------------------------
- * Function : AUD_Start
- * Start Decoding Audio
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t AUD_Start(STAUD_StartParams_t *STAUD_StartParams_p)
- {
- ST_ErrorCode_t ST_ErrorCode;
- ST_ErrorCode = STAUD_Start(AUD_Handle, STAUD_StartParams_p);
- STTBX_Print(("STAUD_Start(%d,%d,%d,%02.2x)=%s",
- STAUD_StartParams_p->StreamContent, STAUD_StartParams_p->StreamType,
- STAUD_StartParams_p->SamplingFrequency, STAUD_StartParams_p->StreamID,
- KB_ErrorGetText(ST_ErrorCode) ));
- return ( ST_ErrorCode );
- }
- //TMTM added
- ST_ErrorCode_t AUD_Term(void)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STAUD_TermParams_t TermParams;
- /*ST_ErrorCode = STAUD_Close(AUD_Handle);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("STAUD_Close()=%s", KB_ErrorGetText(ST_ErrorCode) ));
- }*/
-
- TermParams.ForceTerminate = TRUE;
-
- ST_ErrorCode = STAUD_Term(AUD_DeviceName, &TermParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("STAUD_Term()=%s", KB_ErrorGetText(ST_ErrorCode) ));
- }
-
- return ( ST_ErrorCode );
- }
- /* EOF --------------------------------------------------------------------- */