Current Play and Write Positions

DirectSound maintains two pointers into the buffer: the current play position (or play cursor) and the current write position (or write cursor). These positions are byte offsets into the buffer, not absolute memory addresses.

The IDirectSoundBuffer::Play method always starts playing at the buffer's current play position. When a buffer is created, the play position is set to zero. As a sound is played, the play position moves and always points to the next byte of data to be output. When the buffer is stopped, the play position remains where it is.

The current write position is the point after which it is safe to write data into the buffer. The block between the current play position and the current write position is already committed to be played, and cannot be changed safely.

Visualize the buffer as a clock face, with data written to it in a clockwise direction. The play position and the write position are like two hands sweeping around the face at the same speed, the write position always keeping a little ahead of the play position. If the play position points to the 1 and the write position points to the 2, it is only safe to write data after the 2. Data between the 1 and the 2 may already have been queued for playback by DirectSound and should not be touched.

Note  The write position moves with the play position, not with data written to the buffer. If you're streaming data, you are responsible for maintaining your own pointer into the buffer to indicate where the next block of data should be written.

Also note that the dwWriteCursor parameter to the IDirectSoundBuffer::Lock method is not the current write position; it is the offset within the buffer where you actually intend to begin writing data. (If you do want to begin writing at the current write position, you specify DSBLOCK_FROMWRITECURSOR in the dwFlags parameter. In this case the dwWriteCursor parameter is ignored.)

An application can retrieve the current play and write positions by calling the IDirectSoundBuffer::GetCurrentPosition method. The IDirectSoundBuffer::SetCurrentPosition method lets you set the current play position, but the current write position cannot be changed.