From 5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Mon, 23 Jun 2014 19:07:29 -0700 Subject: Add floating point volume handling to AudioMixer Use floating point volume in AudioMixer mixing when floating point input is used with the new mixer engine. AudioResampler is updated to take floating point volume to match. Both legacy integer and floating point mixer engines work. For now, integer volume is used when the new mixer engine runs in integer input mode, for backward compatibility with the legacy mixer. The new mixer engine will generally run in floating point input mode. When the legacy path is removed, the integer volumes will be removed. Change-Id: I79e80c292ae7c8b8bdd0aa371a1b2c3a1b618290 --- services/audioflinger/test-resample.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'services/audioflinger/test-resample.cpp') diff --git a/services/audioflinger/test-resample.cpp b/services/audioflinger/test-resample.cpp index 78c9927..84a655a 100644 --- a/services/audioflinger/test-resample.cpp +++ b/services/audioflinger/test-resample.cpp @@ -383,20 +383,8 @@ int main(int argc, char* argv[]) { AudioResampler* resampler = AudioResampler::create(format, channels, output_freq, quality); - - /* set volume precision to 12 bits, so the volume scale is 1<<12. - * The output int32_t is represented as Q4.27, with 4 bits of guard - * followed by the int16_t Q.15 portion, and then 12 trailing bits of - * additional precision. - * - * Generally 0 < volumePrecision <= 14 (due to the limits of - * int16_t values for Volume). volumePrecision cannot be 0 due - * to rounding and shifts. - */ - const int volumePrecision = 12; // in bits - resampler->setSampleRate(input_freq); - resampler->setVolume(1 << volumePrecision, 1 << volumePrecision); + resampler->setVolume(AudioResampler::UNITY_GAIN_FLOAT, AudioResampler::UNITY_GAIN_FLOAT); if (profileResample) { /* @@ -481,19 +469,20 @@ int main(int argc, char* argv[]) { int32_t* out = (int32_t*) output_vaddr; int16_t* convert = (int16_t*) malloc(output_frames * channels * sizeof(int16_t)); + const int volumeShift = 12; // shift requirement for Q4.27 to Q.15 // round to half towards zero and saturate at int16 (non-dithered) - const int roundVal = (1<<(volumePrecision-1)) - 1; // volumePrecision > 0 + const int roundVal = (1<<(volumeShift-1)) - 1; // volumePrecision > 0 for (size_t i = 0; i < output_frames; i++) { for (int j = 0; j < channels; j++) { int32_t s = out[i * output_channels + j] + roundVal; // add offset here if (s < 0) { - s = (s + 1) >> volumePrecision; // round to 0 + s = (s + 1) >> volumeShift; // round to 0 if (s < -32768) { s = -32768; } } else { - s = s >> volumePrecision; + s = s >> volumeShift; if (s > 32767) { s = 32767; } -- cgit v1.1