Microsoft Windows CE 3.0  

Current Play and Write Positions

This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

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

The IDirectSoundBuffer::Playmethod 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 at the next byte of data.

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 dwWriteCursorparameter to the IDirectSoundBuffer::Lockmethod 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 dwFlagsparameter. In this case the dwWriteCursorparameter is ignored.)

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

To ensure that the current play position is reported as accurately as possible, you should always specify the DSBCAPS_GETCURRENTPOSITION2 flag when creating a secondary buffer. For more information, see DSBUFFERDESC.

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.