audio_dec_dolby.c 9.17 KB
#include "os_config.h"

#include "c_def.h"
#include "debug.h"
#include "oem.h"


#ifdef DOLBY_AC3_DEC

#include "fifo.h"
#include "regmap.h"

#include "mem_reloc.h"

#include "hw_da_pp.h"

#include "message.h"
#include "audio_com.h"
#include "audio_dec.h"
#include "audio_dec_dolby.h"
#include "app_dac.h"
#include "app_cmd.h"
#include "app_main.h"

#include "xa_type_def.h"



#if 0
#undef AUDIO__OUTPUT_1_CH
#undef AUDIO_OUTPUT_2_CH
#undef AUDIO_OUTPUT_3_CH
#undef AUDIO_OUTPUT_4_CH
#undef AUDIO_OUTPUT_6_CH
#undef AUDIO_OUTPUT_0P1_CH_USED_WIRLESS
#endif


#ifdef AUDIO_HEADPHONE_OUTPUT
#define AUDIO_OUTPUT_2_CH
#else
//#define AUDIO_AC3_OUTPUT_1_CH
//#define AUDIO_OUTPUT_2_CH
//#define AUDIO_OUTPUT_3_CH
#define AUDIO_OUTPUT_4_CH
//#define AUDIO_OUTPUT_6_CH
#endif

//#define AUDIO_OUTPUT_0P1_CH_USED_WIRLESS



/*
"-z:1\0",                    //Enables/Disables clearing of unused channels at the output
"-lfeout:0\0",               //Enable/Disable lfe output
"-ocfg:2\0",                 //Specifies output channel configuration in the range 0 to 7
"-och:2\0",                  //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2C,3l,4r,5s\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
*/

#if 1//lib

#if defined AUDIO_OUTPUT_6_CH

#if 0
#define OPTEK_AC3_ARGC	2

//default
//5.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",
//	"-chmap:0L,1R,2C,3l,4r,5s\0"
	"-chmap:0L,1R,2C,3s,4l,5r\0",
};

#else

#define OPTEK_AC3_ARGC	5

//5.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",                        //Enables/Disables clearing of unused channels at the output
	"-lfeout:1\0",                   //Enable/Disable lfe output
	"-ocfg:7\0",                     //Specifies output channel configuration in the range 0 to 7
//	"-ocfg:6\0",                     //Specifies output channel configuration in the range 0 to 7
	"-och:6\0",                      //Specifies the number of PCM channels to output in the range 1 to 6
//	"-chmap:0L,1R,2C,3l,4r,5s\0"     //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
	"-chmap:0L,1R,2C,3s,4l,5r\0"     //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};

#endif

#elif defined AUDIO_OUTPUT_4_CH

#define OPTEK_AC3_ARGC	5

//3.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",                         //Enables/Disables clearing of unused channels at the output
	"-lfeout:1\0",                    //Enable/Disable lfe output
	"-ocfg:5\0",                      //Specifies output channel configuration in the range 0 to 7
	"-och:4\0",                       //Specifies the number of PCM channels to output in the range 1 to 6
	"-chmap:0L,1R,2C,3s,4l,5r\0"      //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};

#elif defined AUDIO_OUTPUT_3_CH

#define OPTEK_AC3_ARGC	5

//2.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",                      //Enables/Disables clearing of unused channels at the output
	"-lfeout:1\0",                 //Enable/Disable lfe output
	"-ocfg:4\0",                   //Specifies output channel configuration in the range 0 to 7
	"-och:3\0",                    //Specifies the number of PCM channels to output in the range 1 to 6
	"-chmap:0L,1R,2s,3l,4r,5C\0"   //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};

#elif defined AUDIO_OUTPUT_2_CH

#define OPTEK_AC3_ARGC	5

#if 1
//2.0
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",                     //Enables/Disables clearing of unused channels at the output
	"-lfeout:0\0",                //Enable/Disable lfe output
	"-ocfg:7\0",                  //Specifies output channel configuration in the range 0 to 7
//	"-ocfg:2\0",                  //Specifies output channel configuration in the range 0 to 7
	"-och:2\0",                   //Specifies the number of PCM channels to output in the range 1 to 6
	"-chmap:0L,1R,2s,3l,4r,5C\0"  //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#else
//2.0, for testing
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
	"-z:1\0",                     //Enables/Disables clearing of unused channels at the output
	"-lfeout:1\0",                //Enable/Disable lfe output
	"-ocfg:2\0",                  //Specifies output channel configuration in the range 0 to 7
	"-och:2\0",                   //Specifies the number of PCM channels to output in the range 1 to 6
	"-chmap:0L,1R,2s,3C,4l,5r\0"      //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
//	"-chmap:0L,1R,2C,3s,4l,5r\0"      //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
//	"-chmap:0l,1r,2L,3R,4C,5s\0"      //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
//	"-chmap:0C,1s,2L,3R,4l,5r\0"      //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#endif

#else
#error "The output channels of Dolby must be defined"
#endif


XA_ERRORCODE xa_dd_ac3_dec_main_process (WORD32 argc, char *argv[]) __INTERNAL_RAM_TEXT;
//void xa_shift_input_buffer (char *buf, int buf_size, int bytes_consumed) __INTERNAL_RAM_TEXT;
//int xa_spdif_fread(void *buffer, int size, int count, void *fp) __INTERNAL_RAM_TEXT;

#endif


extern unsigned int ui_ocfg;
extern unsigned int ui_stmode;
extern unsigned int ui_dynrng_mode;
extern unsigned int ui_monorep;
extern unsigned int ui_dyn_cut_hi;
extern unsigned int ui_dyn_boost_lo;


void dd_ac3_dec_init( void )
{
	//DBG_Printf("%s\n\r", __func__);

#if defined AUDIO_PWM_OUTPUT

#if defined AUDIO_OUTPUT_2_CH
	audio_out_mode = AUDIO_OUT_L_R;
	da_pp_channel_setting(0);
#elif defined AUDIO_OUTPUT_3_CH
	audio_out_mode = AUDIO_OUT_L_R_Sub;
	da_pp_channel_setting(1);
#elif defined AUDIO_OUTPUT_4_CH
	audio_out_mode = AUDIO_OUT_L_R_Center_Sub;
	da_pp_channel_setting(1);
#elif defined AUDIO_OUTPUT_6_CH
	audio_out_mode = AUDIO_OUT_L_R_Center_Sub_LS_RS;
	//audio_out_mode = AUDIO_OUT_L_R_Sub_Center_LS_RS,
	da_pp_channel_setting(2);
#else
	audio_out_mode = AUDIO_OUT_L_R;
	da_pp_channel_setting(MI2S_OUTPUT_CHANNEL_DEFAULT);
#endif

#else
	audio_out_mode = AUDIO_OUT_L_R;
	da_pp_channel_setting(MI2S_OUTPUT_CHANNEL_DEFAULT);
#endif


#if 1//downmix lt/Rt mode, must use the code below at released version 
	DBG_Printf("dd_ac3_dec_init\n");
	ui_stmode = 1;
	//ui_ocfg = 0;//Ls Rs C mix in L R, Ls Rs C not sound, s not modify
	//ui_ocfg = 1;//Ls Rs L R mix in C, Ls Rs L R not sound, s not modify
	//ui_ocfg = 2;//Ls Rs C mix in L R, Ls Rs C not sound, s not modify
	//ui_ocfg = 3;// Ls mix in L, Rs mix in R, Ls Rs not sound, C s not modify
	//ui_ocfg = 4;//C mix in L R, Rs mix in Ls, Rs C not sound, s not modify
	//ui_ocfg = 5;//Rs mix in Ls, Rs not sound, L R C s not modify

	ui_ocfg = 2;//C mix in L R, C not sound, Ls Rs s not modify

	//ui_ocfg = 7;//not mix, L R C Ls Rs s not modify, default
	//ui_dynrng_mode = 0;
	ui_dynrng_mode = 2;
	ui_monorep = 0;
	//ui_dyn_cut_hi = 0;
	//ui_dyn_boost_lo = 0;
	//ui_dyn_cut_hi = 0x007FFFFF;
	//ui_dyn_boost_lo = 0x007FFFFF;
#endif


	//default
	//app_main_data.playing_stream_sample_rate = 48000;
	//app_main_data.playing_stream_bitrate = (384000/8);

	//uMsgSend (UI_CODEC, UI_DEC_INIT_SUCCESS, 0);

}

void dd_ac3_dec_open( void )
{
}

void dd_ac3_dec_close( void )
{
}

void dd_ac3_dec_fini( void )
{
}


//XA_ERRORCODE xa_dd_ac3_dec_process (void);

void dd_ac3_dec_decode( void )
{
	int ret;

#ifdef DD_AC3_DEC_16BIT_OUT
	app_main_data.audio_out_24bit= FALSE;
#else
	app_main_data.audio_out_24bit= TRUE;
#endif

	ret = xa_dd_ac3_dec_main_process(OPTEK_AC3_ARGC, optek_ac3_argv);
	//xa_dd_ac3_dec_main_process();

	//DBG_Printf("ac3's return :%d\n\r", ret);

	// Reached the end of bit stream.
	if (wRequestDecodeFrameExit != TRUE)
	{
		//playing to stream end
		uMsgSend (UI_CODEC, UI_DECODE_STREAM_EOF, 0);
	}
	else
	{
		//asm("break 1,1");
		DBG_Printf("ac3's dec force exit\n\r");
	}
}

void app_nav_dec_set_parms_cb (u32 freq, u32 bit_rate)
{
	app_main_data.playing_stream_sample_rate = freq;
	//app_main_data.playing_stream_chans = chans;
	app_main_data.playing_stream_bitrate = (bit_rate/8);

	switch (freq)
	{
	case 44100:
		break;

	case 48000:
		break;

	case 32000:
		break;

	case 88200:
		break;
		
	case 96000:
		break;
		
	case 64000:
		break;
		
	case 176400:
		break;
		
	case 192000:
		break;
		
	case 128000:
		break;

	default:
		DBG_Assert (FALSE);
		break;
	}

	//waiting for audio pll
	//app_nav_sleep(100);
}


#if 0
#define	DOBLY_DD_AC3_DECODE dd_ac3_dec_init, \
                            dd_ac3_dec_open, \
                            dd_ac3_dec_close, \
                            decnone_fini, \
                            dd_ac3_dec_decode
#else
#define	DOBLY_DD_AC3_DECODE dd_ac3_dec_init, \
                            dd_ac3_dec_fini, \
                            dd_ac3_dec_decode
#endif

const DECODE_DEVICE dd_ac3_decode =
{
	DOBLY_DD_AC3_DECODE
};

#endif //DOLBY_AC3_DEC