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

📄 envelop.cpp

📁 声音处理程序,通过FFT可以看声音的频谱.
💻 CPP
字号:
// Envelop.cpp : implementation file
//

#include "stdafx.h"
#include "vib.h"
//#include "Envelop.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEnvelop dialog


CEnvelop::CEnvelop(CWnd* pParent /*=NULL*/)
	: CDialog(CEnvelop::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEnvelop)
	//}}AFX_DATA_INIT
	m_szClient.cx=-1;
	m_szClient.cy=-1;
}


void CEnvelop::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEnvelop)
	DDX_Control(pDX, IDC_WAVEBUTTON, m_wave);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEnvelop, CDialog)
	//{{AFX_MSG_MAP(CEnvelop)
	ON_WM_DRAWITEM()
	ON_WM_DESTROY()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEnvelop message handlers

BOOL CEnvelop::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	int nAT;
	SIZE size;
	POINT point;
	CString s,str;

	theApp.m_pView->StopWave();

	size.cx=theApp.m_nDispMaxFreq;
	nAT=theApp.m_nDispFreqPlus;
	size.cy=nAT<0?-nAT*32767:32767/nAT;
	m_wave.SetCalcSize(size);

	point.x=-99999;point.y=0;
	m_wave.InsertPoint(point);

	str=theApp.m_strEnvelop+";";
	while((nAT=str.Find(";"))!=-1)
	{
		s=str.Left(nAT);
		str=str.Mid(nAT+1);

		point.x=atoi(s);
		point.y=atoi(s.Mid(s.Find('=')+1));
		m_wave.InsertPoint(point);
	}
	point.x=99999;point.y=0;
	m_wave.InsertPoint(point);
	
	CheckDlgButton(IDC_SENSITIVITY,theApp.m_bEnvelopSense);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CEnvelop::OnOK() 
{
	// TODO: Add extra validation here
	int i;
	CString str,s;
	for(i=1;i<m_wave.m_nPointCount-1;i++)
	{
		s.Format(";%d=%d",m_wave.m_pPoint[i].x,m_wave.m_pPoint[i].y);
		str+=s;
	}
	theApp.m_strEnvelop=str.Mid(1);
	theApp.m_bEnvelopSense=IsDlgButtonChecked(IDC_SENSITIVITY);

	theApp.ConfigOption(TRUE);
	theApp.ConfigOption(FALSE);
	theApp.SetPause(FALSE);
	CDialog::OnOK();
}

void CEnvelop::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);

	int i,x,y,p;
	int nWidth=m_wave.GetClientSize().cx;
	int nHeight=m_wave.GetClientSize().cy;
	double dScaleX,dScaleY;
	double* aWave=theApp.m_aFFTOut;
	CDC* pDC=m_wave.GetDC();
	CPen pen(PS_SOLID,1,RGB(255,0,0));
	CPen* pOldPen=pDC->SelectObject(&pen);

	dScaleX=1000.0/theApp.m_msWinFFT*nWidth/theApp.m_nDispMaxFreq;
	i=theApp.m_nDispFreqPlus;
	dScaleY=nHeight/32767.0;
	dScaleY=i<0?-dScaleY/i:dScaleY*i;
	p=theApp.m_nDispMaxFreq*theApp.m_msWinFFT/1000+1;
	for(i=0;i<p;i++)
	{
		x=(int)(i*dScaleX+0.5);
		y=nHeight-(int)(dScaleY*sqrt(aWave[i])+0.5);
		if(i)pDC->LineTo(x,y);else pDC->MoveTo(x,y);
	}

	pDC->SelectObject(pOldPen);
	m_wave.ReleaseDC(pDC);
	
}

void CEnvelop::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	theApp.m_pView->StartWave();
}

void CEnvelop::OnSize(UINT nType, int cx, int cy) 
{
	
	CDialog::OnSize(nType, cx, cy);
	// TODO: Add your message handler code here

	int cx0,cy0;
	CWnd* pWnd;
	CRect rect;

	cx0=m_szClient.cx;
	cy0=m_szClient.cy;
	m_szClient.cx=cx;
	m_szClient.cy=cy;
	if(cx0==-1 && cy0==-1)return;

	m_wave.m_ClientSize.cx=-1;
	m_wave.m_ClientSize.cy=-1;

	pWnd=GetDlgItem(IDC_WAVEBUTTON);
	pWnd->GetWindowRect(rect);
	ScreenToClient(rect);
	rect.right+=cx-cx0;
	rect.bottom+=cy-cy0;
	pWnd->MoveWindow(rect);

	pWnd=GetDlgItem(IDC_SENSITIVITY);
	pWnd->GetWindowRect(rect);
	ScreenToClient(rect);
	rect.bottom+=cy-cy0;
	rect.top+=cy-cy0;
	pWnd->MoveWindow(rect);

	pWnd=GetDlgItem(IDOK);
	pWnd->GetWindowRect(rect);
	ScreenToClient(rect);
	rect.right+=cx-cx0;
	rect.bottom+=cy-cy0;
	rect.left+=cx-cx0;
	rect.top+=cy-cy0;
	pWnd->MoveWindow(rect);

	pWnd=GetDlgItem(IDCANCEL);
	pWnd->GetWindowRect(rect);
	ScreenToClient(rect);
	rect.right+=cx-cx0;
	rect.bottom+=cy-cy0;
	rect.left+=cx-cx0;
	rect.top+=cy-cy0;
	pWnd->MoveWindow(rect);
}

⌨️ 快捷键说明

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