work around AudioPCI driver bug (can't test to see if this actually works)

This commit is contained in:
Glenn Maynard
2004-02-27 06:47:07 +00:00
parent fd1dd28b4d
commit be746862a5
2 changed files with 20 additions and 2 deletions
+19 -2
View File
@@ -139,6 +139,7 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
buffer_locked = false; buffer_locked = false;
last_cursor_pos = write_cursor = buffer_bytes_filled = 0; last_cursor_pos = write_cursor = buffer_bytes_filled = 0;
LastPosition = 0; LastPosition = 0;
playing = false;
/* The size of the actual DSound buffer. This can be large; we generally /* The size of the actual DSound buffer. This can be large; we generally
* won't fill it completely. */ * won't fill it completely. */
@@ -294,16 +295,24 @@ bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int chunksize)
* the two values returned by GetCurrentPosition, that we can't write to. */ * the two values returned by GetCurrentPosition, that we can't write to. */
result = buf->GetCurrentPosition(&cursorstart, &cursorend); result = buf->GetCurrentPosition(&cursorstart, &cursorend);
#ifndef _XBOX #ifndef _XBOX
if ( result == DSERR_BUFFERLOST ) { if ( result == DSERR_BUFFERLOST )
{
buf->Restore(); buf->Restore();
result = buf->GetCurrentPosition(&cursorstart, &cursorend); result = buf->GetCurrentPosition(&cursorstart, &cursorend);
} }
if ( result != DS_OK ) { if ( result != DS_OK )
{
LOG->Warn(hr_ssprintf(result, "DirectSound::GetCurrentPosition failed")); LOG->Warn(hr_ssprintf(result, "DirectSound::GetCurrentPosition failed"));
return false; return false;
} }
#endif #endif
/* Some cards (Creative AudioPCI) have a no-write area even when not playing. I'm not
* sure what that means, but it breaks the assumption that we can fill the whole writeahead
* when prebuffering. */
if( !playing )
cursorend = cursorstart;
/* Update buffer_bytes_filled. */ /* Update buffer_bytes_filled. */
{ {
int first_byte_filled = write_cursor-buffer_bytes_filled; int first_byte_filled = write_cursor-buffer_bytes_filled;
@@ -454,11 +463,17 @@ int64_t DSoundBuf::GetPosition() const
void DSoundBuf::Play() void DSoundBuf::Play()
{ {
if( playing )
return;
buf->Play(0, 0, DSBPLAY_LOOPING); buf->Play(0, 0, DSBPLAY_LOOPING);
playing = true;
} }
void DSoundBuf::Stop() void DSoundBuf::Stop()
{ {
if( !playing )
return;
buf->Stop(); buf->Stop();
buf->SetCurrentPosition(0); buf->SetCurrentPosition(0);
@@ -469,6 +484,8 @@ void DSoundBuf::Stop()
DWORD play, write; DWORD play, write;
buf->GetCurrentPosition( &play, &write ); buf->GetCurrentPosition( &play, &write );
RAGE_ASSERT_M( play == 0 && write == 0, ssprintf("%i, %i", play, write) ); RAGE_ASSERT_M( play == 0 && write == 0, ssprintf("%i, %i", play, write) );
playing = false;
} }
/* /*
+1
View File
@@ -40,6 +40,7 @@ class DSoundBuf
int write_cursor, buffer_bytes_filled; /* bytes */ int write_cursor, buffer_bytes_filled; /* bytes */
int64_t last_cursor_pos; /* frames */ int64_t last_cursor_pos; /* frames */
mutable int64_t LastPosition; mutable int64_t LastPosition;
bool playing;
bool buffer_locked; bool buffer_locked;
char *locked_buf; char *locked_buf;