📄 filter.cpp
字号:
#include "stdafx.h"
#include "Filter.h"
#include <math.h>
CFilter::CFilter()
{
m_hWnd = NULL;
wBitsPerSample = 0;
}
CFilter::~CFilter()
{
m_MDC.DeleteDC();
}
void CFilter::Init(HWND hWnd,unsigned short wBits)
{
m_hWnd = hWnd;
wBitsPerSample = wBits;
m_MDC.CreateCompatibleDC (NULL);
brush.CreateSolidBrush(RGB(0,0,0));
pen.CreatePen (PS_SOLID,0,RGB(0,255,0));
GetClientRect(hWnd,&memrec);
}
int CFilter::Filter(char* pBuf)
{
if( m_hWnd == NULL || wBitsPerSample == 0 )
return -1;
BOOL bTalk = FALSE;
int x,y;
CBitmap m_bitmap;
CBitmap *m_pOldBitmap;
m_bitmap.CreateCompatibleBitmap(CDC::FromHandle (GetDC(m_hWnd)),memrec.Width (),memrec.Height ());
m_pOldBitmap =(CBitmap*)SelectObject(m_MDC.GetSafeHdc (),m_bitmap);
m_MDC.Rectangle (0,0,memrec.Width (),memrec.Height ());
oldpen = m_MDC.SelectObject (&pen);
m_MDC.FillRect(memrec,&brush);
DWORD size;
size = wBitsPerSample == 16 ? SIZE_AUDIO_FRAME/2 : SIZE_AUDIO_FRAME;
int yy = memrec.Height()/2;
m_MDC.MoveTo (0,yy);
int h=yy;
short sample;
for(int register i = 0 ; i <(long)size ; i++) //to draw first channel
{
sample = wBitsPerSample == 16 ? ((*((short*)pBuf+i))*h)/(65535/2) : ( (*((BYTE*)pBuf+i)-128)*h)/128;
x = int(((float)i/size)*(memrec.Width()));
y = yy-sample;
if( abs(sample) > 15 && !bTalk )
{
bTalk = TRUE;
}
m_MDC.LineTo (x,y);
}
m_MDC.SelectObject(oldpen);
CRect rc;
GetClientRect(m_hWnd,&rc);
StretchBlt(GetDC(m_hWnd),0,0,rc.Width (),rc.Height (),m_MDC.GetSafeHdc(),0,0,memrec.Width ()
,memrec.Height(),SRCCOPY);
if( bTalk )
return 1;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -