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

Commit bb6f0a0b authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Fix underruns when sample rate != native sample rate

This forces a minimum of 3 application buffers when the sample rates
don't match, using the normal mixer and low latency HAL.

There is still an issue that the latency() varies depending on whether
screen was off or on at the time of creating the AudioTrack.

With screen on:
I/AudioTrack( 2028): afFrameCount=960, minBufCount=2, afSampleRate=48000, afLatency=50
I/AudioTrack( 2028): minFrameCount: 2646, afFrameCount=960, minBufCount=3, sampleRate=44100, afSampleRate=48000, afLatency=50

With screen off:
I/AudioTrack( 2817): afFrameCount=960, minBufCount=4, afSampleRate=48000, afLatency=84
I/AudioTrack( 2817): minFrameCount: 3528, afFrameCount=960, minBufCount=4, sampleRate=44100, afSampleRate=48000, afLatency=84

Change-Id: Ib45515edff2afcd672dda34881b658c800ffc25a
parent 587f8425
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -861,8 +861,10 @@ status_t AudioTrack::createTrack_l(

        // Ensure that buffer depth covers at least audio hardware latency
        uint32_t minBufCount = afLatency / ((1000 * afFrameCount)/afSampleRate);
        if (minBufCount < 2) {
            minBufCount = 2;
        ALOGV("afFrameCount=%d, minBufCount=%d, afSampleRate=%u, afLatency=%d",
                afFrameCount, minBufCount, afSampleRate, afLatency);
        if (minBufCount <= 2) {
            minBufCount = sampleRate == afSampleRate ? 2 : 3;
        }

        size_t minFrameCount = (afFrameCount*sampleRate*minBufCount)/afSampleRate;