summaryrefslogtreecommitdiffstats
path: root/libaudio
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2010-10-18 11:48:36 -0700
committerEric Laurent <elaurent@google.com>2010-10-18 11:57:27 -0700
commit9b53daddaa32cbc377995e83ce169081ee7989ed (patch)
treef73161eb3222cda921767c3551731d196c43d30f /libaudio
parent04cdb18b02e0275b4c369b254224afdcbef7920d (diff)
downloaddevice_samsung_crespo-9b53daddaa32cbc377995e83ce169081ee7989ed.zip
device_samsung_crespo-9b53daddaa32cbc377995e83ce169081ee7989ed.tar.gz
device_samsung_crespo-9b53daddaa32cbc377995e83ce169081ee7989ed.tar.bz2
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
Diffstat (limited to 'libaudio')
-rwxr-xr-xlibaudio/AudioHardwareALSA.cpp15
1 files changed, 9 insertions, 6 deletions
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;
}
/*