summaryrefslogtreecommitdiffstats
path: root/media/libmedia/ToneGenerator.cpp
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2009-10-05 20:29:18 -0700
committerEric Laurent <elaurent@google.com>2009-10-06 18:59:35 -0700
commite33e00e931d1381d402484aa5cde67e540e3c82c (patch)
tree406a97eb4bfe9bfb0d472cd4b7758d4518f8daee /media/libmedia/ToneGenerator.cpp
parent5bffa09d4483ac31de42077d05d24ba26fab928d (diff)
downloadframeworks_av-e33e00e931d1381d402484aa5cde67e540e3c82c.zip
frameworks_av-e33e00e931d1381d402484aa5cde67e540e3c82c.tar.gz
frameworks_av-e33e00e931d1381d402484aa5cde67e540e3c82c.tar.bz2
Fix issue 2139634: DTMF tones on Sholes popping, hissing (audio latency too high).
This change is a complement to the main fix in kernel driver for the same issue (partner change #1250). It removes clicks sometimes heard after the end of the tones while audio flinger is sending 0s to the audio output stream. The problem was that the sleep time between two writes was more than the duration of one audio output stream buffer which could cause some underrun. Also fixed a recent regression in ToneGenerator that made that the end of previous tone was repeated at the beginning of current one under certain timing circumstances when the maximum tone duration was specified.
Diffstat (limited to 'media/libmedia/ToneGenerator.cpp')
-rw-r--r--media/libmedia/ToneGenerator.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index d36bec9..3729eb3 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -879,6 +879,7 @@ ToneGenerator::~ToneGenerator() {
////////////////////////////////////////////////////////////////////////////////
bool ToneGenerator::startTone(int toneType, int durationMs) {
bool lResult = false;
+ status_t lStatus;
if ((toneType < 0) || (toneType >= NUM_TONES))
return lResult;
@@ -898,15 +899,16 @@ bool ToneGenerator::startTone(int toneType, int durationMs) {
toneType = getToneForRegion(toneType);
mpNewToneDesc = &sToneDescriptors[toneType];
- if (durationMs == -1) {
- mMaxSmp = TONEGEN_INF;
- } else {
- if (durationMs > (int)(TONEGEN_INF / mSamplingRate)) {
- mMaxSmp = (durationMs / 1000) * mSamplingRate;
- } else {
- mMaxSmp = (durationMs * mSamplingRate) / 1000;
+ mDurationMs = durationMs;
+
+ if (mState == TONE_STOPPED) {
+ LOGV("Start waiting for previous tone to stop");
+ lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
+ if (lStatus != NO_ERROR) {
+ LOGE("--- start wait for stop timed out, status %d", lStatus);
+ mState = TONE_IDLE;
+ return lResult;
}
- LOGV("startTone, duration limited to %d ms", durationMs);
}
if (mState == TONE_INIT) {
@@ -919,7 +921,7 @@ bool ToneGenerator::startTone(int toneType, int durationMs) {
mLock.lock();
if (mState == TONE_STARTING) {
LOGV("Wait for start callback");
- status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
+ lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
if (lStatus != NO_ERROR) {
LOGE("--- Immediate start timed out, status %d", lStatus);
mState = TONE_IDLE;
@@ -931,9 +933,8 @@ bool ToneGenerator::startTone(int toneType, int durationMs) {
}
} else {
LOGV("Delayed start\n");
-
mState = TONE_RESTARTING;
- status_t lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
+ lStatus = mWaitCbkCond.waitRelative(mLock, seconds(1));
if (lStatus == NO_ERROR) {
if (mState != TONE_IDLE) {
lResult = true;
@@ -1316,6 +1317,17 @@ bool ToneGenerator::prepareWave() {
mpToneDesc = mpNewToneDesc;
+ if (mDurationMs == -1) {
+ mMaxSmp = TONEGEN_INF;
+ } else {
+ if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
+ mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
+ } else {
+ mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
+ }
+ LOGV("prepareWave, duration limited to %d ms", mDurationMs);
+ }
+
while (mpToneDesc->segments[segmentIdx].duration) {
// Get total number of sine waves: needed to adapt sine wave gain.
unsigned int lNumWaves = numWaves(segmentIdx);