aaudio: prevent noise when stopping a stream
The DSP is stopped after the callback is stopped.
If the CPU is slow and the time gap is too large then
the DSP can play past the valid data and play invalid data.
To prevent noise, this new code clears part of the FIFO
beyond the valid data. Then when the DSP has read the valid
data it clears the entire FIFO.
Then it waits for the valid data to reach the speaker,
based on a latency estimation using timestamps.
Bug: 261783315
Test: Use OboeTester with repro steps in the bug.
Change-Id: Ia31df4b21c805b4ae9ca4fb8366068be1cce2c9f
diff --git a/media/libaaudio/src/fifo/FifoBuffer.h b/media/libaaudio/src/fifo/FifoBuffer.h
index 7b0aca1..860ccad 100644
--- a/media/libaaudio/src/fifo/FifoBuffer.h
+++ b/media/libaaudio/src/fifo/FifoBuffer.h
@@ -115,6 +115,13 @@
*/
void eraseMemory();
+ /**
+ * Clear some memory after the write pointer.
+ * This can be used to prevent the reader from accidentally reading stale data
+ * in case it is reading asynchronously.
+ */
+ fifo_frames_t eraseEmptyMemory(fifo_frames_t numFrames);
+
protected:
virtual uint8_t *getStorage() const = 0;