From 9b53daddaa32cbc377995e83ce169081ee7989ed Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 18 Oct 2010 11:48:36 -0700 Subject: Issue 3058745: fix audio HAL downsampler. Latest audio HAL downsampler implementation had a problem that caused one sample to be dropped if the input buffer size was odd while downsampling by a factor of 2. This explains why record timing was correct for 22 and 16kHz but not for 11 or 8kHz: in the later case, the second stage of resampling (22 to 11) receives 503 frames for each buffer. Change-Id: Ib8fcba3ddfbbab50a908e6b0a6cdc2b398acd862 --- libaudio/AudioHardwareALSA.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'libaudio') diff --git a/libaudio/AudioHardwareALSA.cpp b/libaudio/AudioHardwareALSA.cpp index 6c8a610..4df3c42 100755 --- a/libaudio/AudioHardwareALSA.cpp +++ b/libaudio/AudioHardwareALSA.cpp @@ -2305,13 +2305,16 @@ void resample_2_1(int16_t* input, int16_t* output, int* num_samples_in, int* num return; } - for (int i = 0; i < *num_samples_in - (int)OVERLAP_22KHZ; i += 2) { - output[i / 2] = clip(fir_convolve(input + i, filter_22khz_coeff, NUM_COEFF_22KHZ)); - } + int odd_smp = *num_samples_in & 0x1; + int num_samples = *num_samples_in - odd_smp - OVERLAP_22KHZ; + + for (int i = 0; i < num_samples; i += 2) { + output[i / 2] = clip(fir_convolve(input + i, filter_22khz_coeff, NUM_COEFF_22KHZ)); + } - memmove(input, input + *num_samples_in - OVERLAP_22KHZ, OVERLAP_22KHZ * sizeof(*input)); - *num_samples_out = (*num_samples_in - OVERLAP_22KHZ) / 2; - *num_samples_in = OVERLAP_22KHZ; + memmove(input, input + num_samples, (OVERLAP_22KHZ + odd_smp) * sizeof(*input)); + *num_samples_out = num_samples / 2; + *num_samples_in = OVERLAP_22KHZ + odd_smp; } /* -- cgit v1.1