/**********************************************************************

Copyright(c) Analog Devices, Inc. All Rights Reserved. 

This software is proprietary and confidential.  By using this software 
you agree to the terms of the associated Analog Devices License Agreement.  

$RCSfile: codec_52xc1.h,v $
$Revision: 1.1 $
$Date: 2008/06/06 06:24:56 $

Description:
	
******************************************************************************

Include files

*****************************************************************************/

#ifndef __CODEC_52XC1_H__
#define __CODEC_52XC1_H__

#include <mediaplayer.h>

/*****************************************************************************

Macros to adjust audio volume

****************************************************************************/
#define		VOLUME_STRIDE			0x3
#define		VOLUME_MIN				0x4f
#define		VOLUME_MAX				0x79

/* DMA Bus width (Element width) for SPORT DMA */
#define     DMA_BUS_WIDTH_IN_BYTES      2

/* Number of DAC channels (Front Out Left, Front Out Right) */
/* Stereo mode */
#define		NUM_AUDIO_DAC_CHANNELS			        2

/* Number of ADC channels (Line In Left, Line In Right) */
#define		NUM_AUDIO_ADC_CHANNELS			        2

/* PCM sample resolution = 16 bits (2bytes) */
#define     PCM_SAMPLE_RESOLUTION_IN_BYTES          2

/* Base buffer size per DAC channel */
#define		BUFFER_SIZE_PER_AUDIO_DAC_CHANNEL	    (1024 * 16)	/* 16kB */
/* Base buffer size per ADC channel */
#define		BUFFER_SIZE_PER_AUDIO_ADC_CHANNEL       (1024 * 16)	/* 16kB */

/* Max Buffer size to hold Audio COCEC - DAC samples */
#define		AUDIO_CODEC_DAC_BUFFER_SIZE   		    (BUFFER_SIZE_PER_AUDIO_DAC_CHANNEL *\
                                                     NUM_AUDIO_DAC_CHANNELS *\
                                                     PCM_SAMPLE_RESOLUTION_IN_BYTES)
/* Max Buffer size to hold Audio COCEC - ADC samples */
#define		AUDIO_CODEC_ADC_BUFFER_SIZE	    	    (BUFFER_SIZE_PER_AUDIO_ADC_CHANNEL *\
                                                     NUM_AUDIO_ADC_CHANNELS *\
                                                     PCM_SAMPLE_RESOLUTION_IN_BYTES)

/*****************************************************************************

Macros to adjust Audio Encoder/Decoder (algorithm) buffer memory allocation

****************************************************************************/

/* Maximum Input samples per channel */
#define     AUDIO_MAX_INPUT_SAMPLES_PER_CHAN        (1024 * 2)  /* 2kB */
/* Maximum Output samples per channel */
#define     AUDIO_MAX_OUTPUT_PCM_SAMPLES_PER_CHAN   (1024 * 2)  /* 2kB */

/* Max Buffer size allocated for Audio Decoder output stream */
#define		AUDIO_DECODER_OUT_BUFFER_SIZE           (NUM_AUDIO_DAC_CHANNELS*\
                                                     AUDIO_MAX_OUTPUT_PCM_SAMPLES_PER_CHAN*\
                                                     PCM_SAMPLE_RESOLUTION_IN_BYTES)

/* Max Buffer size allocated for Audio Decoder input stream */
#define		AUDIO_DECODER_IN_BUFFER_SIZE            (NUM_AUDIO_DAC_CHANNELS*\
                                                     AUDIO_MAX_INPUT_SAMPLES_PER_CHAN*\
                                                     PCM_SAMPLE_RESOLUTION_IN_BYTES)
/* Define number of FIFOs to use */
#define     NUM_PCM_FIFO_BUFFERS                    4  /* bigger FIFO to handle MP3 */

/* PCM FIFO Size */
#define     PCM_FIFO_BUFFER_SIZE                    (AUDIO_MAX_OUTPUT_PCM_SAMPLES_PER_CHAN *\
                                                     NUM_AUDIO_DAC_CHANNELS *\
                                                     (NUM_PCM_FIFO_BUFFERS) *\
                                                     PCM_SAMPLE_RESOLUTION_IN_BYTES)
                                                     
                                                   


/*****************************************************************************

Variable declaratioins

*****************************************************************************/

extern volatile u8  AudioDecoderOutBuf[AUDIO_DECODER_OUT_BUFFER_SIZE];
extern volatile u8  AudioDecoderInBuf[AUDIO_DECODER_IN_BUFFER_SIZE];

/*****************************************************************************

Function prototypes

*****************************************************************************/ 
void DisplayProgress(           /* Displays file progress */
    FILE    *fp, 
    u32     FileLength, 
    u32     TrackLength, 
    u32     NumDecodedSamples, 
    u32     SamplingRate
);
u32     ConfigAudioDevice       (void);
u32     EnableCodecDataflow     (u32 SamplingRate);
u32     DisableCodecDataflow    (void);
u32     CloseAudioDevice        (void);
void    PlayAudioFile           (char *FileName);
u32 AdjustCodecVolume(u32 VolumeLevel);
void ClearOutboundBuffer(void);

#endif /*__CODEC_52XC1_H__*/

/*****/
