The IDirectSoundBuffer::Lock method obtains a valid write pointer to the sound buffer's audio data.
HRESULT Lock(
DWORD dwWriteCursor,
DWORD dwWriteBytes,
LPVOID lplpvAudioPtr1,
LPDWORD lpdwAudioBytes1,
LPVOID lplpvAudioPtr2,
LPDWORD lpdwAudioBytes2,
DWORD dwFlags
);
DSBLOCK_FROMWRITECURSOR | |
Locks from the current write position, making a call to IDirectSoundBuffer::GetCurrentPosition unnecessary. If this flag is specified, the dwWriteCursor parameter is ignored. | |
DSBLOCK_ENTIREBUFFER | |
Locks the entire buffer. The dwWriteBytes parameter is ignored. |
If the method succeeds, the return value is DS_OK.
If the method fails, the return value may be one of the following error values:
DSERR_BUFFERLOST
DSERR_INVALIDCALL
DSERR_INVALIDPARAM
DSERR_PRIOLEVELNEEDED
This method accepts an offset and a byte count, and returns two write pointers and their associated sizes. Two pointers are required because sound buffers are circular. If the locked bytes do not wrap around the end of the buffer, the second pointer, lplpvAudioBytes2, will be NULL. However, if the bytes do wrap around, then the second pointer will point to the beginning of the buffer.
If the application passes NULL for the lplpvAudioPtr2 and lpdwAudioBytes2 parameters, DirectSound will not lock the wraparound portion of the buffer.
The application should write data to the pointers returned by the IDirectSoundBuffer::Lock method, and then call the IDirectSoundBuffer::Unlock method to release the buffer back to DirectSound. The sound buffer should not be locked for long periods of time; if it is, the play cursor will reach the locked bytes and configuration-dependent audio problems, possibly random noise, will result.
Warning This method returns a write pointer only. The application should not try to read sound data from this pointer; the data might not be valid even though the DirectSoundBuffer object contains valid sound data. For example, if the buffer is located in on-board memory, the pointer might be an address to a temporary buffer in main system memory. When IDirectSoundBuffer::Unlock is called, this temporary buffer will be transferred to the on-board memory.
Windows NT: Use version 4.0 or later.
Windows: Use Windows 95 or later. Available as a redistributable for Windows 95.
Windows CE: Unsupported.
Header: Declared in dsound.h.
Import Library: Use dsound.lib.
IDirectSoundBuffer, IDirectSoundBuffer::GetCurrentPosition, IDirectSoundBuffer::Unlock