64-bit frame counts

remove DSoundBuf::Reset
This commit is contained in:
Glenn Maynard
2004-01-19 22:21:57 +00:00
parent d29ac34a0f
commit cf97705203
10 changed files with 47 additions and 59 deletions
+8 -14
View File
@@ -136,7 +136,8 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
samplebits = samplebits_;
writeahead = writeahead_;
buffer_locked = false;
last_cursor_pos = write_cursor = LastPosition = buffer_bytes_filled = 0;
last_cursor_pos = write_cursor = buffer_bytes_filled = 0;
LastPosition = 0;
/* The size of the actual DSound buffer. This can be large; we generally
* won't fill it completely. */
@@ -395,7 +396,6 @@ bool DSoundBuf::get_output_buf(char **buffer, unsigned *bufsiz, int chunksize)
/* 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 / bytes_per_frame();
buffer_locked = true;
return true;
@@ -407,7 +407,7 @@ void DSoundBuf::release_output_buf(char *buffer, unsigned bufsiz)
buffer_locked = false;
}
int DSoundBuf::GetPosition() const
int64_t DSoundBuf::GetPosition() const
{
DWORD cursor, junk;
buf->GetCurrentPosition(&cursor, &junk);
@@ -415,10 +415,12 @@ int DSoundBuf::GetPosition() const
int write_cursor_frames = write_cursor / bytes_per_frame();
int frames_behind = write_cursor_frames - cursor_frames;
if(frames_behind <= 0)
/* frames_behind will be 0 if we're called before the buffer starts playing:
* both write_cursor_frames and cursor_frames will be 0. */
if( frames_behind < 0 )
frames_behind += buffersize_frames(); /* unwrap */
int ret = last_cursor_pos - frames_behind;
int64_t ret = last_cursor_pos - frames_behind;
/* Failsafe: never return a value smaller than we've already returned.
* This can happen once in a while in underrun conditions. */
@@ -437,15 +439,7 @@ void DSoundBuf::Stop()
{
buf->Stop();
buf->SetCurrentPosition(0);
last_cursor_pos = LastPosition = write_cursor = buffer_bytes_filled = 0;
}
void DSoundBuf::Reset()
{
/* Nothing is playing. Reset the sample count; this is just to
* prevent eventual overflow. */
last_cursor_pos = LastPosition = 0;
last_cursor_pos = write_cursor = buffer_bytes_filled = 0;
}
/*
+4 -5
View File
@@ -37,8 +37,8 @@ class DSoundBuf
int bytes_per_frame() const { return channels*samplebits/8; }
int write_cursor, buffer_bytes_filled; /* bytes */
int last_cursor_pos; /* frames */
mutable int LastPosition;
int64_t last_cursor_pos; /* frames */
mutable int64_t LastPosition;
bool buffer_locked;
char *locked_buf;
@@ -56,7 +56,6 @@ public:
bool get_output_buf(char **buffer, unsigned *bufsiz, int chunksize);
void release_output_buf(char *buffer, unsigned bufsiz);
void Reset();
void Play();
void Stop();
void SetVolume(float vol);
@@ -64,8 +63,8 @@ public:
int GetSampleRate() { return samplerate; }
~DSoundBuf();
int GetPosition() const;
int GetOutputPosition() const { return last_cursor_pos; }
int64_t GetPosition() const;
int64_t GetOutputPosition() const { return last_cursor_pos; }
};
#endif
@@ -82,7 +82,7 @@ void RageSound_DSound::Update(float delta)
{
if(str[i]->state != str[i]->STOPPING) continue;
int ps = str[i]->pcm->GetPosition();
const int64_t ps = str[i]->pcm->GetPosition();
if(ps < str[i]->flush_pos)
continue; /* stopping but still flushing */
@@ -105,8 +105,8 @@ bool RageSound_DSound::stream::GetData(bool init)
char *locked_buf;
unsigned len;
const int play_pos = pcm->GetOutputPosition();
const int cur_play_pos = pcm->GetPosition();
const int64_t play_pos = pcm->GetOutputPosition();
const int64_t cur_play_pos = pcm->GetPosition();
if(init) {
/* We're initializing; fill the entire buffer. The buffer is supposed to
@@ -130,17 +130,18 @@ bool RageSound_DSound::stream::GetData(bool init)
if( !start_time.IsZero() )
{
/* If the sound is supposed to start at a time past this buffer, insert silence. */
const int iFramesUntilThisBuffer = play_pos - cur_play_pos;
const int64_t iFramesUntilThisBuffer = play_pos - cur_play_pos;
const float fSecondsBeforeStart = -start_time.Ago();
const int iFramesBeforeStart = int(fSecondsBeforeStart * pcm->GetSampleRate());
const int iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( iSilentFramesInThisBuffer * bytes_per_frame, 0, bytes_left );
const int64_t iFramesBeforeStart = int64_t(fSecondsBeforeStart * pcm->GetSampleRate());
const int64_t iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( int(iSilentFramesInThisBuffer * bytes_per_frame), 0, bytes_left );
memset( locked_buf, 0, iSilentBytesInThisBuffer );
bytes_read += iSilentBytesInThisBuffer;
bytes_left -= iSilentBytesInThisBuffer;
if( !iSilentBytesInThisBuffer )
/* If we didn't completely fill the buffer, then we've written all of the silence. */
if( bytes_left )
start_time.SetZero();
}
@@ -314,7 +315,7 @@ void RageSound_DSound::StopMixing( RageSoundBase *snd )
stream_pool[i]->snd = NULL;
}
int RageSound_DSound::GetPosition( const RageSoundBase *snd ) const
int64_t RageSound_DSound::GetPosition( const RageSoundBase *snd ) const
{
LockMutex L(SOUNDMAN->lock);
@@ -25,7 +25,7 @@ class RageSound_DSound: public RageSoundDriver
STOPPING
} state;
int flush_pos; /* state == STOPPING only */
int64_t flush_pos; /* state == STOPPING only */
RageTimer start_time;
bool GetData(bool init);
@@ -47,7 +47,7 @@ class RageSound_DSound: public RageSoundDriver
/* virtuals: */
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
int GetPosition( const RageSoundBase *snd ) const;
int64_t GetPosition( const RageSoundBase *snd ) const;
void Update(float delta);
void VolumeChanged();
@@ -63,12 +63,11 @@ bool RageSound_DSound_Software::GetData()
char *locked_buf;
unsigned len;
const int play_pos = pcm->GetOutputPosition();
const int cur_play_pos = pcm->GetPosition();
const int64_t play_pos = pcm->GetOutputPosition();
int64_t cur_play_pos = -1;
if(!pcm->get_output_buf(&locked_buf, &len, chunksize))
return false;
/* Silence the buffer. */
memset(locked_buf, 0, len);
@@ -94,11 +93,13 @@ bool RageSound_DSound_Software::GetData()
if( !sounds[i]->start_time.IsZero() )
{
/* If the sound is supposed to start at a time past this buffer, insert silence. */
const int iFramesUntilThisBuffer = play_pos - cur_play_pos;
if( cur_play_pos == -1 )
cur_play_pos = pcm->GetPosition();
const int64_t iFramesUntilThisBuffer = play_pos - cur_play_pos;
const float fSecondsBeforeStart = -sounds[i]->start_time.Ago();
const int iFramesBeforeStart = int(fSecondsBeforeStart * samplerate);
const int iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( iSilentFramesInThisBuffer * bytes_per_frame, 0, bytes_left );
const int64_t iFramesBeforeStart = int64_t(fSecondsBeforeStart * samplerate);
const int64_t iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( int(iSilentFramesInThisBuffer * bytes_per_frame), 0, bytes_left );
memset( buf+bytes_read, 0, iSilentBytesInThisBuffer );
bytes_read += iSilentBytesInThisBuffer;
@@ -177,14 +178,9 @@ void RageSound_DSound_Software::StopMixing( RageSoundBase *snd )
delete sounds[i];
sounds.erase(sounds.begin()+i, sounds.begin()+i+1);
/* If nothing is playing, reset the frame count; this is just to
* prevent eventual overflow. */
if(sounds.empty())
pcm->Reset();
}
int RageSound_DSound_Software::GetPosition( const RageSoundBase *snd ) const
int64_t RageSound_DSound_Software::GetPosition( const RageSoundBase *snd ) const
{
LockMut(SOUNDMAN->lock);
return pcm->GetPosition();
@@ -15,7 +15,7 @@ class RageSound_DSound_Software: public RageSoundDriver
RageSoundBase *snd;
RageTimer start_time;
bool stopping;
int flush_pos; /* when stopping only */
int64_t flush_pos; /* when stopping only */
sound() { snd = NULL; stopping=false; }
};
@@ -38,7 +38,7 @@ class RageSound_DSound_Software: public RageSoundDriver
/* virtuals: */
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
int GetPosition( const RageSoundBase *snd ) const;
int64_t GetPosition( const RageSoundBase *snd ) const;
float GetPlayLatency() const;
int GetSampleRate( int rate ) const;
@@ -131,9 +131,9 @@ void RageSound_Null::StopMixing( RageSoundBase *snd )
sounds.erase(sounds.begin()+i, sounds.begin()+i+1);
}
int RageSound_Null::GetPosition( const RageSoundBase *snd ) const
int64_t RageSound_Null::GetPosition( const RageSoundBase *snd ) const
{
return int(RageTimer::GetTimeSinceStart() * samplerate);
return int64_t(RageTimer::GetTimeSinceStart() * samplerate);
}
RageSound_Null::RageSound_Null()
@@ -39,7 +39,7 @@ protected:
/* virtuals: */
virtual void StartMixing( RageSoundBase *snd );
virtual void StopMixing( RageSoundBase *snd );
virtual int GetPosition( const RageSoundBase *snd ) const;
virtual int64_t GetPosition( const RageSoundBase *snd ) const;
virtual float GetPlayLatency() const;
virtual void Update(float delta);
virtual bool GetData();
@@ -80,8 +80,8 @@ bool RageSound_WaveOut::GetData()
static SoundMixBuffer mix;
mix.SetVolume( SOUNDMAN->GetMixVolume() );
const int play_pos = last_cursor_pos;
const int cur_play_pos = GetPosition( NULL );
const int64_t play_pos = last_cursor_pos;
const int64_t cur_play_pos = GetPosition( NULL );
for(unsigned i = 0; i < sounds.size(); ++i)
{
@@ -94,11 +94,11 @@ bool RageSound_WaveOut::GetData()
if( !sounds[i]->start_time.IsZero() )
{
/* If the sound is supposed to start at a time past this buffer, insert silence. */
const int iFramesUntilThisBuffer = play_pos - cur_play_pos;
const int64_t iFramesUntilThisBuffer = play_pos - cur_play_pos;
const float fSecondsBeforeStart = -sounds[i]->start_time.Ago();
const int iFramesBeforeStart = int(fSecondsBeforeStart * samplerate);
const int iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( iSilentFramesInThisBuffer * bytes_per_frame, 0, bytes_left );
const int64_t iFramesBeforeStart = int64_t(fSecondsBeforeStart * samplerate);
const int64_t iSilentFramesInThisBuffer = iFramesBeforeStart-iFramesUntilThisBuffer;
const int iSilentBytesInThisBuffer = clamp( int(iSilentFramesInThisBuffer * bytes_per_frame), 0, bytes_left );
memset( buf+bytes_read, 0, iSilentBytesInThisBuffer );
bytes_read += iSilentBytesInThisBuffer;
@@ -181,7 +181,7 @@ void RageSound_WaveOut::StopMixing( RageSoundBase *snd )
sounds.erase(sounds.begin()+i, sounds.begin()+i+1);
}
int RageSound_WaveOut::GetPosition( const RageSoundBase *snd ) const
int64_t RageSound_WaveOut::GetPosition( const RageSoundBase *snd ) const
{
LockMutex L(SOUNDMAN->lock);
@@ -12,10 +12,8 @@ class RageSound_WaveOut: public RageSoundDriver
struct sound {
RageSoundBase *snd;
RageTimer start_time;
bool stopping;
int flush_pos; /* state == STOPPING only */
int64_t flush_pos; /* state == STOPPING only */
sound() { snd = NULL; stopping=false; }
};
@@ -39,7 +37,7 @@ class RageSound_WaveOut: public RageSoundDriver
/* virtuals: */
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
int GetPosition( const RageSoundBase *snd ) const;
int64_t GetPosition( const RageSoundBase *snd ) const;
float GetPlayLatency() const;
public: