diff options
author | Dave Sparks <davidsparks@android.com> | 2009-12-14 21:12:05 -0800 |
---|---|---|
committer | Dave Sparks <davidsparks@android.com> | 2009-12-14 21:48:17 -0800 |
commit | 66d28cedd92dcc1669ace23231da1b8c1374ff2f (patch) | |
tree | 5e667867fb0a9f87aad5a9be18dca97b7195dca9 /media/jni/soundpool/SoundPool.cpp | |
parent | 725218602e8505cd6fe3075253fcb792727e2431 (diff) | |
download | frameworks_base-66d28cedd92dcc1669ace23231da1b8c1374ff2f.zip frameworks_base-66d28cedd92dcc1669ace23231da1b8c1374ff2f.tar.gz frameworks_base-66d28cedd92dcc1669ace23231da1b8c1374ff2f.tar.bz2 |
Fix SoundPool buffer size rounding error. Bug 2327620.
AudioTrack was modified earlier to calculate minimum buffer size
based on the hardware reported latency. Previously, it was a
hard-coded value. As a result of this change, the minimum buffer
size is now variable based on hardware latency. On Passion, this
brought out a subtle rounding error in the buffer size calculation
in SoundPool. This can cause AudioTrack creation to fail based on
the requested sample rate. This fix calculates the total buffer
size first, and then does rounding before dividing by the number
of buffers.
Diffstat (limited to 'media/jni/soundpool/SoundPool.cpp')
-rw-r--r-- | media/jni/soundpool/SoundPool.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index b17e31b..c6b7aba 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -501,7 +501,8 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV } int numChannels = sample->numChannels(); uint32_t sampleRate = uint32_t(float(sample->sampleRate()) * rate + 0.5); - uint32_t bufferFrames = (afFrameCount * sampleRate) / afSampleRate; + uint32_t totalFrames = (kDefaultBufferCount * afFrameCount * sampleRate) / afSampleRate; + uint32_t bufferFrames = (totalFrames + (kDefaultBufferCount - 1)) / kDefaultBufferCount; uint32_t frameCount = 0; if (loop) { @@ -510,13 +511,13 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV #ifndef USE_SHARED_MEM_BUFFER // Ensure minimum audio buffer size in case of short looped sample - if(frameCount < kDefaultBufferCount * bufferFrames) { - frameCount = kDefaultBufferCount * bufferFrames; + if(frameCount < totalFrames) { + frameCount = totalFrames; } #endif AudioTrack* newTrack; - + // mToggle toggles each time a track is started on a given channel. // The toggle is concatenated with the SoundChannel address and passed to AudioTrack // as callback user data. This enables the detection of callbacks received from the old @@ -525,7 +526,7 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV unsigned long toggle = mToggle ^ 1; void *userData = (void *)((unsigned long)this | toggle); uint32_t channels = (numChannels == 2) ? AudioSystem::CHANNEL_OUT_STEREO : AudioSystem::CHANNEL_OUT_MONO; - + #ifdef USE_SHARED_MEM_BUFFER newTrack = new AudioTrack(streamType, sampleRate, sample->format(), channels, sample->getIMemory(), 0, callback, userData); |