ffmpeg player sound effects fade 1-

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/xjb2006/article/details/85159676

 Directly on the player:

 

 Players require the use of similar TTPlayer fade function, the sound fades, is the beginning of the sound gradually increases, it will not suddenly be great. At the end of the sound gradually release small, will not suddenly disappear. Especially particularly useful for certain special occasions, such as ballroom dancing, songs and other audio sound stage where a lot of switching, with the fade will not be very smooth unexpected! Closer to home, in fact, achieve program principle is very simple, linear control music playback volume. At first, for example within 3 seconds, the volume gradually increases from 0 to 100. 3 seconds before the end, when the volume gradually reduced from 100 to 0. drag the progress, and start playing the same approach. OK, directly on the core code:

void CMP3FenGe::SetFadeIn(  LONG nFadeIn, LONG nFadeInStartTime, LONG nFadeInTime)
{
	m_nFadeIn=nFadeIn;
	m_nFadeInStartTime=nFadeInStartTime;
	m_nFadeInTime=nFadeInTime;

}

void CMP3FenGe::SetFadeOut(  LONG nFadeOut, LONG nFadeOutStartTime, LONG nFadeOutTime)
{
	m_nFadeOut=nFadeOut;
	m_nFadeOutStartTime=nFadeOutStartTime;
	m_nFadeOutTime=nFadeOutTime;
}


声音回调函数调用插入:
		FadeIn((BYTE*)BufLeft,dwRetBytesL);
		FadeOut((BYTE*)BufLeft,dwRetBytesL);

具体实现:
//淡入淡出 0无效果  1淡入
void CMP3FenGe::FadeIn(BYTE *pData,int nLen)
{
	if(m_nFadeIn==0)
		return;
	if(m_nFadeInTime<=100)
		return;
	__int64 nCurTime=this->GetCurMSec();
	if(nCurTime>=m_nFadeInStartTime&&nCurTime<=m_nFadeInStartTime+m_nFadeInTime)
	{
		double dbGain=(double)(nCurTime-m_nFadeInStartTime)/(double)(m_nFadeInTime);
		WaveGain(pData,nLen,dbGain);
		TRACE("fadein gain:%0.2f\n",dbGain);
	
	}

}

//淡入淡出 0无效果  1淡入 2淡出
void CMP3FenGe::FadeOut(BYTE *pData,int nLen)
{
	if(m_nFadeOut==0)
		return;
	if(m_nFadeOutTime<=100)
		return;
	__int64 nCurTime=this->GetCurMSec();
	if(nCurTime>=m_nFadeOutStartTime&&nCurTime<=m_nFadeOutStartTime+m_nFadeOutTime)
	{
		double dbGain=1-(double)(nCurTime-m_nFadeOutStartTime)/(double)(m_nFadeOutTime);
		WaveGain(pData,nLen,dbGain);
		TRACE("fadeout gain:%0.2f\n",dbGain);
	
	}

}


声音增益调整函数:
//调整增益
static void WaveGain(BYTE *pBuf,int nLen,float fGain=3.0f)//16位单声道
{
	short w;
	for(int i=0;i<nLen;i+=2)
	{
		w=MAKEWORD(pBuf[i],pBuf[i+1]);
		int iw=(float)w*fGain;
		if(iw>32767)
			iw=32767;
		if(iw<-32767)
			iw=-32767;
		w =	iw;
		(pBuf)[i]=LOBYTE(w);
		(pBuf)[i+1]=HIBYTE(w);
	}
}

 

 Well, this document mainly speak at the sound fade algorithm, next time to continue speaking tone processing algorithms speed of sound at the same harmonic sounds. Stay tuned!

May be one day, probably in January, it may be one year. . . . . .

When uploading the code to find time to go, and finally make ads:

The need for cooperation to contact QQ35744025, I have 03 years working (good old), "proficient" audio and video applications programming techniques (plus barely proficient, to attract attention, ha ha), proficient in VC, MFC, multimedia educational software, recording and broadcasting software, live most software has acquired the core technology, such as technology ffmpeg, MP4, FLV synthesis coding, H264, AAC, MP3, IPP can use efficient space conversion image, and can use INTEL cuda hardware H264 codec 240 may be implemented 1080P real-time encoding, full synchronization and a high degree of smoothness, rtmp live push, rtmp server, YV12, YUV422, NV12, RGB24, RGB32 familiar with the conversion, scaling, codec wav, AAC, mp3, and video transition effects algorithms, video watermarking, LOGO, text. Video screen capture, video capture camera, a video image display The D3D efficient, OPENCV, image library ximage, GDI, GDIPLUS skilled application, a voice recognition and text conversion, recognition and matching, LAN remote control, real-time audio and video call, capture card playback, in addition to the SQL database, ACCESS, EXCEL database, DOC, PDF file open to extract, FTPServer, Client, all of the above codes have been commercial.

Ah ah ah ah ah ah ah ah ah ah ah ah ah ah ah, there has been no detailed statistics, that I have learned so many things, ah, I really admire his ah

 

 

Guess you like

Origin blog.csdn.net/xjb2006/article/details/85159676