Filter.cpp
上传用户:amei960
上传日期:2007-02-05
资源大小:143k
文件大小:2k
- #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;
- }