Record.cpp : implementation file
//
#include "stdafx.h"
#include "mmsystem.h"
#include "math.h"
#include "Record.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CRecord
CRecord::CRecord()
{
buffer = new short[cbhrecord.tbsize];
ibuf = cbhrecord.ibuf;
bsize = cbhrecord.bsize;
readsize = 0;
havestoped = 1;
}
CRecord::~CRecord()
{
}
BEGIN_MESSAGE_MAP(CRecord, CWnd)
//{{AFX_MSG_MAP(CRecord)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
ON_MESSAGE(MM_WIM_DATA, OnRecord)
END_MESSAGE_MAP()
/
// CRecord message handlers
LRESULT CRecord::OnRecord(WPARAM wp, LPARAM lp)
{
if(havestoped)
return 0;
int i=GetDlgCtrlID();
if(cbhrecord.resycle(lp))
{
readsize = cbhrecord.rsize;
memcpy(buffer,cbhrecord.tbuffer, readsize*2);
havestoped = 1;
if(i)
GetParent()->SendMessage(WM_COMMAND, i,1);
return 0;
}
noiselevel = cbhrecord.noiselevel;
if(i)
GetParent()->SendMessage(WM_COMMAND, i,0);
Invalidate(FALSE);
//m_noiselevel.Format("声音电平:%f",record->noiselevel);
//UpdateData(FALSE);
return 0;
}
int CRecord::start()
{
if(!havestoped)
return 0;
havestoped = 0;
cbhrecord.start(m_hWnd);
return 0;
}
int CRecord::stop()
{
cbhrecord.stop();
//readsize = cbhrecord.rsize;
havestoped = 1;
memset(ibuf,0,bsize*2);
Invalidate(FALSE);
return 0;
}
int CRecord::replay()
{
if(!havestoped)
return 0;
myplaysound(buffer, readsize);
return 0;
}
void CRecord::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CBrush bb(NULL_BRUSH);
CRect rcClient;
GetClientRect(&rcClient);
dc.FillRect(rcClient, &bb);
CPoint * point;
point = new CPoint[bsize];
CPen bluepen(PS_SOLID, 1, RGB(0,0,255));
CPen *poldpen=NULL;
poldpen = dc.SelectObject(&bluepen);
for(DWORD i=0; i<bsize; i++){
point[i].x=(i*rcClient.Width())/bsize;
point[i].y=((ibuf[i]+32768)*rcClient.Height())/65536;
}
dc.Polyline(point,bsize);
dc.SelectObject(poldpen);
// Do not call CWnd::OnPaint() for painting messages
}
BOOL CRecord::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return CWnd::OnEraseBkgnd(pDC);
}
int CRecord::save()
{
if(!havestoped)
return 0;
if(readsize==0)
return 0;
static char BASED_CODE szFilter[]="声音文件(*.wav)|*.wav|所有文件(*.*)|*.*||";
CFileDialog dlg(FALSE, "wav", NULL, OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT, szFilter,NULL);
if(dlg.DoModal()==IDOK)
{
makewave(dlg.GetPathName(), buffer, readsize);
return 1;
}
return 0;
}
int CRecord::open()
{
if(!havestoped)
return 0;
static char BASED_CODE szFilter[]="声音文件(*.wav)|*.wav|所有文件(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT, szFilter,NULL);
if(dlg.DoModal()==IDOK) {
readsize=readwave(dlg.GetPathName(), buffer, cbhrecord.tbsize);
return 1;
}
return 0;
}