Platform SDK: DirectX |
The information in this topic pertains only to applications written in C and C++. See DirectSound Visual Basic Tutorials.
At this point it is presumed that you have obtained a valid filename and are ready to start saving sound data in a wave file. The process is initiated in the following function:
BOOL StartWrite(TCHAR *pszFileName) { if (WaveOpenFile(pszFileName, &hmmio, &wfx, &mmckinfoData, &mmckinfoParent)) return FALSE; if (WaveStartDataWrite(&hmmio, &mmckinfoData, &mmioinfo)) { WaveCloseWriteFile(&hmmio, &mmckinfoData, &mmckinfoParent, &mmioinfo, dwTotalBytesWritten / (wfx.wBitsPerSample / 8)); DeleteFile(pszFileName); return FALSE; } if FAILED(IDirectSoundCaptureBuffer_Start(lpdscb, DSCBSTART_LOOPING)) { WaveCloseWriteFile(&hmmio, &mmckinfoData, &mmckinfoParent, &mmioinfo, 0); DeleteFile(pszFileName); return FALSE; } dwTotalBytesWritten = 0; return TRUE; }
This function first calls the WaveOpenFile function in Wavwrite.cpp, in order to create a RIFF file and write the header for the wave format. It then calls the WaveStartDataWrite function, which advances the file pointer to the data chunk. Finally, it starts the capture buffer. In half a second your application will be notified that data is available, and you must be ready to copy it to the file.
Note also the initialization of dwTotalBytesWritten. This value is going to be needed for the data chunk header after capture is complete.