I have an application that will capture sound from a mic in real-time. The application runs but when I have finished recording the sound I am receiving an error with the memcpy command. The error outputs a messagebox that says:
"Unhandled exception at 0x004739ca in capturesound.exe: 0xC0000005: Access violation writing location 0x00000000."
This error is on the "memcpy.asm" which is on the line:
"rep movsd ;N - move all of our dwords"
Here is the part where I used memcpy:
//-----------------------------------------------------------------------------
// Name: RecordCapturedData()
// Desc: Copies data from the capture buffer to the output buffer
//-----------------------------------------------------------------------------
HRESULT RecordCapturedData()
{
HRESULT hr;
VOID* pbCaptureData = NULL;
DWORD dwCaptureLength;
VOID* pbCaptureData2 = NULL;
DWORD dwCaptureLength2;
DWORD dwDataWrote;
DWORD dwReadPos;
DWORD dwCapturePos;
LONG lLockSize;
void* buf;
if( NULL == g_pDSBCapture )
return S_FALSE;
//if( NULL == g_pWaveFile )
// return S_FALSE;
if( FAILED( hr = g_pDSBCapture->GetCurrentPosition( &dwCapturePos, &dwReadPos ) ) )
return DXTRACE_ERR_MSGBOX( TEXT("GetCurrentPosition"), hr );
lLockSize = dwReadPos - g_dwNextCaptureOffset;
if( lLockSize < 0 )
lLockSize += g_dwCaptureBufferSize;
// Block align lock size so that we are always write on a boundary
lLockSize -= (lLockSize % g_dwNotifySize);
if( lLockSize == 0 )
return S_FALSE;
// Lock the capture buffer down
if( FAILED( hr = g_pDSBCapture->Lock( g_dwNextCaptureOffset, lLockSize,
&pbCaptureData, &dwCaptureLength,
&pbCaptureData2, &dwCaptureLength2, 0L ) ) )
return DXTRACE_ERR_MSGBOX( TEXT("Lock"), hr );
if(pbCaptureData) memcpy(buf,pbCaptureData,dwCaptureLength);
if(pbCaptureData2) memcpy((char*)
buf+dwCaptureLength,pbCaptureData2,dwCaptureLength2);
// Move the capture offset along
g_dwNextCaptureOffset += dwCaptureLength;
g_dwNextCaptureOffset %= g_dwCaptureBufferSize; // Circular buffer
// Move the capture offset along
g_dwNextCaptureOffset += dwCaptureLength2;
g_dwNextCaptureOffset %= g_dwCaptureBufferSize; // Circular buffer
}
// Unlock the capture buffer
g_pDSBCapture->Unlock( pbCaptureData, dwCaptureLength,
pbCaptureData2, dwCaptureLength2 );
return S_OK;
}
