audioflinger: Fix for removing noise while resuming playback after pause
-Issue: While resuming playback after pausing and seeking to backward,
there is a noise.
-Rootcause: When Resuming a Playback after Pausing and seeking,
AudioResampler's reset() function is resetting their member
variables but derived classes' s member variable are not resetting.
This is causing a noise in Playback because AudioResamplerSinc,
AudioResamplerOrder1 and AudioResamplerCubic's member variables
pointing to some previous state/values.
-Fix: To reset the derived class member variables,
override the reset function in all the derived classes.
Change-Id: I0584947ac203f9470cdc4a680ebccadf60e4e7db
CRs-Fixed: 482838
diff --git a/services/audioflinger/AudioResampler.cpp b/services/audioflinger/AudioResampler.cpp
index 2c3c719..48c189c 100644
--- a/services/audioflinger/AudioResampler.cpp
+++ b/services/audioflinger/AudioResampler.cpp
@@ -52,6 +52,7 @@
static const int kPreInterpShift = kNumPhaseBits - kNumInterpBits;
void init() {}
+ void reset();
void resampleMono16(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider);
void resampleStereo16(int32_t* out, size_t outFrameCount,
@@ -294,6 +295,14 @@
}
}
+void AudioResamplerOrder1::reset() {
+ mInputIndex = 0;
+ mPhaseFraction = 0;
+ mBuffer.frameCount = 0;
+ mX0L = 0;
+ mX0R = 0;
+}
+
void AudioResamplerOrder1::resampleStereo16(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider) {
diff --git a/services/audioflinger/AudioResamplerCubic.cpp b/services/audioflinger/AudioResamplerCubic.cpp
index 18e59e9..ff4e473 100644
--- a/services/audioflinger/AudioResamplerCubic.cpp
+++ b/services/audioflinger/AudioResamplerCubic.cpp
@@ -32,6 +32,14 @@
memset(&right, 0, sizeof(state));
}
+void AudioResamplerCubic::reset(){
+ mInputIndex = 0;
+ mPhaseFraction = 0;
+ mBuffer.frameCount = 0;
+ memset(&left, 0, sizeof(state));
+ memset(&right, 0, sizeof(state));
+}
+
void AudioResamplerCubic::resample(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider) {
diff --git a/services/audioflinger/AudioResamplerCubic.h b/services/audioflinger/AudioResamplerCubic.h
index 203b933..5ec38ee 100644
--- a/services/audioflinger/AudioResamplerCubic.h
+++ b/services/audioflinger/AudioResamplerCubic.h
@@ -43,6 +43,7 @@
int32_t a, b, c, y0, y1, y2, y3;
} state;
void init();
+ void reset ();
void resampleMono16(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider);
void resampleStereo16(int32_t* out, size_t outFrameCount,
diff --git a/services/audioflinger/AudioResamplerSinc.cpp b/services/audioflinger/AudioResamplerSinc.cpp
index 207f26b..60cfef7 100644
--- a/services/audioflinger/AudioResamplerSinc.cpp
+++ b/services/audioflinger/AudioResamplerSinc.cpp
@@ -497,6 +497,15 @@
mRingFull = mImpulse + (numCoefs+1)*mChannelCount;
}
+void AudioResamplerSinc::reset(){
+ mInputIndex = 0;
+ mPhaseFraction = 0;
+ mBuffer.frameCount = 0;
+ const Constants& c(*mConstants);
+ const size_t stateSize = (2*c.halfNumCoefs) * mChannelCount * 2;
+ memset(mState, 0, sizeof(int16_t)*stateSize);
+}
+
void AudioResamplerSinc::setVolume(int16_t left, int16_t right) {
AudioResampler::setVolume(left, right);
mVolumeSIMD[0] = int32_t(left)<<16;
diff --git a/services/audioflinger/AudioResamplerSinc.h b/services/audioflinger/AudioResamplerSinc.h
index 1ea4474..636586f 100644
--- a/services/audioflinger/AudioResamplerSinc.h
+++ b/services/audioflinger/AudioResamplerSinc.h
@@ -44,6 +44,8 @@
private:
void init();
+ void reset();
+
virtual void setVolume(int16_t left, int16_t right);
template<int CHANNELS>