remove "fake" sounds
This commit is contained in:
@@ -61,24 +61,10 @@ void RageSoundManager::StopMixing(RageSound *snd)
|
|||||||
sounds_to_delete.insert(snd);
|
sounds_to_delete.insert(snd);
|
||||||
owned_sounds.erase(snd);
|
owned_sounds.erase(snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
map<RageSound *, FakeSound>::iterator fake =
|
|
||||||
fake_sounds.find(const_cast<RageSound *>(snd));
|
|
||||||
if(fake != fake_sounds.end())
|
|
||||||
fake_sounds.erase(fake);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundManager::GetPosition(const RageSound *snd) const
|
int RageSoundManager::GetPosition(const RageSound *snd) const
|
||||||
{
|
{
|
||||||
map<RageSound *, FakeSound>::const_iterator fake =
|
|
||||||
fake_sounds.find(const_cast<RageSound *>(snd));
|
|
||||||
if(fake != fake_sounds.end())
|
|
||||||
{
|
|
||||||
float time_since = RageTimer::GetTimeSinceStart() - fake->second.begin;
|
|
||||||
|
|
||||||
return int(time_since * 44100); // XXX
|
|
||||||
}
|
|
||||||
|
|
||||||
return driver->GetPosition(snd);
|
return driver->GetPosition(snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,45 +81,6 @@ void RageSoundManager::Update(float delta)
|
|||||||
(*i)->Update(delta);
|
(*i)->Update(delta);
|
||||||
|
|
||||||
driver->Update(delta);
|
driver->Update(delta);
|
||||||
|
|
||||||
/* We keep a list of "fake" sound effects. These are sound effects that
|
|
||||||
* have been requested to play, but the driver couldn't play them; usually
|
|
||||||
* because it's run out of sound channels. Pretend we're playing them,
|
|
||||||
* since this should be uncommon. */
|
|
||||||
{
|
|
||||||
char buf[1024*16];
|
|
||||||
map<RageSound *, FakeSound>::iterator j = fake_sounds.begin(),
|
|
||||||
next = j;
|
|
||||||
while(j != fake_sounds.end())
|
|
||||||
{
|
|
||||||
next++;
|
|
||||||
|
|
||||||
RageSound *s = j->first;
|
|
||||||
FakeSound &fake = j->second;
|
|
||||||
|
|
||||||
int bytes = int(min(unsigned(delta * 44100*4), sizeof(buf)));
|
|
||||||
|
|
||||||
int now = int(RageTimer::GetTimeSinceStart() - fake.begin) * 44100;
|
|
||||||
|
|
||||||
int got = s->GetPCM(buf, bytes, now);
|
|
||||||
if(got < bytes)
|
|
||||||
s->StopPlaying();
|
|
||||||
|
|
||||||
j = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RageSoundManager::AddFakeSound(RageSound *snd)
|
|
||||||
{
|
|
||||||
map<RageSound *, FakeSound>::const_iterator fake =
|
|
||||||
fake_sounds.find(const_cast<RageSound *>(snd));
|
|
||||||
|
|
||||||
ASSERT(fake == fake_sounds.end());
|
|
||||||
FakeSound newfake;
|
|
||||||
newfake.begin = RageTimer::GetTimeSinceStart();
|
|
||||||
newfake.samples_read = 0;
|
|
||||||
fake_sounds[snd] = newfake;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float RageSoundManager::GetPlayLatency() const
|
float RageSoundManager::GetPlayLatency() const
|
||||||
|
|||||||
@@ -18,12 +18,6 @@ class RageSoundManager
|
|||||||
/* Set of sounds that are finished and should be deleted. */
|
/* Set of sounds that are finished and should be deleted. */
|
||||||
set<RageSound *> sounds_to_delete;
|
set<RageSound *> sounds_to_delete;
|
||||||
|
|
||||||
struct FakeSound {
|
|
||||||
float begin;
|
|
||||||
int samples_read;
|
|
||||||
};
|
|
||||||
map<RageSound *, FakeSound> fake_sounds;
|
|
||||||
|
|
||||||
RageSoundDriver *driver;
|
RageSoundDriver *driver;
|
||||||
|
|
||||||
/* Prefs: */
|
/* Prefs: */
|
||||||
@@ -42,7 +36,6 @@ public:
|
|||||||
void StartMixing(RageSound *snd); /* used by RageSound */
|
void StartMixing(RageSound *snd); /* used by RageSound */
|
||||||
void StopMixing(RageSound *snd); /* used by RageSound */
|
void StopMixing(RageSound *snd); /* used by RageSound */
|
||||||
int GetPosition(const RageSound *snd) const; /* used by RageSound */
|
int GetPosition(const RageSound *snd) const; /* used by RageSound */
|
||||||
void AddFakeSound(RageSound *snd); /* used by drivers */
|
|
||||||
float GetPlayLatency() const;
|
float GetPlayLatency() const;
|
||||||
int GetDriverSampleRate( int rate ) const;
|
int GetDriverSampleRate( int rate ) const;
|
||||||
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
||||||
@@ -52,6 +45,7 @@ public:
|
|||||||
|
|
||||||
RageSound *PlaySound(RageSound &snd);
|
RageSound *PlaySound(RageSound &snd);
|
||||||
void StopPlayingSound(RageSound &snd);
|
void StopPlayingSound(RageSound &snd);
|
||||||
|
|
||||||
/* A list of all sounds that currently exist. RageSound adds and removes
|
/* A list of all sounds that currently exist. RageSound adds and removes
|
||||||
* itself to this. */
|
* itself to this. */
|
||||||
set<RageSound *> all_sounds;
|
set<RageSound *> all_sounds;
|
||||||
|
|||||||
Reference in New Issue
Block a user