Jump to content
  • Advertisement
Sign in to follow this  

Saving Captured PCM data to a file

This topic is 4330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the capture sound sample of directx I am trying to save the raw data captured by the capture buffer and then saving it to a .pcm file. I have substituted the "Write" command from the CWaveFile with "WriteFile" command from Win32. Is this procedure correct? Thanks!
HRESULT RecordCapturedData() 
    HRESULT hr;
    VOID*   pbCaptureData    = NULL;
    DWORD   dwCaptureLength;
    VOID*   pbCaptureData2   = NULL;
    DWORD   dwCaptureLength2;
    DWORD   dwDataWrote;
    DWORD   dwReadPos;
    DWORD   dwCapturePos;
    LONG lLockSize;
	//void* audio1=NULL,*audio2=NULL;
	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 );

    // Write the data into the wav file
    //if( FAILED( hr = audio1->write( dwCaptureLength, 
      //                                        (BYTE*)pbCaptureData, 
        //                                      &dwDataWrote ) ) )
        //return DXTRACE_ERR_MSGBOX( TEXT("Write"), hr );


    // Move the capture offset along
    g_dwNextCaptureOffset += dwCaptureLength; 
    g_dwNextCaptureOffset %= g_dwCaptureBufferSize; // Circular buffer

   if( pbCaptureData2 != NULL )
                                 &dwDataWrote , 
        // Write the data into the wav file
       // if( FAILED( hr = audio2->write( dwCaptureLength2, 
         //                                         (BYTE*)pbCaptureData2, 
           //                                       &dwDataWrote ) ) )
            //return DXTRACE_ERR_MSGBOX( TEXT("Write"), hr );

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!