diff options
author | James Dong <jdong@google.com> | 2010-06-24 19:55:31 -0700 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-06-24 21:59:25 -0700 |
commit | d3d4e5069e1af0437c4f5a7b4ba344bda5b937af (patch) | |
tree | 596bf02fa9495c743c1069ecb99b5f134afac850 /media/libstagefright/AudioSource.cpp | |
parent | 47c778f4a5fa639b2082fcc74080d33ac847b232 (diff) | |
download | frameworks_av-d3d4e5069e1af0437c4f5a7b4ba344bda5b937af.zip frameworks_av-d3d4e5069e1af0437c4f5a7b4ba344bda5b937af.tar.gz frameworks_av-d3d4e5069e1af0437c4f5a7b4ba344bda5b937af.tar.bz2 |
Track maximum amplitude and fix getMaxAmplitude()
- only start to track the max amplitude after the first call to getMaxAmplitude()
Change-Id: I64d3d9ca0542202a8535a211425e8bccceca50fc
Diffstat (limited to 'media/libstagefright/AudioSource.cpp')
-rw-r--r-- | media/libstagefright/AudioSource.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp index d203dbf..6031797 100644 --- a/media/libstagefright/AudioSource.cpp +++ b/media/libstagefright/AudioSource.cpp @@ -78,6 +78,8 @@ status_t AudioSource::start(MetaData *params) { mCollectStats = true; } + mTrackMaxAmplitude = false; + mMaxAmplitude = 0; mStartTimeUs = 0; int64_t startTimeUs; if (params && params->findInt64(kKeyTime, &startTimeUs)) { @@ -168,6 +170,10 @@ status_t AudioSource::read( return (status_t)n; } + if (mTrackMaxAmplitude) { + trackMaxAmplitude((int16_t *) buffer->data(), n >> 1); + } + uint32_t sampleRate = mRecord->getSampleRate(); int64_t timestampUs = (1000000LL * numFramesRecorded) / sampleRate + mStartTimeUs; buffer->meta_data()->setInt64(kKeyTime, timestampUs); @@ -181,4 +187,27 @@ status_t AudioSource::read( return OK; } +void AudioSource::trackMaxAmplitude(int16_t *data, int nSamples) { + for (int i = nSamples; i > 0; --i) { + int16_t value = *data++; + if (value < 0) { + value = -value; + } + if (mMaxAmplitude < value) { + mMaxAmplitude = value; + } + } +} + +int16_t AudioSource::getMaxAmplitude() { + // First call activates the tracking. + if (!mTrackMaxAmplitude) { + mTrackMaxAmplitude = true; + } + int16_t value = mMaxAmplitude; + mMaxAmplitude = 0; + LOGV("max amplitude since last call: %d", value); + return value; +} + } // namespace android |