simplify
This commit is contained in:
@@ -123,23 +123,18 @@ bool RageSound_DSound::stream::GetData(bool init)
|
|||||||
* fill anything in STOPPING; in that case, we just clear the audio buffer. */
|
* fill anything in STOPPING; in that case, we just clear the audio buffer. */
|
||||||
if(state != STOPPING)
|
if(state != STOPPING)
|
||||||
{
|
{
|
||||||
unsigned bytes_read = 0;
|
int bytes_read = 0;
|
||||||
unsigned bytes_left = len;
|
int bytes_left = len;
|
||||||
|
|
||||||
/* Does the sound have a start time? */
|
/* Does the sound have a start time? */
|
||||||
if( !start_time.IsZero() )
|
if( !start_time.IsZero() )
|
||||||
{
|
{
|
||||||
/* If the sound is supposed to start at a time past this buffer, fill with
|
/* If the sound is supposed to start at a time past this buffer, insert silence. */
|
||||||
* silence. */
|
|
||||||
const float fSecondsBeforeStart = -start_time.Ago();
|
|
||||||
|
|
||||||
const int iFramesUntilThisBuffer = play_pos - cur_play_pos;
|
const int iFramesUntilThisBuffer = play_pos - cur_play_pos;
|
||||||
const float fSecondsUntilThisBuffer = float(iFramesUntilThisBuffer) / str_ds->GetSampleRate();
|
const float fSecondsBeforeStart = -start_time.Ago();
|
||||||
|
const int iFramesBeforeStart = int(fSecondsBeforeStart * str_ds->GetSampleRate());
|
||||||
const float fSilentSecondsInThisBuffer = max( 0, fSecondsBeforeStart-fSecondsUntilThisBuffer );
|
const int iSilentFramesInThisBuffer = max( 0, iFramesBeforeStart-iFramesUntilThisBuffer );
|
||||||
const int iSilentFramesInThisBuffer = int( fSilentSecondsInThisBuffer * str_ds->GetSampleRate() );
|
const int iSilentBytesInThisBuffer = min( iSilentFramesInThisBuffer * bytes_per_frame, bytes_left );
|
||||||
const int iActualSilentFramesInThisBuffer = min( iSilentFramesInThisBuffer, (int) bytes_left/bytes_per_frame );
|
|
||||||
const int iSilentBytesInThisBuffer = iActualSilentFramesInThisBuffer * bytes_per_frame;
|
|
||||||
|
|
||||||
memset( locked_buf, 0, iSilentBytesInThisBuffer );
|
memset( locked_buf, 0, iSilentBytesInThisBuffer );
|
||||||
bytes_read += iSilentBytesInThisBuffer;
|
bytes_read += iSilentBytesInThisBuffer;
|
||||||
@@ -149,10 +144,10 @@ bool RageSound_DSound::stream::GetData(bool init)
|
|||||||
start_time.SetZero();
|
start_time.SetZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned got = snd->GetPCM( locked_buf+bytes_read, len-bytes_read, play_pos + (bytes_read/bytes_per_frame));
|
int got = snd->GetPCM( locked_buf+bytes_read, len-bytes_read, play_pos + (bytes_read/bytes_per_frame));
|
||||||
bytes_read += got;
|
bytes_read += got;
|
||||||
|
|
||||||
if( bytes_read < len )
|
if( bytes_read < (int) len )
|
||||||
{
|
{
|
||||||
/* Fill the remainder of the buffer with silence. */
|
/* Fill the remainder of the buffer with silence. */
|
||||||
memset( locked_buf+got, 0, len-bytes_read );
|
memset( locked_buf+got, 0, len-bytes_read );
|
||||||
|
|||||||
Reference in New Issue
Block a user