Hi guys, I redesigned my PSG emulation engine yet again and this time I got it right lol..(after the 3rd time). Any who there is a problem with my buffering code, it seems that if my FPS falls even slightly below 60 (like 54 or 53). The sound is broken up and distorted, obviously I cannot accept this! What I do is I generate sample data in sync with the CPU emulation in a buffer half the length of the output buffer to the speakers. Then I lock from the current write cursor of the buffer and half the size of the output buffer then I copy my data over, thats it. What I was thinking of doing is:
Making a 1000 ms buffer
Process 100ms at a time
Figure out current chunk that is being played
Update the 100 ms chunk after the one that is being played
Continue emulation

Any better ideas out there?
Posted on 2004-07-24 22:57:23 by x86asm
Maybe, dynamic sync the sound. Something as simple as allowing the sound to jump to the start of the buffer just updated - this assumes you are using a rather small buffer and it doesn't get behind too much.

If you are going to use 10 x 100ms buffers then update as far in advance as possible -- when 100ms has finished playing then that buffer is updated. But if it continues falling behind, there is some sound to be skipped at extreme lag -- no amount of buffering will help.
Posted on 2004-07-26 01:56:21 by bitRAKE