⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acm.cpp

📁 音频编码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				the_StreamSize->cbDstLength = the_stream->GetOutputSizeForInput(the_StreamSize->cbSrcLength);				Result = MMSYSERR_NOERROR;			}#endif // ENABLE_DECODING		}		break;	default:		Result = MMSYSERR_INVALFLAG;		break;	}	return Result;}inline DWORD ACM::OnStreamClose(LPACMDRVSTREAMINSTANCE a_StreamInstance){	DWORD Result = ACMERR_NOTPOSSIBLE;	my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "OnStreamClose the stream 0x%X",a_StreamInstance->dwInstance);    if (WAVE_FORMAT_PCM == a_StreamInstance->pwfxSrc->wFormatTag &&		PERSONAL_FORMAT == a_StreamInstance->pwfxDst->wFormatTag)    {	ACMStream::Erase( (ACMStream *) a_StreamInstance->dwInstance );	}    else if (PERSONAL_FORMAT == a_StreamInstance->pwfxSrc->wFormatTag &&		 WAVE_FORMAT_PCM== a_StreamInstance->pwfxDst->wFormatTag)    {#ifdef ENABLE_DECODING		DecodeStream::Erase( (DecodeStream *) a_StreamInstance->dwInstance );#endif // ENABLE_DECODING	}	// nothing to do yet	Result = MMSYSERR_NOERROR;	return Result;}inline DWORD ACM::OnStreamPrepareHeader(LPACMDRVSTREAMINSTANCE a_StreamInstance, LPACMSTREAMHEADER a_StreamHeader){	DWORD Result = ACMERR_NOTPOSSIBLE;	my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "  prepare : Src : %d (0x%08X) / %d - Dst : %d (0x%08X) / %d"												, a_StreamHeader->cbSrcLength												, a_StreamHeader->pbSrc												, a_StreamHeader->cbSrcLengthUsed												, a_StreamHeader->cbDstLength												, a_StreamHeader->pbDst												, a_StreamHeader->cbDstLengthUsed											  );	if (WAVE_FORMAT_PCM == a_StreamInstance->pwfxSrc->wFormatTag &&		PERSONAL_FORMAT == a_StreamInstance->pwfxDst->wFormatTag)	{		ACMStream * the_stream = (ACMStream *)a_StreamInstance->dwInstance;				if (the_stream->open(my_EncodingProperties))			Result = MMSYSERR_NOERROR;	}	else if (PERSONAL_FORMAT == a_StreamInstance->pwfxSrc->wFormatTag &&		     WAVE_FORMAT_PCM == a_StreamInstance->pwfxDst->wFormatTag)	{#ifdef ENABLE_DECODING		DecodeStream * the_stream = (DecodeStream *)a_StreamInstance->dwInstance;				if (the_stream->open())			Result = MMSYSERR_NOERROR;#endif // ENABLE_DECODING	}	return Result;}inline DWORD ACM::OnStreamUnPrepareHeader(LPACMDRVSTREAMINSTANCE a_StreamInstance, LPACMSTREAMHEADER a_StreamHeader){	DWORD Result = ACMERR_NOTPOSSIBLE;	my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "unprepare : Src : %d / %d - Dst : %d / %d"											, a_StreamHeader->cbSrcLength											, a_StreamHeader->cbSrcLengthUsed											, a_StreamHeader->cbDstLength											, a_StreamHeader->cbDstLengthUsed											);    if (WAVE_FORMAT_PCM == a_StreamInstance->pwfxSrc->wFormatTag &&		PERSONAL_FORMAT == a_StreamInstance->pwfxDst->wFormatTag)    {	ACMStream * the_stream = (ACMStream *)a_StreamInstance->dwInstance;	DWORD OutputSize = a_StreamHeader->cbDstLength;		if (the_stream->close(a_StreamHeader->pbDst, &OutputSize) && (OutputSize <= a_StreamHeader->cbDstLength))	{		a_StreamHeader->cbDstLengthUsed = OutputSize;			Result = MMSYSERR_NOERROR;		}	}    else if (PERSONAL_FORMAT == a_StreamInstance->pwfxSrc->wFormatTag &&		 WAVE_FORMAT_PCM== a_StreamInstance->pwfxDst->wFormatTag)    {#ifdef ENABLE_DECODING		DecodeStream * the_stream = (DecodeStream *)a_StreamInstance->dwInstance;		DWORD OutputSize = a_StreamHeader->cbDstLength;				if (the_stream->close(a_StreamHeader->pbDst, &OutputSize) && (OutputSize <= a_StreamHeader->cbDstLength))		{			a_StreamHeader->cbDstLengthUsed = OutputSize;			Result = MMSYSERR_NOERROR;	}#endif // ENABLE_DECODING	}	return Result;}inline DWORD ACM::OnStreamConvert(LPACMDRVSTREAMINSTANCE a_StreamInstance, LPACMDRVSTREAMHEADER a_StreamHeader){	DWORD Result = ACMERR_NOTPOSSIBLE;	if (WAVE_FORMAT_PCM == a_StreamInstance->pwfxSrc->wFormatTag &&		PERSONAL_FORMAT == a_StreamInstance->pwfxDst->wFormatTag)	{		my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "OnStreamConvert SRC = PCM (encode)");		ACMStream * the_stream = (ACMStream *) a_StreamInstance->dwInstance;		if (the_stream != NULL)		{			if (the_stream->ConvertBuffer( a_StreamHeader ))				Result = MMSYSERR_NOERROR;		}	}	else if (PERSONAL_FORMAT == a_StreamInstance->pwfxSrc->wFormatTag &&		     WAVE_FORMAT_PCM == a_StreamInstance->pwfxDst->wFormatTag)	{		my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "OnStreamConvert SRC = MP3 (decode)");#ifdef ENABLE_DECODING		DecodeStream * the_stream = (DecodeStream *) a_StreamInstance->dwInstance;		if (the_stream != NULL)		{			if (the_stream->ConvertBuffer( a_StreamHeader ))				Result = MMSYSERR_NOERROR;		}#endif // ENABLE_DECODING	}	else		my_debug.OutPut(DEBUG_LEVEL_FUNC_CODE, "OnStreamConvert unsupported conversion");	return Result;}void ACM::GetMP3FormatForIndex(const DWORD the_Index, WAVEFORMATEX & the_Format, unsigned short the_String[ACMFORMATDETAILS_FORMAT_CHARS]) const{	int Block_size;    char temp[ACMFORMATDETAILS_FORMAT_CHARS];	if (the_Index < bitrate_table.size())	{	//	the_Format.wBitsPerSample = 16;		the_Format.wBitsPerSample = 0;			/// \todo handle more channel modes (mono, stereo, joint-stereo, dual-channel)	//	the_Format.nChannels = SIZE_CHANNEL_MODE - int(the_Index % SIZE_CHANNEL_MODE);			the_Format.nBlockAlign = 1;		the_Format.nSamplesPerSec = bitrate_table[the_Index].frequency;		the_Format.nAvgBytesPerSec = bitrate_table[the_Index].bitrate * 1000 / 8;		if (bitrate_table[the_Index].frequency >= mpeg1_freq[SIZE_FREQ_MPEG1-1])			Block_size = 1152;		else			Block_size = 576;			the_Format.nChannels = bitrate_table[the_Index].channels;		the_Format.cbSize = sizeof(MPEGLAYER3WAVEFORMAT) - sizeof(WAVEFORMATEX);		MPEGLAYER3WAVEFORMAT * tmpFormat = (MPEGLAYER3WAVEFORMAT *) &the_Format;		tmpFormat->wID             = 1;		// this is the only way I found to know if we do CBR or ABR		tmpFormat->fdwFlags        = 2 + ((bitrate_table[the_Index].mode == vbr_abr)?0:2);		tmpFormat->nBlockSize      = Block_size * the_Format.nAvgBytesPerSec / the_Format.nSamplesPerSec;		tmpFormat->nFramesPerBlock = 1;		tmpFormat->nCodecDelay     = 0; // 0x0571 on FHG	         /// \todo : generate the string with the appropriate stereo mode         if (bitrate_table[the_Index].mode == vbr_abr)             wsprintfA( temp, "%d Hz, %d kbps ABR, %s", the_Format.nSamplesPerSec, the_Format.nAvgBytesPerSec * 8 / 1000, (the_Format.nChannels == 1)?"Mono":"Stereo");         else             wsprintfA( temp, "%d Hz, %d kbps CBR, %s", the_Format.nSamplesPerSec, the_Format.nAvgBytesPerSec * 8 / 1000, (the_Format.nChannels == 1)?"Mono":"Stereo");         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, temp, -1, the_String, ACMFORMATDETAILS_FORMAT_CHARS);     } }void ACM::GetPCMFormatForIndex(const DWORD the_Index, WAVEFORMATEX & the_Format, unsigned short the_String[ACMFORMATDETAILS_FORMAT_CHARS]) const{	the_Format.nChannels = SIZE_CHANNEL_MODE - int(the_Index % SIZE_CHANNEL_MODE);	the_Format.wBitsPerSample = 16;	the_Format.nBlockAlign = the_Format.nChannels * the_Format.wBitsPerSample / 8;	DWORD a_Channel_Independent = the_Index / SIZE_CHANNEL_MODE;	// first MPEG1 frequencies	if (a_Channel_Independent < SIZE_FREQ_MPEG1)	{		the_Format.nSamplesPerSec = mpeg1_freq[a_Channel_Independent];	}	else	{		a_Channel_Independent -= SIZE_FREQ_MPEG1;		the_Format.nSamplesPerSec = mpeg2_freq[a_Channel_Independent];	}	the_Format.nAvgBytesPerSec = the_Format.nSamplesPerSec * the_Format.nChannels * the_Format.wBitsPerSample / 8;}DWORD ACM::GetNumberEncodingFormats() const{	return bitrate_table.size();}bool ACM::IsSmartOutput(const int frequency, const int bitrate, const int channels) const{	double compression_ratio = double(frequency * 2 * channels) / double(bitrate * 100);//my_debug.OutPut(DEBUG_LEVEL_FUNC_DEBUG, "compression_ratio %f, freq %d, bitrate %d, channels %d", compression_ratio, frequency, bitrate, channels);	if(my_EncodingProperties.GetSmartOutputMode())		return (compression_ratio <= my_EncodingProperties.GetSmartRatio());	else return true;}void ACM::BuildBitrateTable(){	my_debug.OutPut("entering BuildBitrateTable");	// fill the table	unsigned int channel,bitrate,freq;		bitrate_table.clear();	// CBR bitrates	for (channel = 0;channel < SIZE_CHANNEL_MODE;channel++)	{		// MPEG I		for (freq = 0;freq < SIZE_FREQ_MPEG1;freq++)		{			for (bitrate = 0;bitrate < SIZE_BITRATE_MPEG1;bitrate++)			{				if (!my_EncodingProperties.GetSmartOutputMode() || IsSmartOutput(mpeg1_freq[freq], mpeg1_bitrate[bitrate], channel+1))				{					bitrate_item * bitrate_table_tmp = new bitrate_item;					if (bitrate_table_tmp == NULL)						return;										bitrate_table_tmp->frequency = mpeg1_freq[freq];					bitrate_table_tmp->bitrate = mpeg1_bitrate[bitrate];					bitrate_table_tmp->channels = channel+1;					bitrate_table_tmp->mode = vbr_off;					bitrate_table.push_back(*bitrate_table_tmp);				}			}		}		// MPEG II / II.5		for (freq = 0;freq < SIZE_FREQ_MPEG2;freq++)		{			for (bitrate = 0;bitrate < SIZE_BITRATE_MPEG2;bitrate++)			{				if (!my_EncodingProperties.GetSmartOutputMode() || IsSmartOutput(mpeg2_freq[freq], mpeg2_bitrate[bitrate], channel+1))				{					bitrate_item * bitrate_table_tmp = new bitrate_item;					if (bitrate_table_tmp == NULL)						return;										bitrate_table_tmp->frequency = mpeg2_freq[freq];					bitrate_table_tmp->bitrate = mpeg2_bitrate[bitrate];					bitrate_table_tmp->channels = channel+1;					bitrate_table_tmp->mode = vbr_abr;					bitrate_table.push_back(*bitrate_table_tmp);				}			}		}	}	if (my_EncodingProperties.GetAbrOutputMode())	// ABR bitrates	{		for (channel = 0;channel < SIZE_CHANNEL_MODE;channel++)		{			// MPEG I			for (freq = 0;freq < SIZE_FREQ_MPEG1;freq++)			{				for (bitrate = my_EncodingProperties.GetAbrBitrateMax();					   bitrate >= my_EncodingProperties.GetAbrBitrateMin(); 				     bitrate -= my_EncodingProperties.GetAbrBitrateStep())				{					if (bitrate >= mpeg1_bitrate[SIZE_BITRATE_MPEG1-1] && (!my_EncodingProperties.GetSmartOutputMode() || IsSmartOutput(mpeg1_freq[freq], bitrate, channel+1)))					{						bitrate_item * bitrate_table_tmp = new bitrate_item;						if (bitrate_table_tmp == NULL)							return;												bitrate_table_tmp->frequency = mpeg1_freq[freq];						bitrate_table_tmp->bitrate = bitrate;						bitrate_table_tmp->channels = channel+1;						bitrate_table_tmp->mode = vbr_abr;						bitrate_table.push_back(*bitrate_table_tmp);					}				}			}			// MPEG II / II.5			for (freq = 0;freq < SIZE_FREQ_MPEG2;freq++)			{				for (bitrate = my_EncodingProperties.GetAbrBitrateMax();					   bitrate >= my_EncodingProperties.GetAbrBitrateMin(); 				     bitrate -= my_EncodingProperties.GetAbrBitrateStep())				{					if (bitrate >= mpeg2_bitrate[SIZE_BITRATE_MPEG2-1] && (!my_EncodingProperties.GetSmartOutputMode() || IsSmartOutput(mpeg2_freq[freq], bitrate, channel+1)))					{						bitrate_item * bitrate_table_tmp = new bitrate_item;						if (bitrate_table_tmp == NULL)							return;												bitrate_table_tmp->frequency = mpeg2_freq[freq];						bitrate_table_tmp->bitrate = bitrate;						bitrate_table_tmp->channels = channel+1;						bitrate_table_tmp->mode = vbr_abr;						bitrate_table.push_back(*bitrate_table_tmp);					}				}			}		}	}	// sorting by frequency/bitrate/channel	std::sort(bitrate_table.begin(), bitrate_table.end());/*	{		// display test		int i=0;		for (i=0; i<bitrate_table.size();i++)		{			my_debug.OutPut("bitrate_table[%d].frequency = %d",i,bitrate_table[i].frequency);			my_debug.OutPut("bitrate_table[%d].bitrate = %d",i,bitrate_table[i].bitrate);			my_debug.OutPut("bitrate_table[%d].channel = %d",i,bitrate_table[i].channels);			my_debug.OutPut("bitrate_table[%d].ABR = %s\n",i,(bitrate_table[i].mode == vbr_abr)?"ABR":"CBR");		}	}*/	my_debug.OutPut("leaving BuildBitrateTable");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -