fix some dumb sync bugs
This commit is contained in:
@@ -151,7 +151,7 @@ bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, i
|
|||||||
|
|
||||||
/* Increment last_cursor_pos to point at where the data we're about to
|
/* Increment last_cursor_pos to point at where the data we're about to
|
||||||
* ask for will actually be played. */
|
* ask for will actually be played. */
|
||||||
last_cursor_pos += buffersize_frames();
|
last_cursor_pos += num_bytes_empty / samplesize();
|
||||||
|
|
||||||
buffer_locked = true;
|
buffer_locked = true;
|
||||||
|
|
||||||
@@ -169,9 +169,10 @@ int DSoundBuf::GetPosition() const
|
|||||||
{
|
{
|
||||||
DWORD cursor, junk;
|
DWORD cursor, junk;
|
||||||
buf->GetCurrentPosition(&cursor, &junk);
|
buf->GetCurrentPosition(&cursor, &junk);
|
||||||
int last_fill = write_cursor;
|
int cursor_frames = int(cursor) / samplesize();
|
||||||
|
int write_cursor_frames = write_cursor / samplesize();
|
||||||
|
|
||||||
int frames_behind = (last_fill - int(cursor)) / samplesize();
|
int frames_behind = write_cursor_frames - cursor_frames;
|
||||||
if(frames_behind <= 0)
|
if(frames_behind <= 0)
|
||||||
frames_behind += buffersize_frames(); /* unwrap */
|
frames_behind += buffersize_frames(); /* unwrap */
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ int DSoundBuf::GetPosition() const
|
|||||||
|
|
||||||
void DSoundBuf::Play()
|
void DSoundBuf::Play()
|
||||||
{
|
{
|
||||||
HRESULT hr = buf->Play(0, 0, DSBPLAY_LOOPING);
|
buf->Play(0, 0, DSBPLAY_LOOPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSoundBuf::Stop()
|
void DSoundBuf::Stop()
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ class DSoundBuf
|
|||||||
int channels, samplerate, samplebits, buffersize;
|
int channels, samplerate, samplebits, buffersize;
|
||||||
|
|
||||||
int buffersize_frames() const { return buffersize / samplesize(); }
|
int buffersize_frames() const { return buffersize / samplesize(); }
|
||||||
int samplesize() const { return samplebits; }
|
int samplesize() const { return channels*samplebits/8; }
|
||||||
|
|
||||||
int write_cursor, last_cursor_pos;
|
int write_cursor, last_cursor_pos; /* frames */
|
||||||
mutable int LastPosition;
|
mutable int LastPosition;
|
||||||
|
|
||||||
bool buffer_locked;
|
bool buffer_locked;
|
||||||
|
|||||||
Reference in New Issue
Block a user