Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66d28ced authored by Dave Sparks's avatar Dave Sparks
Browse files

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.
parent 72521860
Loading
Loading
Loading
Loading
+6 −5
Original line number Original line Diff line number Diff line
@@ -501,7 +501,8 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV
    }
    }
    int numChannels = sample->numChannels();
    int numChannels = sample->numChannels();
    uint32_t sampleRate = uint32_t(float(sample->sampleRate()) * rate + 0.5);
    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;
    uint32_t frameCount = 0;


    if (loop) {
    if (loop) {
@@ -510,8 +511,8 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV


#ifndef USE_SHARED_MEM_BUFFER
#ifndef USE_SHARED_MEM_BUFFER
    // Ensure minimum audio buffer size in case of short looped sample
    // Ensure minimum audio buffer size in case of short looped sample
    if(frameCount < kDefaultBufferCount * bufferFrames) {
    if(frameCount < totalFrames) {
        frameCount = kDefaultBufferCount * bufferFrames;
        frameCount = totalFrames;
    }
    }
#endif
#endif