I am doing an application (actualy and emulator) which runs at 60 frame per seconds. Each frame, I am locking a 735 bytes of data from the soundbuffer and copy the sound data generated during the last frame.
. The frame rate is controled by polling the InVBlank field of a D3DRASTER_STATUS structure (from directX).
. The soundbuffer is WAVE_FORMAT_PCM, 16 bits samples, 44100 Hz sample rate
. 735 is 44100/60
. the buffer size is 0x8000 (it is a little arbitrary, I didn't really think about a size as an issue in fact)
. When locking the soundbuffer, I do not use DSBLOCK_FROMWRITECURSOR. I read somewhere that this feature may be buggy, and that the application should keep track of its own write cursor.
The sound is smooth, but at some points, it seems that the readcursor and the "application write cursor" get desynchronized. On the case of the computer I'm testing on, the read cursor seems be a little slower than the write one.
So first the image and the sound gets a little desynchronized (to the extend of the buffer size). And when the write cursor crosses the read cursor, it makes noise.
If you read that far, thank you :-D
So now, here is the problem. Is there a good way to do "cursor computation" so that the sound rendering always sounds smooth ? Some kind of formula ?
Let's say I read the read cursor, makes a diff with the write cursor, and update one or the other, what should be the parameters ?
Maybe it's my way of feeding the buffer which is bad from the start ?
Any suggestion, help, warm words of encouragement, congratulation, ... would be greatly appreciated.
Thanks in advance.
Fo-su to tomo ni aran koto wo.