Looping Sounds
[The feature associated with this page, DirectSound, is a legacy feature. It has been superseded by WASAPI and Audio Graphs. Media Casting have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Media Casting instead of DirectSound, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
DirectSound does not directly support looping within a buffer, or repetition of only a portion of a sound. (The DSBPLAY_LOOPING flag causes the entire buffer to play again when the play cursor reaches the end.) Although it is possible to implement looping on a static buffer by resetting the play cursor to the start of the loop each time it reaches the end of the loop, doing so might result in audio glitches, as DirectSound must discard any preprocessed data and begin preprocessing again.
To repeat a portion of a sound, play the sound in a streaming buffer and implement the loop in your source data.