aboutsummaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorSahil Sachdeva <sahils@google.com>2009-09-29 23:32:55 -0700
committerSahil Sachdeva <sahils@google.com>2009-09-30 14:49:52 -0700
commitf63fa1c0ee556c330a8ec8a182de996f658c3f98 (patch)
tree766bc9a825a23301fb5fb5887dc965324428c5a9 /android
parentdbb9b662d2787ccba7f2211569a2126ee1309ead (diff)
downloadopencore-f63fa1c0ee556c330a8ec8a182de996f658c3f98.tar.gz
Fix the AudioRecord Latency in Audio Input MIO.
Calculate the correct latency based on Opencore BufferSize and KernelBufferSize.
Diffstat (limited to 'android')
-rw-r--r--android/author/android_audio_input.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/android/author/android_audio_input.cpp b/android/author/android_audio_input.cpp
index 27d647a4a..27bb68140 100644
--- a/android/author/android_audio_input.cpp
+++ b/android/author/android_audio_input.cpp
@@ -1175,8 +1175,22 @@ int AndroidAudioInput::audin_thread_func() {
// The difference in 2 will give the actual time
// of first audio capture.
uint32 systime = (uint32) (systemTime() / 1000000L);
- // TODO: add audio hardware input latency here
- uint32 recordLatency = record->latency();
+ uint32 recordLatency = 0;
+
+ // Get the latency now
+ size_t kernelBufferSize = 0;
+ status_t ret = AudioSystem::getInputBufferSize(iAudioSamplingRate,
+ AudioSystem::PCM_16_BIT,
+ iAudioNumChannels, &kernelBufferSize);
+
+ if (ret == NO_ERROR) {
+ uint32 readBufferFrames = kBufferSize/2/iAudioNumChannels;
+ uint32 kernelFrames = kernelBufferSize/2/iAudioNumChannels;
+ recordLatency = ((readBufferFrames - 1)/kernelFrames + 1) * (kernelFrames*1000)/iAudioSamplingRate;
+ } else {
+ LOGE("AudioSystem::getInputBufferSize returned error");
+ }
+
iFirstFrameTs = systime - recordLatency;
LOGV("First Audio Frame received systime %d, recordLatency %d, iFirstFrameTs %d", systime, recordLatency, iFirstFrameTs);
}