码迷,mamicode.com
首页 > 其他好文 > 详细

faac源码分析之faacEncOpen

时间:2015-01-31 12:35:26      阅读:555      评论:0      收藏:0      [点我收藏+]

标签:faac   aac   faac源码分析   faacencopen   

faacEncOpen的代码流程图如下所示:

技术分享

主要包括初始化解码器句柄以及使用的默认参数,最后的是各个功能模块的初始化,主要是分配内存,初始化一些系数表。

faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
	unsigned int numChannels,
	unsigned long *inputSamples,
	unsigned long *maxOutputBytes)
{
	unsigned int channel;
	faacEncHandle hEncoder;

	*inputSamples = FRAME_LEN*numChannels;
	*maxOutputBytes = (6144/8)*numChannels;

#ifdef DRM
	*maxOutputBytes += 1; /* for CRC */
#endif

	hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
	SetMemory(hEncoder, 0, sizeof(faacEncStruct));

	hEncoder->numChannels = numChannels;
	hEncoder->sampleRate = sampleRate;
	hEncoder->sampleRateIdx = GetSRIndex(sampleRate);

	/* Initialize variables to default values */
	hEncoder->frameNum = 0;
	hEncoder->flushFrame = 0;

	/* Default configuration */
	hEncoder->config.version = FAAC_CFG_VERSION;
	hEncoder->config.name = libfaacName;
	hEncoder->config.copyright = libCopyright;
	hEncoder->config.mpegVersion = MPEG4;
	hEncoder->config.aacObjectType = LOW;
	hEncoder->config.allowMidside = 0;
	hEncoder->config.useLfe = 0;
	hEncoder->config.useTns = 0;
	hEncoder->config.bitRate = 48000; /* default bitrate / channel */
	hEncoder->config.bandWidth = 32000/*bwfac * hEncoder->sampleRate*/;
	/* if (hEncoder->config.bandWidth > bwbase)
	hEncoder->config.bandWidth = bwbase;*/
	hEncoder->config.quantqual = 100;
	hEncoder->config.psymodellist = (psymodellist_t *)psymodellist;
	hEncoder->config.psymodelidx = 0;
	hEncoder->psymodel =
		hEncoder->config.psymodellist[hEncoder->config.psymodelidx].model;
	hEncoder->config.shortctl = SHORTCTL_NORMAL;

	/* default channel map is straight-through */
	for( channel = 0; channel < 64; channel++ )
		hEncoder->config.channel_map[channel] = channel;

	/*
	by default we have to be compatible with all previous software
	which assumes that we will generate ADTS
	/AV
	*/
	hEncoder->config.outputFormat = 0;//raw without adts

	/*
	be compatible with software which assumes 24bit in 32bit PCM
	*/
	hEncoder->config.inputFormat = FAAC_INPUT_16BIT;

	/* find correct sampling rate depending parameters */
	hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];

	for (channel = 0; channel < numChannels; channel++) 
	{
		hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
		hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
		hEncoder->coderInfo[channel].block_type = ONLY_SHORT_WINDOW;
		hEncoder->coderInfo[channel].num_window_groups = 1;
		hEncoder->coderInfo[channel].window_group_length[0] = 8;

		/* FIXME: Use sr_idx here */
		hEncoder->coderInfo[channel].max_pred_sfb = GetMaxPredSfb(hEncoder->sampleRateIdx);

		hEncoder->sampleBuff[channel] = NULL;
		hEncoder->nextSampleBuff[channel] = NULL;
		hEncoder->next2SampleBuff[channel] = NULL;
		hEncoder->ltpTimeBuff[channel] = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
		SetMemory(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
	}

	/* Initialize coder functions */
	fft_initialize( &hEncoder->fft_tables );//fast fourier transform initialize

	hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
		hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
		hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
		hEncoder->srInfo->num_cb_short);

	FilterBankInit(hEncoder);

	TnsInit(hEncoder);

	LtpInit(hEncoder);

	PredInit(hEncoder);

	AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels,
		&(hEncoder->aacquantCfg));



	HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);

	/* Return handle */
	return hEncoder;
}


faac源码分析之faacEncOpen

标签:faac   aac   faac源码分析   faacencopen   

原文地址:http://blog.csdn.net/arbboter/article/details/43339387

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!