From f87e63a3861ed97c73e92b7026e77871b06d0f40 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 29 Dec 2002 00:19:05 +0000 Subject: [PATCH] fix some dumb sync bugs --- stepmania/src/arch/Sound/DSoundHelpers.cpp | 9 +++++---- stepmania/src/arch/Sound/DSoundHelpers.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stepmania/src/arch/Sound/DSoundHelpers.cpp b/stepmania/src/arch/Sound/DSoundHelpers.cpp index bf94872989..f432ecc61e 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.cpp +++ b/stepmania/src/arch/Sound/DSoundHelpers.cpp @@ -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 * ask for will actually be played. */ - last_cursor_pos += buffersize_frames(); + last_cursor_pos += num_bytes_empty / samplesize(); buffer_locked = true; @@ -169,9 +169,10 @@ int DSoundBuf::GetPosition() const { DWORD 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) frames_behind += buffersize_frames(); /* unwrap */ @@ -187,7 +188,7 @@ int DSoundBuf::GetPosition() const void DSoundBuf::Play() { - HRESULT hr = buf->Play(0, 0, DSBPLAY_LOOPING); + buf->Play(0, 0, DSBPLAY_LOOPING); } void DSoundBuf::Stop() diff --git a/stepmania/src/arch/Sound/DSoundHelpers.h b/stepmania/src/arch/Sound/DSoundHelpers.h index d59383d49a..594d4daffb 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.h +++ b/stepmania/src/arch/Sound/DSoundHelpers.h @@ -25,9 +25,9 @@ class DSoundBuf int channels, samplerate, samplebits, buffersize; 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; bool buffer_locked;