summaryrefslogtreecommitdiffstats
path: root/libaudio
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2010-11-15 15:17:12 -0800
committerEric Laurent <elaurent@google.com>2010-11-30 16:19:19 -0800
commitee0ab9299099b9f5e0e3577ffe407ae2e8be2455 (patch)
tree5203a1e7e380b425414e38db59e63044a070bebb /libaudio
parent1b7e599fa49ef8bc2e1292dd60a3ae603bbbf0bb (diff)
downloaddevice_samsung_crespo-ee0ab9299099b9f5e0e3577ffe407ae2e8be2455.zip
device_samsung_crespo-ee0ab9299099b9f5e0e3577ffe407ae2e8be2455.tar.gz
device_samsung_crespo-ee0ab9299099b9f5e0e3577ffe407ae2e8be2455.tar.bz2
Fix issue 3198397
Use only 15 bits for fractional part of the increment in resample_441_320() to avoid overflow when multiplying by the difference between previous and next samples in interpolated value computation. Change-Id: I9f5a726d11f6b051db390df3d13312f1ee782d3a
Diffstat (limited to 'libaudio')
-rw-r--r--libaudio/AudioHardware.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
index 10409a1..4cca932 100644
--- a/libaudio/AudioHardware.cpp
+++ b/libaudio/AudioHardware.cpp
@@ -1771,16 +1771,17 @@ void resample_441_320(int16_t* input, int16_t* output, int* num_samples_in, int*
}
const float step_float = (float)RESAMPLE_16KHZ_SAMPLES_IN / (float)RESAMPLE_16KHZ_SAMPLES_OUT;
+ const uint32_t step = (uint32_t)(step_float * 32768.0f + 0.5f); // 17.15 fixed point
- uint32_t in_sample_num = 0; // 16.16 fixed point
- const uint32_t step = (uint32_t)(step_float * 65536.0f + 0.5f); // 16.16 fixed point
+ uint32_t in_sample_num = 0; // 17.15 fixed point
for (int j = 0; j < RESAMPLE_16KHZ_SAMPLES_OUT; ++j, in_sample_num += step) {
- const uint32_t whole = in_sample_num >> 16;
- const uint32_t frac = (in_sample_num & 0xffff); // 0.16 fixed point
+ const uint32_t whole = in_sample_num >> 15;
+ const uint32_t frac = (in_sample_num & 0x7fff); // 0.15 fixed point
const int32_t s1 = tmp[whole];
const int32_t s2 = tmp[whole + 1];
- *output++ = clip(s1 + (((s2 - s1) * (int32_t)frac) >> 16));
+ *output++ = clip(s1 + (((s2 - s1) * (int32_t)frac) >> 15));
}
+
}
const int samples_consumed = num_blocks * RESAMPLE_16KHZ_SAMPLES_IN;