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

📄 blademp3encdll.c

📁 音频编码
💻 C
📖 第 1 页 / 共 2 页
字号:
	if ( !lameConfig.format.LHV1.bOriginal )	{		lame_set_original( gfp, 0 );	}	else	{		lame_set_original( gfp, 1 );	}	// Add CRC?	if ( lameConfig.format.LHV1.bCRC )	{		lame_set_error_protection( gfp, 1 );	}	else	{		lame_set_error_protection( gfp, 0 );	}	// Set private bit?	if ( lameConfig.format.LHV1.bPrivate )	{		lame_set_extension( gfp, 1 );	}	else	{		lame_set_extension( gfp, 0 );	}		// Set VBR min bitrate, if specified	if ( lameConfig.format.LHV1.dwBitrate > 0 )	{		lame_set_VBR_min_bitrate_kbps( gfp, lameConfig.format.LHV1.dwBitrate );	}	// Set Maxbitrate, if specified	if ( lameConfig.format.LHV1.dwMaxBitrate > 0 )	{		lame_set_VBR_max_bitrate_kbps( gfp, lameConfig.format.LHV1.dwMaxBitrate );	}	// Set bit resovoir option	if ( lameConfig.format.LHV1.bNoRes )	{		lame_set_disable_reservoir( gfp,1 );		lame_set_padding_type( gfp, PAD_NO );	}	// check if the VBR tag is required	if ( TRUE == lameConfig.format.LHV1.bWriteVBRHeader) 	{		lame_set_bWriteVbrTag( gfp, 1 );	}	else	{		lame_set_bWriteVbrTag( gfp, 0 );	}	// Override Quality setting, use HIGHBYTE = NOT LOWBYTE to be backwards compatible	if (	( lameConfig.format.LHV1.nQuality & 0xFF ) ==			((~( lameConfig.format.LHV1.nQuality >> 8 )) & 0xFF) )	{		lame_set_quality( gfp, lameConfig.format.LHV1.nQuality & 0xFF );	}		if ( 0 != ( nInitReturn = lame_init_params( gfp ) ) )	{		return nInitReturn;	}	//LAME encoding call will accept any number of samples.  	if ( 0 == lame_get_version( gfp ) )	{		// For MPEG-II, only 576 samples per frame per channel		*dwSamples= 576 * lame_get_num_channels( gfp );	}	else	{		// For MPEG-I, 1152 samples per frame per channel		*dwSamples= 1152 * lame_get_num_channels( gfp );	}	// Set the input sample buffer size, so we know what we can expect	dwSampleBufferSize = *dwSamples;	// Set MP3 buffer size, conservative estimate	*dwBufferSize=(DWORD)( 1.25 * ( *dwSamples / lame_get_num_channels( gfp ) ) + 7200 );	// For debugging purposes	dump_config( gfp );	// Everything went OK, thus return SUCCESSFUL	return BE_ERR_SUCCESSFUL;}__declspec(dllexport) BE_ERR	beFlushNoGap(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput){	int nOutputSamples = 0;	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;	// Init the global flags structure    nOutputSamples = lame_encode_flush_nogap( gfp, pOutput, LAME_MAXMP3BUFFER );	if ( nOutputSamples < 0 )	{		*pdwOutput = 0;		return BE_ERR_BUFFER_TOO_SMALL;	}	else	{		*pdwOutput = nOutputSamples;	}	return BE_ERR_SUCCESSFUL;}__declspec(dllexport) BE_ERR	beDeinitStream(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput){	int nOutputSamples = 0;	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;    nOutputSamples = lame_encode_flush( gfp, pOutput, 0 );	if ( nOutputSamples < 0 )	{		*pdwOutput = 0;		return BE_ERR_BUFFER_TOO_SMALL;	}	else	{		*pdwOutput = nOutputSamples;	}  	return BE_ERR_SUCCESSFUL;}__declspec(dllexport) BE_ERR	beCloseStream(HBE_STREAM hbeStream){	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;	// lame will be close in VbrWriteTag function	if ( !lame_get_bWriteVbrTag( gfp ) )	{		// clean up of allocated memory		lame_close( gfp );		gfp_save = NULL;	}	else	{		gfp_save = (lame_global_flags*)hbeStream;	}	// DeInit encoder	return BE_ERR_SUCCESSFUL;}__declspec(dllexport) VOID		beVersion(PBE_VERSION pbeVersion){	// DLL Release date	char lpszDate[20]	= { '\0', };	char lpszTemp[5]	= { '\0', };	lame_version_t lv   = { 0, };	// Set DLL interface version	pbeVersion->byDLLMajorVersion=MAJORVERSION;	pbeVersion->byDLLMinorVersion=MINORVERSION;	get_lame_version_numerical ( &lv );	// Set Engine version number (Same as Lame version)	pbeVersion->byMajorVersion = lv.major;	pbeVersion->byMinorVersion = lv.minor;	pbeVersion->byAlphaLevel   = lv.alpha;	pbeVersion->byBetaLevel	   = lv.beta;#ifdef MMX_choose_table	pbeVersion->byMMXEnabled=1;#else	pbeVersion->byMMXEnabled=0;#endif	memset( pbeVersion->btReserved, 0, sizeof( pbeVersion->btReserved ) );	// Get compilation date	strcpy(lpszDate,__DATE__);	// Get the first three character, which is the month	strncpy(lpszTemp,lpszDate,3);	lpszTemp[3] = '\0';	pbeVersion->byMonth=1;	// Set month	if (strcmp(lpszTemp,"Jan")==0)	pbeVersion->byMonth = 1;	if (strcmp(lpszTemp,"Feb")==0)	pbeVersion->byMonth = 2;	if (strcmp(lpszTemp,"Mar")==0)	pbeVersion->byMonth = 3;	if (strcmp(lpszTemp,"Apr")==0)	pbeVersion->byMonth = 4;	if (strcmp(lpszTemp,"May")==0)	pbeVersion->byMonth = 5;	if (strcmp(lpszTemp,"Jun")==0)	pbeVersion->byMonth = 6;	if (strcmp(lpszTemp,"Jul")==0)	pbeVersion->byMonth = 7;	if (strcmp(lpszTemp,"Aug")==0)	pbeVersion->byMonth = 8;	if (strcmp(lpszTemp,"Sep")==0)	pbeVersion->byMonth = 9;	if (strcmp(lpszTemp,"Oct")==0)	pbeVersion->byMonth = 10;	if (strcmp(lpszTemp,"Nov")==0)	pbeVersion->byMonth = 11;	if (strcmp(lpszTemp,"Dec")==0)	pbeVersion->byMonth = 12;	// Get day of month string (char [4..5])	pbeVersion->byDay=atoi( lpszDate + 4 );	// Get year of compilation date (char [7..10])	pbeVersion->wYear = atoi( lpszDate + 7 );	memset( pbeVersion->zHomepage, 0x00, BE_MAX_HOMEPAGE );	strcpy( pbeVersion->zHomepage, "http://www.mp3dev.org/" );}__declspec(dllexport) BE_ERR	beEncodeChunk(HBE_STREAM hbeStream, DWORD nSamples, 			 PSHORT pSamples, PBYTE pOutput, PDWORD pdwOutput){	// Encode it	int dwSamples;	int	nOutputSamples = 0;	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;	dwSamples = nSamples / lame_get_num_channels( gfp );	// old versions of lame_enc.dll required exactly 1152 samples	// and worked even if nSamples accidently set to 2304 	// simulate this behavoir:	if ( 1 == lame_get_num_channels( gfp ) && nSamples == 2304)	{	  dwSamples/= 2;	}	if ( 1 == lame_get_num_channels( gfp ) )	{		nOutputSamples = lame_encode_buffer(gfp,pSamples,pSamples,dwSamples,pOutput,0);	}	else	{		nOutputSamples = lame_encode_buffer_interleaved(gfp,pSamples,dwSamples,pOutput,0);	}	if ( nOutputSamples < 0 )	{		*pdwOutput=0;		return BE_ERR_BUFFER_TOO_SMALL;	}	else	{		*pdwOutput = (DWORD)nOutputSamples;	}	return BE_ERR_SUCCESSFUL;}// accept floating point audio samples, scaled to the range of a signed 16-bit//  integer (within +/- 32768), in non-interleaved channels  -- DSPguru, jd__declspec(dllexport) BE_ERR	beEncodeChunkFloatS16NI(HBE_STREAM hbeStream, DWORD nSamples, 			PFLOAT buffer_l, PFLOAT buffer_r, PBYTE pOutput, PDWORD pdwOutput){	int nOutputSamples;	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;	nOutputSamples = lame_encode_buffer_float(gfp,buffer_l,buffer_r,nSamples,pOutput,0);	if ( nOutputSamples >= 0 )	{		*pdwOutput = (DWORD) nOutputSamples;	}	else	{		*pdwOutput=0;		return BE_ERR_BUFFER_TOO_SMALL;	}	return BE_ERR_SUCCESSFUL;}__declspec(dllexport) BE_ERR beWriteInfoTag( HBE_STREAM hbeStream,											 LPCSTR lpszFileName ){	FILE* fpStream	= NULL;	BE_ERR beResult	= BE_ERR_SUCCESSFUL;	lame_global_flags*	gfp = (lame_global_flags*)hbeStream;	if ( NULL != gfp )	{		// Do we have to write the VBR tag?		if ( lame_get_bWriteVbrTag( gfp ) )		{			// Try to open the file			fpStream=fopen( lpszFileName, "rb+" );			// Check file open result			if ( NULL == fpStream )			{				beResult = BE_ERR_INVALID_FORMAT_PARAMETERS;			}			else			{				// Write Xing header again				lame_mp3_tags_fid( gfp, fpStream );				// Close the file stream				fclose( fpStream );			}			// clean up of allocated memory			lame_close( gfp );		}	}	else	{		beResult = BE_ERR_INVALID_FORMAT_PARAMETERS;	}	// return result	return beResult;}// for backwards compatiblity__declspec(dllexport) BE_ERR beWriteVBRHeader(LPCSTR lpszFileName){	return beWriteInfoTag( (HBE_STREAM)gfp_save, lpszFileName );}BOOL APIENTRY DllMain(HANDLE hModule,                       DWORD  ul_reason_for_call,                       LPVOID lpReserved){	gs_hModule=hModule;    switch( ul_reason_for_call )	{		case DLL_PROCESS_ATTACH:			// Enable debug/logging?			gs_bLogFile = GetPrivateProfileInt("Debug","WriteLogFile",gs_bLogFile,"lame_enc.ini");		break;		case DLL_THREAD_ATTACH:		break;		case DLL_THREAD_DETACH:		break;		case DLL_PROCESS_DETACH:		break;    }    return TRUE;}static void dump_config( 	lame_global_flags*	gfp ){	DebugPrintf("\n\nLame_enc configuration options:\n");	DebugPrintf("==========================================================\n");	DebugPrintf("version                =%d\n",lame_get_version( gfp ) );	DebugPrintf("Layer                  =3\n");	DebugPrintf("mode                   =");	switch ( lame_get_mode( gfp ) )	{		case STEREO:       DebugPrintf( "Stereo\n" ); break;		case JOINT_STEREO: DebugPrintf( "Joint-Stereo\n" ); break;		case DUAL_CHANNEL: DebugPrintf( "Forced Stereo\n" ); break;		case MONO:         DebugPrintf( "Mono\n" ); break;		case NOT_SET:      /* FALLTROUGH */		default:           DebugPrintf( "Error (unknown)\n" ); break;	}	DebugPrintf("Input sample rate      =%.1f kHz\n", lame_get_in_samplerate( gfp ) /1000.0 );	DebugPrintf("Output sample rate     =%.1f kHz\n", lame_get_out_samplerate( gfp ) /1000.0 );	DebugPrintf("bitrate                =%d kbps\n", lame_get_brate( gfp ) );	DebugPrintf("Quality Setting        =%d\n", lame_get_quality( gfp ) );	DebugPrintf("Low pass frequency     =%d\n", lame_get_lowpassfreq( gfp ) );	DebugPrintf("Low pass width         =%d\n", lame_get_lowpasswidth( gfp ) );	DebugPrintf("High pass frequency    =%d\n", lame_get_highpassfreq( gfp ) );	DebugPrintf("High pass width        =%d\n", lame_get_highpasswidth( gfp ) );	DebugPrintf("No short blocks        =%d\n", lame_get_no_short_blocks( gfp ) );	DebugPrintf("Force short blocks     =%d\n", lame_get_force_short_blocks( gfp ) );	DebugPrintf("de-emphasis            =%d\n", lame_get_emphasis( gfp ) );	DebugPrintf("private flag           =%d\n", lame_get_extension( gfp ) );	DebugPrintf("copyright flag         =%d\n", lame_get_copyright( gfp ) );	DebugPrintf("original flag          =%d\n",	lame_get_original( gfp ) );	DebugPrintf("CRC                    =%s\n", lame_get_error_protection( gfp ) ? "on" : "off" );	DebugPrintf("Fast mode              =%s\n", ( lame_get_quality( gfp ) )? "enabled" : "disabled" );	DebugPrintf("Force mid/side stereo  =%s\n", ( lame_get_force_ms( gfp ) )?"enabled":"disabled" );	DebugPrintf("Padding Type           =%d\n", lame_get_padding_type( gfp ) );	DebugPrintf("Disable Reservoir      =%d\n", lame_get_disable_reservoir( gfp ) );	DebugPrintf("Allow diff-short       =%d\n", lame_get_allow_diff_short( gfp ) );	DebugPrintf("Interchannel masking   =%f\n", lame_get_interChRatio( gfp ) );	DebugPrintf("Strict ISO Encoding    =%s\n", ( lame_get_strict_ISO( gfp ) ) ?"Yes":"No");	DebugPrintf("Scale                  =%5.2f\n", lame_get_scale( gfp ) );	DebugPrintf("VBR                    =%s, VBR_q =%d, VBR method =",					( lame_get_VBR( gfp ) !=vbr_off ) ? "enabled": "disabled",		            lame_get_VBR_q( gfp ) );	switch ( lame_get_VBR( gfp ) )	{		case vbr_off:	DebugPrintf( "vbr_off\n" );	break;		case vbr_mt :	DebugPrintf( "vbr_mt \n" );	break;		case vbr_rh :	DebugPrintf( "vbr_rh \n" );	break;		case vbr_mtrh:	DebugPrintf( "vbr_mtrh \n" );	break;		case vbr_abr: 			DebugPrintf( "vbr_abr (average bitrate %d kbps)\n", lame_get_VBR_mean_bitrate_kbps( gfp ) );		break;		default:			DebugPrintf("error, unknown VBR setting\n");		break;	}	DebugPrintf("Vbr Min bitrate        =%d kbps\n", lame_get_VBR_min_bitrate_kbps( gfp ) );	DebugPrintf("Vbr Max bitrate        =%d kbps\n", lame_get_VBR_max_bitrate_kbps( gfp ) );	DebugPrintf("Write VBR Header       =%s\n", ( lame_get_bWriteVbrTag( gfp ) ) ?"Yes":"No");	DebugPrintf("VBR Hard min           =%d\n", lame_get_VBR_hard_min( gfp ) );	DebugPrintf("ATH Only               =%d\n", lame_get_ATHonly( gfp ) );	DebugPrintf("ATH short              =%d\n", lame_get_ATHshort( gfp ) );	DebugPrintf("ATH no                 =%d\n", lame_get_noATH( gfp ) );	DebugPrintf("ATH type               =%d\n", lame_get_ATHtype( gfp ) );	DebugPrintf("ATH lower              =%f\n", lame_get_ATHlower( gfp ) );	DebugPrintf("ATH aa                 =%d\n", lame_get_athaa_type( gfp ) );	DebugPrintf("ATH aa  loudapprox     =%d\n", lame_get_athaa_loudapprox( gfp ) );	DebugPrintf("ATH aa  sensitivity    =%f\n", lame_get_athaa_sensitivity( gfp ) );	DebugPrintf("Experimental nspsytune =%d\n", lame_get_exp_nspsytune( gfp ) );	DebugPrintf("Experimental X         =%d\n", lame_get_experimentalX( gfp ) );	DebugPrintf("Experimental Y         =%d\n", lame_get_experimentalY( gfp ) );	DebugPrintf("Experimental Z         =%d\n", lame_get_experimentalZ( gfp ) );}static void DispErr(LPSTR strErr){	MessageBox(NULL,strErr,"",MB_OK);}

⌨️ 快捷键说明

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