in directsound, for IDirectSoundBuffer, which method to be in charge of write position of buffer.

StackOverflow https://stackoverflow.com/questions/17159648

  •  01-06-2022
  •  | 
  •  

Question

In directsound, we know, call IDirectSoundBuffer::getcurrentposition(), would get the play-position and write-position in the directsound buffer.But i think copy data into buffer should change the writeposition(this behavior, changing write_position, would be caused by which method, unlock?). I think only the copying data function should only affect the data in buffer, not the write-position..

Was it helpful?

Solution

But i think copy data into buffer should change the writeposition

There is only one position that buffer tracks for you and it is "current position", the position at which hardware playback is taking place, returned to you approximately because it keeps changing with time.

Your data manipulation obviously does not affect this position. Instead, you typically want to keep throwing more and more data ahead of the current position so that playback does not hit buffer underrun and plays data smoothly. So you track your own additional "write position" internally: you add data at this position and you advance this pointer yourself.

The write position returned to you in second argument of GetCurrentPosition call is only informational for you to know which position is still safe to write to (it is late to modify data between play and write positions because this data is already buffered for playback):

The write cursor indicates the position at which it is safe to write new data to the buffer. The write cursor always leads the play cursor, typically by about 15 milliseconds' worth of audio data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top