From 4062d0f4e7e83c14e0503a264f2a1616d9968c5b Mon Sep 17 00:00:00 2001 From: "fbarchard@chromium.org" Date: Tue, 4 May 2010 02:17:28 +0000 Subject: Revert 46314 - floating point audio support in util functions for volume and folding BUG=42861 TEST=none Review URL: http://codereview.chromium.org/1856002 TBR=fbarchard@chromium.org Review URL: http://codereview.chromium.org/1926001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46320 0039d316-1c4b-4281-b951-d872f2087c98 --- media/audio/audio_util.cc | 57 ++++++++--------------------------- media/audio/audio_util_unittest.cc | 33 +++++++++----------- media/audio/win/waveout_output_win.cc | 4 +-- 3 files changed, 29 insertions(+), 65 deletions(-) (limited to 'media') diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index d72cbe7..8774a72 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -24,20 +24,15 @@ static int ScaleChannel(int channel, int volume) { } template -static void AdjustVolume(Format* buf_out, int sample_count, int fixed_volume) { +void AdjustVolume(Format* buf_out, + int sample_count, + int fixed_volume) { for (int i = 0; i < sample_count; ++i) { buf_out[i] = static_cast(ScaleChannel(buf_out[i] - bias, fixed_volume) + bias); } } -static void AdjustVolumeFloat(float* buf_out, int sample_count, float volume) { - for (int i = 0; i < sample_count; ++i) { - buf_out[i] = buf_out[i] * volume; - } -} - - // Channel order for AAC // From http://www.hydrogenaudio.org/forums/lofiversion/index.php/t40046.html @@ -46,7 +41,8 @@ static const int kChannel_L = 1; static const int kChannel_R = 2; template -static int AddChannel(int val, int adder) { +static int AddChannel(int val, + int adder) { Fixed sum = static_cast(val) + static_cast(adder); if (sum > max_value) return max_value; @@ -66,9 +62,9 @@ static int AddChannel(int val, int adder) { template static void FoldChannels(Format* buf_out, - int sample_count, - const float volume, - int channels) { + int sample_count, + const float volume, + int channels) { Format* buf_in = buf_out; const int center_volume = static_cast(volume * 0.707f * 65536); const int fixed_volume = static_cast(volume * 65536); @@ -91,31 +87,6 @@ static void FoldChannels(Format* buf_out, buf_in += channels; } } - -static void FoldChannelsFloat(float* buf_out, - int sample_count, - const float volume, - int channels) { - float* buf_in = buf_out; - const float center_volume = volume * 0.707f; - - for (int i = 0; i < sample_count; ++i) { - float center = buf_in[kChannel_C]; - float left = buf_in[kChannel_L]; - float right = buf_in[kChannel_R]; - - center = center * center_volume; - left = left * volume; - right = right * volume; - - buf_out[0] = left + center; - buf_out[1] = right + center; - - buf_out += 2; - buf_in += channels; - } -} - } // namespace // AdjustVolume() does an in place audio sample change. @@ -146,10 +117,9 @@ bool AdjustVolume(void* buf, fixed_volume); return true; } else if (bytes_per_sample == 4) { - // 4 byte per sample is float. - AdjustVolumeFloat(reinterpret_cast(buf), - sample_count, - volume); + AdjustVolume(reinterpret_cast(buf), + sample_count, + fixed_volume); return true; } } @@ -180,9 +150,8 @@ bool FoldChannels(void* buf, channels); return true; } else if (bytes_per_sample == 4) { - // 4 byte per sample is float. - FoldChannelsFloat( - reinterpret_cast(buf), + FoldChannels( + reinterpret_cast(buf), sample_count, volume, channels); diff --git a/media/audio/audio_util_unittest.cc b/media/audio/audio_util_unittest.cc index 22e9afe..c0ed0fc 100644 --- a/media/audio/audio_util_unittest.cc +++ b/media/audio/audio_util_unittest.cc @@ -66,19 +66,16 @@ TEST(AudioUtilTest, AdjustVolume_s16_one) { EXPECT_EQ(0, expected_test); } -TEST(AudioUtilTest, AdjustVolume_f32) { +TEST(AudioUtilTest, AdjustVolume_s32) { // Test AdjustVolume() on 32 bit samples. - float samples_f32[kNumberOfSamples] = { -4.0f, 0.5f, -.05f, 123.0f }; - float expected_f32[kNumberOfSamples] = { -4.0f * 0.25f, - 0.5f * 0.25f, - -.05f * 0.25f, - 123.0f * 0.25f }; - bool result_f32 = media::AdjustVolume(samples_f32, sizeof(samples_f32), + int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; + int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; + bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), 4, // channels. - sizeof(samples_f32[0]), + sizeof(samples_s32[0]), 0.25f); - EXPECT_EQ(true, result_f32); - int expected_test = memcmp(samples_f32, expected_f32, sizeof(expected_f32)); + EXPECT_EQ(true, result_s32); + int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); EXPECT_EQ(0, expected_test); } @@ -112,17 +109,17 @@ TEST(AudioUtilTest, FoldChannels_s16) { EXPECT_EQ(0, expected_test); } -TEST(AudioUtilTest, FoldChannels_f32) { +TEST(AudioUtilTest, FoldChannels_s32) { // Test FoldChannels() on 32 bit samples. - float samples_f32[6] = { 12.0f, 1.0f, 3.0f, 7.0f, 13.0f, 17.0f }; - float expected_f32[2] = { 12.0f * .707f + 1.0f, - 12.0f * .707f + 3.0f }; - bool result_f32 = media::FoldChannels(samples_f32, sizeof(samples_f32), + int32 samples_s32[6] = { 12, 1, 3, 7, 13, 17 }; + int32 expected_s32[2] = { static_cast(12 * .707 + 1), + static_cast(12 * .707 + 3) }; + bool result_s32 = media::FoldChannels(samples_s32, sizeof(samples_s32), 6, // channels. - sizeof(samples_f32[0]), + sizeof(samples_s32[0]), 1.00f); - EXPECT_EQ(true, result_f32); - int expected_test = memcmp(samples_f32, expected_f32, sizeof(expected_f32)); + EXPECT_EQ(true, result_s32); + int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); EXPECT_EQ(0, expected_test); } diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc index 073d0fc..59f4c1c 100644 --- a/media/audio/win/waveout_output_win.cc +++ b/media/audio/win/waveout_output_win.cc @@ -5,7 +5,6 @@ #include "media/audio/win/waveout_output_win.h" #include -#include #include #pragma comment(lib, "winmm.lib") @@ -56,8 +55,7 @@ PCMWaveOutAudioOutputStream::PCMWaveOutAudioOutputStream( volume_(1), channels_(channels), pending_bytes_(0) { - format_.wFormatTag = bits_per_sample == 32 ? - WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM; + format_.wFormatTag = WAVE_FORMAT_PCM; format_.nChannels = channels > 2 ? 2 : channels; format_.nSamplesPerSec = sampling_rate; format_.wBitsPerSample = bits_per_sample; -- cgit v1.1