simplify DSoundBuf interface
This commit is contained in:
@@ -257,7 +257,7 @@ DSoundBuf::~DSoundBuf()
|
||||
buf->Release();
|
||||
}
|
||||
|
||||
bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, int chunksize)
|
||||
bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int chunksize)
|
||||
{
|
||||
ASSERT(!buffer_locked);
|
||||
|
||||
@@ -311,9 +311,11 @@ bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, i
|
||||
if(!contained(first_byte_filled, write_cursor, cursorstart) ||
|
||||
!contained(first_byte_filled, write_cursor, cursorend))
|
||||
{
|
||||
int missed_by = cursorend - write_cursor;
|
||||
wrap( missed_by, buffersize );
|
||||
LOG->Trace("underrun: %i..%i filled but cursor at %i..%i (missed it by %i)",
|
||||
first_byte_filled, write_cursor, cursorstart, cursorend,
|
||||
(cursorend - write_cursor + buffersize) % buffersize);
|
||||
missed_by);
|
||||
// (cursorend - first_byte_filled + buffersize) % buffersize);
|
||||
|
||||
/* Pretend the space between the play and write cursor is filled
|
||||
@@ -370,9 +372,6 @@ bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, i
|
||||
|
||||
buffer_bytes_filled += num_bytes_empty;
|
||||
|
||||
if( play_pos )
|
||||
*play_pos = last_cursor_pos;
|
||||
|
||||
/* Increment last_cursor_pos to point at where the data we're about to
|
||||
* ask for will actually be played. */
|
||||
last_cursor_pos += num_bytes_empty / samplesize();
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
DSoundBuf(DSound &ds, hw hardware,
|
||||
int channels, int samplerate, int samplebits, int writeahead);
|
||||
|
||||
bool get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, int chunksize);
|
||||
bool get_output_buf(char **buffer, unsigned *bufsiz, int chunksize);
|
||||
void release_output_buf(char *buffer, unsigned bufsiz);
|
||||
|
||||
void Reset();
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
~DSoundBuf();
|
||||
int GetPosition() const;
|
||||
int GetMaxPosition() const { return last_cursor_pos; }
|
||||
int GetOutputPosition() const { return last_cursor_pos; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -105,16 +105,16 @@ bool RageSound_DSound::stream::GetData(bool init)
|
||||
|
||||
char *locked_buf;
|
||||
unsigned len;
|
||||
int play_pos;
|
||||
const int play_pos = str_ds->GetOutputPosition();
|
||||
|
||||
if(init) {
|
||||
/* We're initializing; fill the entire buffer. The buffer is supposed to
|
||||
* be empty, so this should never fail. */
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, &play_pos, buffersize))
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, buffersize))
|
||||
ASSERT(0);
|
||||
} else {
|
||||
/* Just fill one chunk. */
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, &play_pos, chunksize))
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, chunksize))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ bool RageSound_DSound::stream::GetData(bool init)
|
||||
state = STOPPING;
|
||||
|
||||
/* Flush two buffers worth of data. */
|
||||
flush_pos = str_ds->GetMaxPosition();
|
||||
flush_pos = str_ds->GetOutputPosition();
|
||||
}
|
||||
} else {
|
||||
/* Silence the buffer. */
|
||||
@@ -280,7 +280,7 @@ void RageSound_DSound::StopMixing(RageSound *snd)
|
||||
stream_pool[i]->state = stream_pool[i]->STOPPING;
|
||||
|
||||
/* Flush two buffers worth of data. */
|
||||
stream_pool[i]->flush_pos = stream_pool[i]->str_ds->GetMaxPosition();
|
||||
stream_pool[i]->flush_pos = stream_pool[i]->str_ds->GetOutputPosition();
|
||||
|
||||
/* This function is called externally (by RageSound) to stop immediately.
|
||||
* We need to prevent SoundStopped from being called; it should only be
|
||||
|
||||
@@ -63,9 +63,9 @@ bool RageSound_DSound_Software::GetData()
|
||||
|
||||
char *locked_buf;
|
||||
unsigned len;
|
||||
int play_pos;
|
||||
const int play_pos = str_ds->GetOutputPosition();
|
||||
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, &play_pos, chunksize))
|
||||
if(!str_ds->get_output_buf(&locked_buf, &len, chunksize))
|
||||
return false;
|
||||
|
||||
/* Silence the buffer. */
|
||||
@@ -96,7 +96,7 @@ bool RageSound_DSound_Software::GetData()
|
||||
{
|
||||
/* This sound is finishing. */
|
||||
sounds[i]->stopping = true;
|
||||
sounds[i]->flush_pos = str_ds->GetMaxPosition();
|
||||
sounds[i]->flush_pos = str_ds->GetOutputPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user