SoundPool: Do not sleep on stop for USAGE_GAME or on BUFFER_END

Test: SoundPoolApplication, SoundPoolOggTest, Games
Bug: 139787914
Bug: 139788416
Bug: 140579743
Bug: 140779732
Merged-In: I83b9b1d61b65dcc4a73d676e1f8be1e022c70302
Change-Id: I83b9b1d61b65dcc4a73d676e1f8be1e022c70302
(cherry picked from commit a527524356)
This commit is contained in:
Andy Hung
2019-09-10 14:49:46 -07:00
parent d2469209ea
commit 3ce301c6f3

View File

@@ -951,6 +951,8 @@ void SoundChannel::process(int event, void *info, unsigned long toggle)
ALOGV("process %p channel %d event %s", ALOGV("process %p channel %d event %s",
this, mChannelID, (event == AudioTrack::EVENT_UNDERRUN) ? "UNDERRUN" : this, mChannelID, (event == AudioTrack::EVENT_UNDERRUN) ? "UNDERRUN" :
"BUFFER_END"); "BUFFER_END");
// Only BUFFER_END should happen as we use static tracks.
setVolume_l(0.f, 0.f); // set volume to 0 to indicate no need to ramp volume down.
mSoundPool->addToStopList(this); mSoundPool->addToStopList(this);
} else if (event == AudioTrack::EVENT_LOOP_END) { } else if (event == AudioTrack::EVENT_LOOP_END) {
ALOGV("End loop %p channel %d", this, mChannelID); ALOGV("End loop %p channel %d", this, mChannelID);
@@ -966,14 +968,18 @@ void SoundChannel::process(int event, void *info, unsigned long toggle)
bool SoundChannel::doStop_l() bool SoundChannel::doStop_l()
{ {
if (mState != IDLE) { if (mState != IDLE) {
setVolume_l(0, 0);
ALOGV("stop"); ALOGV("stop");
// Since we're forcibly halting the previously playing content, if (mLeftVolume != 0.f || mRightVolume != 0.f) {
// we sleep here to ensure the volume is ramped down before we stop the track. setVolume_l(0.f, 0.f);
// Ideally the sleep time is the mixer period, or an approximation thereof if (mSoundPool->attributes()->usage != AUDIO_USAGE_GAME) {
// (Fast vs Normal tracks are different). // Since we're forcibly halting the previously playing content,
// TODO: consider pausing instead of stop here. // we sleep here to ensure the volume is ramped down before we stop the track.
std::this_thread::sleep_for(std::chrono::milliseconds(20)); // Ideally the sleep time is the mixer period, or an approximation thereof
// (Fast vs Normal tracks are different).
ALOGV("sleeping: ChannelID:%d SampleID:%d", mChannelID, mSample->sampleID());
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
}
mAudioTrack->stop(); mAudioTrack->stop();
mPrevSampleID = mSample->sampleID(); mPrevSampleID = mSample->sampleID();
mSample.clear(); mSample.clear();