aaudio: reset volume ramps to avoid start glitch
When started, the volume scaler was ramping down from
the level it was at when stopped.
This could cause a short noise.
The fix is to reset the flowgraph so that the ramps
start at their target value instead of ramping to them.
Note that this CL only updates the playback side
so that it can be more easily backported.
Bug: 296270351
Bug: 297132022
Test: use repro steps at b/296270351#comment14
Change-Id: I307b76972d56b49e338b1a07b3ed921e996f2050
diff --git a/media/libaaudio/src/client/AAudioFlowGraph.h b/media/libaaudio/src/client/AAudioFlowGraph.h
index e1d517e..0c55fca 100644
--- a/media/libaaudio/src/client/AAudioFlowGraph.h
+++ b/media/libaaudio/src/client/AAudioFlowGraph.h
@@ -72,6 +72,12 @@
*/
int32_t pull(void *destination, int32_t targetFramesToRead);
+ // Reset the entire graph so that volume ramps start at their
+ // target value and sample rate converters start with no phase offset.
+ void reset() {
+ mSink->pullReset();
+ }
+
/**
* Set numFramesToWrite frames from the source into the flowgraph.
* Then, attempt to read targetFramesToRead from the flowgraph.
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index 5bac2ca..5d4c3d4 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -100,6 +100,10 @@
}
void AudioStreamInternalPlay::prepareBuffersForStart() {
+ // Reset volume ramps to avoid a starting noise.
+ // This was called here instead of AudioStreamInternal so that
+ // it will be easier to backport.
+ mFlowGraph.reset();
// Prevent stale data from being played.
mAudioEndpoint->eraseDataMemory();
}