|
|
Hi,
here is some copy-and-paste code:
CBitmap* CMyDialog::ZoomBitmap(CBitmap* pBitmap, const CRect& FitInto)
{
if (FitInto.IsRectEmpty()) return 0;
CRect bmpRect = doGetBitmapRect(pBitmap);
if (bmpRect.IsRectEmpty()) return 0;
CRect zoomedRect = doGetZoomedBitmapRect(pBitmap, FitInto);
if (zoomedRect.IsRectEmpty()) return 0;
CDC* pDC = GetDC();
if (pDC == 0) return 0;
CDC* memDC1 = new CDC;
if (memDC1->CreateCompatibleDC(pDC) == 0)
{
delete memDC1;
ReleaseDC(pDC);
return 0;
}
CDC* memDC2 = new CDC;
if (memDC2->CreateCompatibleDC(pDC) == 0)
{
delete memDC1;
delete memDC2;
ReleaseDC(pDC);
return 0;
}
CBitmap* zoomed = new CBitmap;
if (zoomed->CreateCompatibleBitmap(pDC, zoomedRect.Width(), zoomedRect.Height()) == 0)
{
delete memDC1;
delete memDC2;
delete zoomed;
ReleaseDC(pDC);
return 0;
}
ReleaseDC(pDC);
CBitmap* old1 = memDC1->SelectObject(pBitmap);
CBitmap* old2 = memDC2->SelectObject(zoomed);
memDC2->SetStretchBltMode(HALFTONE);
BOOL result = memDC2->StretchBlt
(
0,
0,
zoomedRect.Width(),
zoomedRect.Height(),
memDC1,
0,
0,
bmpRect.Width(),
bmpRect.Height(),
SRCCOPY
);
if (result == FALSE)
{
delete zoomed;
zoomed = 0;
}
memDC2->SelectObject(old2);
memDC1->SelectObject(old1);
delete memDC2;
delete memDC1;
return zoomed;
}
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
Looks good! But you should eliminate all thoses unneeded news. The only new required by your code is that used to allocate zoomed. If any one of the news (except the first one) was to throw an exception, your code would leak memory.
If you modified the code to take another CBitmap argument to store the results, then you could elimimate all allocation. That way the user of the ZoomBitmap function would not need to know that they are responsible for deleting the returned pointer via delete, unles they had allocated it themselfs.
Exmaple:
BOOL ZoomBitmap(Bitmap& zoomed, Bitmap& srcBitmap, const CRect& FitInto )
{...}<br>
void OnZoom()
{
CBitmap zoomed;
if( ZoomBitmap(zoomed,srcBitmap,FitInto) )
}
Oh well, just some minor observations...
INTP
Every thing is relative...
|
|
|
|
|
hi
how to search for a specific file in folder using VC++?
i have searched CFile class but didn't get the idea.
Thanx in advance
|
|
|
|
|
|
|
my project is get the signal from pc mic to pc. below is one of the Cwavein class. i wan to read buffer to display graph and do signal processing. could anyone help me how to read the buffer? and i wan use 2dpushgraph that is in code project to display my graph. the statement is m_pushgraph.push(a,b),a is the magnitude in the buffer. b is how many line i wan display. could anyone tell me what magnitude should i put, how can i knw the magnitude(shw me example of programming), and should i put all the magnitude or jst push one magnitude and use looping for it and buffer will automatically get the data one by one in the array.thx for ur help.
// WaveIn.cpp: implementation of the CWaveIn class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "xxx.h"
#include "WaveIn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CWaveIn, CWinThread)
CWaveIn::CWaveIn(int iHertz)
{
memset(&m_WaveFormatEx,0x00,sizeof(m_WaveFormatEx)); // set the memory content to all zeros
// configure the audio input record format
m_WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; // Pulse Code Modulation
m_WaveFormatEx.nChannels = 1; // mono
m_WaveFormatEx.wBitsPerSample = 16; // 16-bit/sample
m_WaveFormatEx.cbSize = 0;
m_WaveFormatEx.nSamplesPerSec = iHertz; // sampling freq = 44.1kHz
m_WaveFormatEx.nAvgBytesPerSec = m_WaveFormatEx.nSamplesPerSec*(m_WaveFormatEx.wBitsPerSample/8);
m_WaveFormatEx.nBlockAlign = (m_WaveFormatEx.wBitsPerSample/8)*m_WaveFormatEx.nChannels;
// initialize indicators
m_bAudioIn = FALSE;
m_bRecording = FALSE;
// initialize pointers to NULL
m_ptrWaveOut = NULL;
m_ptrWaveFile = NULL;
}
CWaveIn::~CWaveIn()
{
}
BOOL CWaveIn::InitInstance()
{
// TODO: perform any per-thread initializetion here
return TRUE;
}
int CWaveIn::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CWaveIn, CWinThread)
//{{AFX_MSG_MAP(CWaveIn)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_WAVEIN_START, StartWaveIn)
ON_THREAD_MESSAGE(WM_WAVEIN_STOP, StopWaveIn)
ON_THREAD_MESSAGE(MM_WIM_DATA, OnAudioInputBufferFull)
ON_THREAD_MESSAGE(WM_WAVEIN_ENDTHREAD, OnEndThread)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEOUT, OnPtrWaveOut)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEFILE, OnPtrWaveFile)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////
// create pointer to CWaveOut
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveOut(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveOut = (CWaveOut*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// create pointer to CWaveFile
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveFile(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveFile = (CWaveFile*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// open audio input device
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::StartWaveIn(WPARAM wParam, LPARAM lParam)
{
DWORD mmReturn = 0; // return parameter for multimedia devices
if(m_bAudioIn) // if MIC is already ON, then no need to ON it again.
return FALSE;
if(!m_bAudioIn)
{
// Open AudioInDevice
MMRESULT mmReturn = ::waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_WaveFormatEx, ::GetCurrentThreadId(),0,CALLBACK_THREAD);
// if failed to open AudioInDevice
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if success opening the AudioInDevice
if(!mmReturn)
{
AllocateBuffers(MAXINPUTBUFFERS);
mmReturn = ::waveInStart(m_hWaveIn);// start sampling
// if start sampling failed
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if start sampling success
if(!mmReturn)
{
m_bAudioIn = TRUE; // indicate successfully open the AudioInDevice for sampling
// if the pointer to CWaveOut is available
// send thread to Open the AudioOutDevice at CWaveOut
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_START,0,0);
// need to modify here,
// do not create the file here,
// create the file in CWaveFile
// NOTE: the pointer m_ptrWaveOut & m_ptrWaveFile is obtained while program initialized.
// now we need to modify so that the
// m_ptrWaveFile is only create by
// a thread sent by CWaveFile
//
// so we can also use it as flag to indicate
// whether the recording is started...
// if the pointer to CWaveFile is available
//if(m_ptrWaveFile)
//{
// PWAVEFILE pwsf= (PWAVEFILE) new WAVEFILE;
// ZeroMemory(pwsf,sizeof(WAVEFILE));
// char *p = pwsf->lpszFileName;
// strcpy(p,"sound.wav"); // .wav filename, under the same directory
// memcpy(&pwsf->waveFormatEx,&m_WaveFormatEx,sizeof(m_WaveFormatEx));
// // send thread to create the file at CWaveFile
// m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CREATE,0,(LPARAM)pwsf);
//}
return ERROR_SUCCESS;
}
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// close audio input device
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::StopWaveIn(WPARAM wParam, LPARAM lParam)
{
MMRESULT mmReturn = 0; // return parameter for multimedia device
// if MIC already close, then no need to close again
if(!m_bAudioIn)
return FALSE;
// if MIC is ON, then close it...
if(m_bAudioIn)
{
mmReturn = ::waveInStop(m_hWaveIn); // stop sampling process
if(!mmReturn)
mmReturn = ::waveInReset(m_hWaveIn);
FreeSpareBuffers(); // clean up all buffers
if(!mmReturn)
m_bAudioIn = FALSE; // indicate AudioOutDevice now Close.
Sleep(500);
if(!mmReturn)
mmReturn = ::waveInClose(m_hWaveIn); // close AudioInDevice
// if pointer to AudioOutDevice exist,
// send thread to close the device
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_STOP,0,0);
// if pointer to CWaveFile exist,
// send thread to close the file.
//if(m_ptrWaveFile)
//m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CLOSE,0,0);
return mmReturn;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// response to MM_WIM_DATA
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnAudioInputBufferFull(WPARAM wParam, LPARAM lParam)
{
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) lParam; // receive the return buffer
// if the buffer is not empty
if(lpWaveHdr)
{
BYTE * lpInt = (BYTE*) lpWaveHdr->lpData; // retrieve the audio data
DWORD iRecorded = lpWaveHdr->dwBytesRecorded; // get how many bytes recorded
/* TRACE("\n Data length %d",iRecorded);
AfxMessageBox("");
int *p = (int*)lpInt;
for(int i=0; i<irecorded; i++)
="" trace("\n="" data="" is="" %d",="" p[i]);*=""
="" ::waveinunprepareheader(m_hwavein,="" lpwavehdr,="" sizeof(wavehdr));
="" perform="" input="" signal="" processing="" here,="" i.e.:="" low="" pass="" filter
="" processsounddata(lpint,="" irecorded="" sizeof(byte));
="" if="" pointer="" to="" cwavefile="" exist,
="" send="" thread="" write="" into="" it...
="" if(m_ptrwavefile)
="" {
="" wavehdr*="" pwritehdr="new" wavehdr;
="" if(!pwritehdr)
="" return="" false;
="" memcpy(pwritehdr,lpwavehdr,sizeof(wavehdr));
="" byte="" *="" psound="new" byte[lpwavehdr-="">dwBufferLength];
if(!pSound)
{
delete pWriteHdr;
return FALSE;
}
memcpy(pSound,lpWaveHdr->lpData,lpWaveHdr->dwBufferLength);
pWriteHdr->lpData = (char*)pSound;
// send thread to write to file
m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_WRITE,GetCurrentThreadId(),(LPARAM) pWriteHdr);
}
// if pointer to CWaveOut exist,
// send thread to echo the audio.
if(m_ptrWaveOut)
{
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_WRITE, GetCurrentThreadId(),(LPARAM) lpWaveHdr);
}
else
{
delete lpInt;
delete lpWaveHdr;
}
char debugbuffer[256];
sprintf(debugbuffer, "SOUND BUFFER returned: %d\n",iRecorded);
TRACE(debugbuffer);
if(m_bAudioIn)
{
AllocateBuffers(1);
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// perform clean up
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnEndThread(WPARAM wParam, LPARAM lParam)
{
if(m_bAudioIn)
{
StopWaveIn(0, 0);
}
::PostQuitMessage(0);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// prepare & send the buffer to audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::AllocateBuffers(int nBuffers)
{
int i;
for(i=0; i < nBuffers; i++)
{
LPWAVEHDR lpWaveHdr = CreateWaveHeader();
::waveInPrepareHeader(m_hWaveIn,lpWaveHdr, sizeof(WAVEHDR));
::waveInAddBuffer(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
}
}
///////////////////////////////////////////////////////////////////
// create wave buffer header
///////////////////////////////////////////////////////////////////
LPWAVEHDR CWaveIn::CreateWaveHeader()
{
LPWAVEHDR lpWaveHdr = new WAVEHDR;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
BYTE* lpByte = new BYTE[(m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES)];
lpWaveHdr->lpData = (char *) lpByte;
lpWaveHdr->dwBufferLength = (m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES);
return lpWaveHdr;
}
///////////////////////////////////////////////////////////////////
// free the buffers remained audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::FreeSpareBuffers()
{
MSG msg;
Sleep(20);
while(::PeekMessage(&msg,NULL,MM_WIM_OPEN,MM_WIM_DATA,PM_REMOVE))
{
if(msg.wParam == MM_WIM_OPEN || msg.wParam == MM_WIM_CLOSE)
continue;
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) msg.lParam;
if(lpWaveHdr)
{
BYTE * lpByte = (BYTE*) lpWaveHdr->lpData;
::waveInUnprepareHeader(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
if(lpByte)
delete lpByte;
delete lpWaveHdr;
}
}
}
void CWaveIn::ClearPtrWaveFile()
{
m_ptrWaveFile = NULL;
}
IMPLEMENT_DYNCREATE(CWaveIn, CWinThread)
CWaveIn::CWaveIn(int iHertz)
{
memset(&m_WaveFormatEx,0x00,sizeof(m_WaveFormatEx)); // set the memory content to all zeros
// configure the audio input record format
m_WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; // Pulse Code Modulation
m_WaveFormatEx.nChannels = 1; // mono
m_WaveFormatEx.wBitsPerSample = 16; // 16-bit/sample
m_WaveFormatEx.cbSize = 0;
m_WaveFormatEx.nSamplesPerSec = iHertz; // sampling freq = 44.1kHz
m_WaveFormatEx.nAvgBytesPerSec = m_WaveFormatEx.nSamplesPerSec*(m_WaveFormatEx.wBitsPerSample/8);
m_WaveFormatEx.nBlockAlign = (m_WaveFormatEx.wBitsPerSample/8)*m_WaveFormatEx.nChannels;
// initialize indicators
m_bAudioIn = FALSE;
m_bRecording = FALSE;
// initialize pointers to NULL
m_ptrWaveOut = NULL;
m_ptrWaveFile = NULL;
}
CWaveIn::~CWaveIn()
{
}
BOOL CWaveIn::InitInstance()
{
// TODO: perform any per-thread initializetion here
return TRUE;
}
int CWaveIn::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CWaveIn, CWinThread)
//{{AFX_MSG_MAP(CWaveIn)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_WAVEIN_START, StartWaveIn)
ON_THREAD_MESSAGE(WM_WAVEIN_STOP, StopWaveIn)
ON_THREAD_MESSAGE(MM_WIM_DATA, OnAudioInputBufferFull)
ON_THREAD_MESSAGE(WM_WAVEIN_ENDTHREAD, OnEndThread)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEOUT, OnPtrWaveOut)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEFILE, OnPtrWaveFile)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////
// create pointer to CWaveOut
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveOut(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveOut = (CWaveOut*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// create pointer to CWaveFile
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveFile(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveFile = (CWaveFile*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// open audio input device
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::StartWaveIn(WPARAM wParam, LPARAM lParam)
{
DWORD mmReturn = 0; // return parameter for multimedia devices
if(m_bAudioIn) // if MIC is already ON, then no need to ON it again.
return FALSE;
if(!m_bAudioIn)
{
// Open AudioInDevice
MMRESULT mmReturn = ::waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_WaveFormatEx, ::GetCurrentThreadId(),0,CALLBACK_THREAD);
// if failed to open AudioInDevice
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if success opening the AudioInDevice
if(!mmReturn)
{
AllocateBuffers(MAXINPUTBUFFERS);
mmReturn = ::waveInStart(m_hWaveIn);// start sampling
// if start sampling failed
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if start sampling success
if(!mmReturn)
{
m_bAudioIn = TRUE; // indicate successfully open the AudioInDevice for sampling
// if the pointer to CWaveOut is available
// send thread to Open the AudioOutDevice at CWaveOut
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_START,0,0);
// need to modify here,
// do not create the file here,
// create the file in CWaveFile
// NOTE: the pointer m_ptrWaveOut & m_ptrWaveFile is obtained while program initialized.
// now we need to modify so that the
// m_ptrWaveFile is only create by
// a thread sent by CWaveFile
//
// so we can also use it as flag to indicate
// whether the recording is started...
// if the pointer to CWaveFile is available
//if(m_ptrWaveFile)
//{
// PWAVEFILE pwsf= (PWAVEFILE) new WAVEFILE;
// ZeroMemory(pwsf,sizeof(WAVEFILE));
// char *p = pwsf->lpszFileName;
// strcpy(p,"sound.wav"); // .wav filename, under the same directory
// memcpy(&pwsf->waveFormatEx,&m_WaveFormatEx,sizeof(m_WaveFormatEx));
// // send thread to create the file at CWaveFile
// m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CREATE,0,(LPARAM)pwsf);
//}
return ERROR_SUCCESS;
}
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// close audio input device
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::StopWaveIn(WPARAM wParam, LPARAM lParam)
{
MMRESULT mmReturn = 0; // return parameter for multimedia device
// if MIC already close, then no need to close again
if(!m_bAudioIn)
return FALSE;
// if MIC is ON, then close it...
if(m_bAudioIn)
{
mmReturn = ::waveInStop(m_hWaveIn); // stop sampling process
if(!mmReturn)
mmReturn = ::waveInReset(m_hWaveIn);
FreeSpareBuffers(); // clean up all buffers
if(!mmReturn)
m_bAudioIn = FALSE; // indicate AudioOutDevice now Close.
Sleep(500);
if(!mmReturn)
mmReturn = ::waveInClose(m_hWaveIn); // close AudioInDevice
// if pointer to AudioOutDevice exist,
// send thread to close the device
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_STOP,0,0);
// if pointer to CWaveFile exist,
// send thread to close the file.
//if(m_ptrWaveFile)
//m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CLOSE,0,0);
return mmReturn;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// response to MM_WIM_DATA
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnAudioInputBufferFull(WPARAM wParam, LPARAM lParam)
{
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) lParam; // receive the return buffer
// if the buffer is not empty
if(lpWaveHdr)
{
BYTE * lpInt = (BYTE*) lpWaveHdr->lpData; // retrieve the audio data
DWORD iRecorded = lpWaveHdr->dwBytesRecorded; // get how many bytes recorded
/* TRACE("\n Data length %d",iRecorded);
AfxMessageBox("");
int *p = (int*)lpInt;
for(int i=0; i<irecorded; i++)
="" trace("\n="" data="" is="" %d",="" p[i]);*=""
="" ::waveinunprepareheader(m_hwavein,="" lpwavehdr,="" sizeof(wavehdr));
="" perform="" input="" signal="" processing="" here,="" i.e.:="" low="" pass="" filter
="" processsounddata(lpint,="" irecorded="" sizeof(byte));
="" if="" pointer="" to="" cwavefile="" exist,
="" send="" thread="" write="" into="" it...
="" if(m_ptrwavefile)
="" {
="" wavehdr*="" pwritehdr="new" wavehdr;
="" if(!pwritehdr)
="" return="" false;
="" memcpy(pwritehdr,lpwavehdr,sizeof(wavehdr));
="" byte="" *="" psound="new" byte[lpwavehdr-="">dwBufferLength];
if(!pSound)
{
delete pWriteHdr;
return FALSE;
}
memcpy(pSound,lpWaveHdr->lpData,lpWaveHdr->dwBufferLength);
pWriteHdr->lpData = (char*)pSound;
// send thread to write to file
m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_WRITE,GetCurrentThreadId(),(LPARAM) pWriteHdr);
}
// if pointer to CWaveOut exist,
// send thread to echo the audio.
if(m_ptrWaveOut)
{
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_WRITE, GetCurrentThreadId(),(LPARAM) lpWaveHdr);
}
else
{
delete lpInt;
delete lpWaveHdr;
}
char debugbuffer[256];
sprintf(debugbuffer, "SOUND BUFFER returned: %d\n",iRecorded);
TRACE(debugbuffer);
if(m_bAudioIn)
{
AllocateBuffers(1);
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// perform clean up
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnEndThread(WPARAM wParam, LPARAM lParam)
{
if(m_bAudioIn)
{
StopWaveIn(0, 0);
}
::PostQuitMessage(0);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// prepare & send the buffer to audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::AllocateBuffers(int nBuffers)
{
int i;
for(i=0; i < nBuffers; i++)
{
LPWAVEHDR lpWaveHdr = CreateWaveHeader();
::waveInPrepareHeader(m_hWaveIn,lpWaveHdr, sizeof(WAVEHDR));
::waveInAddBuffer(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
}
}
///////////////////////////////////////////////////////////////////
// create wave buffer header
///////////////////////////////////////////////////////////////////
LPWAVEHDR CWaveIn::CreateWaveHeader()
{
LPWAVEHDR lpWaveHdr = new WAVEHDR;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
BYTE* lpByte = new BYTE[(m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES)];
lpWaveHdr->lpData = (char *) lpByte;
lpWaveHdr->dwBufferLength = (m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES);
return lpWaveHdr;
}
///////////////////////////////////////////////////////////////////
// free the buffers remained audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::FreeSpareBuffers()
{
MSG msg;
Sleep(20);
while(::PeekMessage(&msg,NULL,MM_WIM_OPEN,MM_WIM_DATA,PM_REMOVE))
{
if(msg.wParam == MM_WIM_OPEN || msg.wParam == MM_WIM_CLOSE)
continue;
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) msg.lParam;
if(lpWaveHdr)
{
BYTE * lpByte = (BYTE*) lpWaveHdr->lpData;
::waveInUnprepareHeader(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
if(lpByte)
delete lpByte;
delete lpWaveHdr;
}
}
}
void CWaveIn::ClearPtrWaveFile()
{
m_ptrWaveFile = NULL;
}
|
|
|
|
|
There is an article in the audio section on building and dusplaying "peak files". A peak file is the bit representation of your waveform. The same code shows to display it.
Bill Dennis
Orlando, FL
|
|
|
|
|
Hi,
I have two questions:
1. What does KEY_EXECUTE access mode do to a registry key while opening/creating it?
2. MSDN talks about RegDeleteKeyEx, but it doesnt seem to be defined in VS6 or Platform SDK. Does anyone know more about this API?
Thanks.
|
|
|
|
|
KEY_EXECUTE is equivalent to KEY_READ.
Msdn says:
RegDeleteKeyEx
Client: Requires Windows "Longhorn" or Windows XP Professional x64 Edition.
Server: Requires Windows Server "Longhorn" or Windows Server 2003 SP1.
It is not in VS6. I guess it needs the newest Platform SDK, maybe even the one not compatible with VS6.
this is this.
|
|
|
|
|
Thank you.
Do you know how to obtain the MAXIMUM_ALLOWED access mode for the current user? I want to what MAXIMUM_ALLOWED ultimately maps to.
|
|
|
|
|
|
How to debug through the code in an activeX control.
aasstt
|
|
|
|
|
Depends on the program using the control.
1- You can develop a test application, which uses the Control and set it as the "Executable for debug session"
2- You can use the ActiveX Control Test Container as the "Executable for debug session" in Visual Studio Project Settings.
3- If you are developing the control for use in Internet Explorer, then set iexplore.exe as the executable for debug session.
Place breakpoints in your code, then F5 (Go) it.
this is this.
|
|
|
|
|
First, I am new to C++. I have some C background with DOS and Unix but that was 15 years ago. My most recent work was vb.net. I am now doing some audio based coding in VC++ and I am having some problems, probably from my lack of knowledge. Unfortunately, I have until Monday to get this code working...
I have three classes and three separate files. The developer that started this is simply calling the classes without reinstantiating them.
I am reading a wave file in and that works fine. But, I need to create a global buffer for the wave data so that the other two classes can access it or find someway to pass the buffer by references to the other classes' functions.
Can anyone give me some same code on doing this? Thank you.
Bill Dennis
Orlando, FL
|
|
|
|
|
Create a class for the global data buffer.
Put it in a separate header file.
class CGlobalData<br />
{<br />
static [DATA_TYPE_HERE] m_Data;<br />
};
Then use it as:
CGlobalData::m_Data;
this is this.
|
|
|
|
|
I did as you suggested and am etting the following error:
c:\development\c-tools\Classes\WavWrite.cpp(79): error C2248: 'CReadDemoWave::testinteger' : cannot access private member declared in class 'CReadDemoWave'
I need to be able to access this data from three separate .cpp files.
Here's my 'h:
\
class CReadDemoWave
{ static int testinteger;
public:
void ReadDemoWave();
void ReadDemoIntoBuffer();
void PlayWav();
long QueueWaveData(HWAVEOUT HWaveOut, WAVEHDR * waveHeader,
DWORD WaveDataPlayed, DWORD WaveBufSize, HMMIO HMmio);
LPSTR *GetDemoBuffer(void);
void WriteDemo(HMMIO recordHandle);
WAVEHDR lpDemoData;
DWORD dwDemoDataSize;
int m_nDemoBufferSize;
BYTE* m_pbyDemoBuffer;
HMMIO m_hmmio;
};
I am including the .h in all three .cpp files. Am I doing something wrong?
Bill Dennis
Orlando, FL
|
|
|
|
|
Sorry about that.
You need to make the variable public. By default it is private.
Just write public: before the variable declaration in the class. Like:
class CSomething<br />
{<br />
public:
static DATA_TYPE m_Data;<br />
<br />
};
this is this.
|
|
|
|
|
I'm sorry but now I get the following message:
Single error LNK2001: unresolved external symbol "public: static int CReadDemoWave::testinteger" (?testinteger@CReadDemoWave@@2HA)
Here is my .h:
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#define ERROR_LENGTH 1024
class CReadDemoWave
{
public:
static int testinteger;
void ReadDemoWave();
void ReadDemoIntoBuffer();
void PlayWav();
long QueueWaveData(HWAVEOUT HWaveOut, WAVEHDR * waveHeader,
DWORD WaveDataPlayed, DWORD WaveBufSize, HMMIO HMmio);
LPSTR *GetDemoBuffer(void);
void WriteDemo(HMMIO recordHandle);
// =========== D == E == M == O =======================
// BD create demo buffer.
WAVEHDR lpDemoData;
DWORD dwDemoDataSize;
int m_nDemoBufferSize;
BYTE* m_pbyDemoBuffer;
HMMIO m_hmmio;
//HMMIO hmmio;
char m_szError[ERROR_LENGTH];
int m_nError;
MMIOINFO m_mmioInfo;
DWORD dwDataSize;
DWORD dwCount;
HPSTR m_hptr;
int m_nBufferSize;
};
Bill Dennis
Orlando, FL
|
|
|
|
|
Hi,
the problem here is that the definition is missing.
Guess your header file (ReadDemoWave.h) looks like this:
class CReadDemoWave
{
public:
private:
static int m_anyInt;
};
Then you have to add the definition of m_anyInt to your cpp file:
#include "ReadDemoWave.h"
int CReadDemoWave::m_anyInt;
CReadDemoWave::CReadDemoWave()
{
}
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
Hi,
in my opinion it is always worth an attempt to get around global data.
Maybe this design pattern (Visitor) can help you.
The class that can read wave files:
class IveGotTheData
{
public:
bool ReadWaveFile(const char* Path);
void UseMyData(IknowTheAlgorithm& Operator)
{
Operator.Operate(this);
}
};
The base class for all algorithms that modify your wave data (the Visitor):
class IknowTheAlgorithm
{
public:
virtual void Operate(IveGotTheData* Data) = 0;
};
Your first algorithm is encapsulated in this class:
class Algorithm1 : public IknowTheAlgorithm
{
public:
virtual void Operate(IveGotTheData* Data)
{
}
};
Your second algorithm is encapsulated in this class:
class Algorithm2 : public IknowTheAlgorithm
{
public:
virtual void Operate(IveGotTheData* Data)
{
}
};
Using your algorithms looks like this:
void main()
{
IveGotTheData wav;
if (wav.ReadWaveFile("Test.wav"))
{
Algorithm1 alg1;
Algorithm2 alg2;
wav.UseMyData(alg1);
wav.UseMyData(alg2);
}
}
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
This would be good if it were a new system or code already written in this fashion but I am modifying someone else's code, so I can';t totally rewrite the program. But, thanks.
Bill Dennis
Orlando, FL
|
|
|
|
|
Hi,
could you post the three header files, please ?
Maybe <pre> code </pre> is useful.
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
// WavWrite.h: interface for the CWavWrite class.
#if !defined(AFX_WAVWRITE_H__2C400A28_DDC3_11D0_9FD3_444553540001__INCLUDED_)
#define AFX_WAVWRITE_H__2C400A28_DDC3_11D0_9FD3_444553540001__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
//#include "readdemowave.h"
#define ERROR_LENGTH 1024
//CReadDemoWave cReadDemo;
//static DWORD dwDemoDataSize;
//WAVEHDR lpDemoData;
//static WAVEHDR lpDemoData;
/* Definition from MS
typedef struct {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX;
typedef struct {
FOURCC ckid;
DWORD cksize;
FOURCC fccType;
DWORD dwDataOffset;
DWORD dwFlags;
} MMCKINFO;
*/
class CWavWrite
{
private:
char m_szName[FILENAME_MAX];
HMMIO m_hmmioFile;
HMMIO m_hmmioDemoFile;
MMCKINFO m_ckRIFF, m_ckfmt, m_ckdata;
int m_nDataLeft;
WAVEFORMATEX *m_pwfx;
PCMWAVEFORMAT m_pcmWaveFormat;
int m_cbExtraAlloc;
MMIOINFO m_mmioInfo;
// BD 9/13/05
/*int DEMO;
int rndcnt;
int bufcnt;*/
// Created here so not created each time Read or Write Data is called
// Otherwise these could be local variables - trade speed for size
int m_nCopyLength, m_nActualWrite;
int m_i;
// Error variables
int m_nError;
char m_szError[ERROR_LENGTH];
public:
//WAVEHDR lpDemoData;
//DWORD dwDemoDataSize;
// Constructor (empty) / Destructor
CWavWrite();
virtual ~CWavWrite();
// Data processing - too large to be effective as an inline functions
// BD added lat param for demo buffer
//int Write(BYTE *pBuffer, int nDataSize, WAVEHDR *pDemoBuffer);
int Write(BYTE *pBuffer, int nDataSize);
void WriteDemo(BYTE *pBuffer, int nDataSize);
// File Manipulation
void Open(void);
void Init(MMCKINFO *pckRIFF, MMCKINFO *pckfmt, MMCKINFO *pckdata,
WAVEFORMATEX *pwfx, int nBufferSize);
void Init(short wBitsPerSample, int nSampleFrequency, short wChannels, int nBufferSize);
void Close(void);
// Parameter Manipulation
void SetName(char *);
char *GetName(void);
// Parameters below may be different than input file, CWavRead.
long GetNumberOfSamples(void);
long GetSampleFrequency(void);
short GetBitsPerSample(void);
short GetNumberOfChannels(void);
MMCKINFO *GetckRIFF(void);
MMCKINFO *Getckfmt(void);
MMCKINFO *Getckdata(void);
WAVEFORMATEX *GetWaveFormatEx(void);
WAVEFORMATEX *DEMOfmt;
// Error Handling
int IsError(void) { return m_nError; };
char *GetError(void) { return m_szError; };
// Demo file
int DEMOWrite(void);
int GetStruct(HMMIO);
int ConvertWav(HMMIO);
};
#endif // !defined(AFX_WAVWRITE_H__2C400A28_DDC3_11D0_9FD3_444553540001__INCLUDED_)
////////////////////////////////////////////////////////////////////////////////
// SingleDlg.h : header file
#if !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_)
#define AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "AboutDlg.h"
#include "SingleAlg.h"
#include "StaticButton.h"
#include "ToolTipCtrlAdv.h"
#include "WavWrite.h"
#include "WavRecord.h"
#include "Presets.h"
#include "SettingsDlg.h"
#include "LedMeter.h"
#include "LedDriver.h"
#include "WavRead.h"
//#include "PaletteFromDIB.h"
// #include "Convert.h" //CONVERT
#include "ReadDemoWave.h"
// Shareware stuff
#include "SharewareDlg.h"
#define REG_FILE_NAME "aisin.rg"
#define REG_DAYS 45
#define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0]))
// Audio stuff
//#define LARGEST_BUFFER_SIZE 65536; //352800 // 2 sec at 44.1k 16 bit stereo
//#define NUMBER_OF_BUFFERS 4 // Not needed when using end of gap
#define WM_USER_THREAD_RECORD_FINISHED (WM_APP + 1)
#define WM_USER_NONSTATIC_THREAD_RECORD_UI (WM_APP + 2)
/////////////////////////////////////////////////////////////////////////////
// CSingleDlg dialog
struct THREADPARMS_RECORD
{
CWnd *pWnd;
CSingleAlg *pckSingleAlg;
CWavWrite *pWavWrite;
CWavRecord *pWavRecord;
CReadDemoWave *pReadDemo;
BYTE *pbyBuffer;
int *pnBufferSize;
// put demo buffer here and load it prior to record?
// BD &&& demo buffer
//WAVEHDR lpDemoData;
//DWORD dwDemoDataSize;
BYTE *pDemoBuffer;
int *pnDemoBufferSize;
CString *pstrCurFile;
CString *pstrCurFilePath;
CEvent *pEvent;
CCriticalSection *pCriticalSection;
int *pnStop;
};
class CSingleDlg : public CDialog
{
protected:
// Program variables
CSingleAlg m_ckSingleAlg;
CWavWrite m_cWavWrite;
CWavRecord m_cWavRecord;
CEvent m_cEventRecord;
CCriticalSection m_cCriticalSection;
HANDLE m_hThreadRecord;
THREADPARMS_RECORD m_threadParmsRecord;
int m_nIsRecording, m_nStopRecord;
int m_nBufferSize;
BYTE* m_pbyBuffer;
CReadDemoWave ReadDemo;
//// =========== D == E == M == O =======================
// // BD create demo buffer.
// int m_nDemoBufferSize;
// BYTE* m_pbyDemoBuffer;
// HMMIO m_hmmioDemoFile;
//void ReadDemoIntoBuffer();
/* void ReadWavFile();
DWORD PlayWaveFile(LPSTR path);
*/ long QueueWaveData(HWAVEOUT HWaveOut, WAVEHDR * waveHeader, DWORD WaveDataPlayed, DWORD WaveBufSize, HMMIO HMmio);
//void CALLBACK WaveOutProc(HWAVEOUT waveOut, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
void PlayWav();
//char m_szError[ERROR_LENGTH];
//int m_nError;
//HMMIO m_hmmio;
//MMIOINFO m_mmioInfo;
//DWORD dwDataSize;
//DWORD dwCount;
//HPSTR m_hptr;
//HPSTR lpData;
// Demo buffer
// WAVEHDR lpDemoData;
// DWORD dwDemoDataSize;
//WAVEHDR GetDemoBuffer(void);
//int samplecnt;
// =========== D == E == M == O =======================
long m_lTotalTimeSize, m_lSongTimeSize;
int m_nTotalTimeMin, m_nTotalTimeSec;
int m_nSongTimeMin, m_nSongTimeSec;
int m_nIsLargeFont, m_nNumColors;
int m_nButtonBackground;
UINT m_nWindowSize;
// Algorithm variabls
int m_nSliderGapSize;
int m_nSliderGapLevel;
int m_nSliderMinSongSize;
int m_nSliderEndSize;
int m_nButtonDCBlock;
int m_nCheckIgnore;
int m_nSamplesPerSec;
short m_wBitsPerSample;
short m_nChannels; // Not used in this version, but ready in Presets
int m_nWaveInID;
// Presets
CObArray m_ObArrayPresets;
char m_szCurPresetName[FILENAME_MAX];
char m_szTempPresetFileName[FILENAME_MAX], m_szPresetFileName[FILENAME_MAX];
void LoadPresets(void);
void RestorePresets(void);
void SavePresets(void);
// File Counter
CString m_strCurFile, m_strCurFilePath, m_strCurFileText;
int m_nSongTime, m_nTotalTime, m_nClipped;
CString m_strTotalTime, m_strSongTime, m_strClipped;
// Meters
CLedMeter m_cLedMeterL, m_cLedMeterR;
CFont m_cFontMeter;
LedDriver m_ledDriver;
int m_nIsDisplayedL, m_nIsDisplayedR;
int m_nPeakLevelL, m_nPeakLevelR;
int m_nAveLevelL, m_nAveLevelR;
int m_nClipL, m_nClipR;
// System resources
HICON m_hIconRecord;
HICON m_hIconStop;
HICON m_hIconSndVol;
HBITMAP m_hBitmapAlbum0, m_hBitmapAlbum1;
COLORREF m_colorDialog, m_colorText;
CBrush m_cBrushDialog;
CBrush m_cBrushCombo;
CFont m_cFontCombo;
CPalette m_cPalette; // *m_pcOldPalette;
CToolTipCtrlAdv m_ctlTTAdv;
// RegLevel
int m_nRegLevel;
// Construction
public:
//WAVEHDR lpDemoData;
//DWORD dwDemoDataSize;
CSingleDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CSingleDlg)
enum { IDD = IDD_SINGLE_DIALOG };
CStatic m_ctlStaticClipped;
CButton m_ctlButtonSndVol;
CStatic m_ctlStaticAlbum;
CButton m_ctlButtonBackground;
CStatic m_ctlStaticTotalTime;
CStatic m_ctlStaticSongTime;
CStatic m_ctlStaticCurrentFile;
CComboBox m_ctlComboPresetName;
CButton m_ctlButtonSettings;
CButton m_ctlButtonOK;
CComboBox m_ctlComboOutfileName;
CButton m_ctlButtonRecordStop;
CButton m_ctlButtonRecord;
CButton m_ctlButtonOutfileBrowse;
//}}AFX_DATA
CStaticButton m_ctlStaticButtonAiplSound;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSingleDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CSingleDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButtonOutfileBrowse();
afx_msg void OnSelchangeComboOutfileName();
afx_msg void OnButtonRecord();
afx_msg void OnButtonRecordStop();
virtual void OnOK();
afx_msg void OnClose();
afx_msg void OnDestroy();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnButtonSettings();
afx_msg void OnSelchangeComboPresetName();
afx_msg void OnCheckBackground();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnButtonSndVol();
//}}AFX_MSG
afx_msg LRESULT OnThreadRecordFinished(WPARAM, LPARAM);
afx_msg void OnStaticButtonAiplSound();
// Palette stuff
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
afx_msg BOOL OnQueryNewPalette();
afx_msg void OnSysColorChange(void); // Don't need - when number of colors change
DECLARE_MESSAGE_MAP()
// Meters
static void __stdcall GetMeterData(int iMeter, int& iAverageLevel, int& iPeakLevel, BOOL& bClip);
// Other functions
static UINT ThreadRecord(LPVOID);
static void CALLBACK CallbackRecord(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1,
DWORD dwParam2);
LRESULT OnNonstaticThreadRecordUI(WPARAM wParam, LPARAM lParam);
// Init Stuff
void InitDialogSound(void);
// Settings
void SaveSettings(void);
void RestoreSettings(void);
void RestoreOutfile(CString);
public:
afx_msg void OnBnClickedOk();
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_)
//////////////////////////////////////////////////////////////////////
// WavRecord.h: interface for the CWavRecord class.
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WAVRECORD_H__2C400A28_DDC3_11D0_9FD3_444553540021__INCLUDED_)
#define AFX_WAVRECORD_H__2C400A28_DDC3_11D0_9FD3_444553540021__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#define ERROR_LENGTH 1024
/* Definition from MS
typedef struct {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX;
typedef struct {
LPSTR lpData;
DWORD dwBufferLength;
DWORD dwBytesRecorded;
DWORD dwUser;
DWORD dwFlags;
DWORD dwLoops;
struct wavehdr_tag * lpNext;
DWORD reserved;
} WAVEHDR;
*/
class CWavRecord
{
private:
UINT m_uDeviceID;
HGLOBAL m_pbyData[2];
int m_nCurData;
DWORD m_dwDataSize;
HWAVEIN m_hWaveIn;
WAVEHDR m_WaveHdr[2];
DWORD m_dwBytesRecorded;
// Error variables
int m_nError;
char m_szError[ERROR_LENGTH];
public:
// Constructor (empty) / Destructor
CWavRecord();
virtual ~CWavRecord();
// Data processing
void Start(void);
int Queue(BYTE *pbyData);
int Stop(BYTE *pbyData);
// Data Manipulation
void Open(WAVEFORMATEX *pfwx, DWORD dwCallback, DWORD dwCallbackInstance, DWORD fdwOpen);
void Query(WAVEFORMATEX *pfwx);
void Init(DWORD dwDataSize);
void Close(void);
// Inline - for speed
int IsDone(void);
// Parameter Manipulation
void SetDeviceID(UINT);
UINT GetDeviceID(void);
// Error Handling
int IsError(void) { return m_nError; };
char *GetError(void) { return m_szError; };
};
//////////////////////////////////////////////////////////////////////
// Data Processing - inline for speed
//////////////////////////////////////////////////////////////////////
inline int CWavRecord::IsDone(void)
{
if ( m_WaveHdr[m_nCurData].dwFlags & WHDR_DONE )
return 1;
else
return 0;
}
#endif // !defined(AFX_WAVRECORD_H__2C400A28_DDC3_11D0_9FD3_444553540021__INCLUDED_)
Bill Dennis
Orlando, FL
|
|
|
|
|
Many lines. I need a moment...
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|