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