Record

本文详细介绍了CRecord类的实现细节,包括初始化、消息处理、绘图、开始/停止录音等功能。通过源代码分析,展示了如何使用CRecord进行音频记录、回放及保存等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值