diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 02:17:28 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 02:17:28 +0000 |
commit | 4062d0f4e7e83c14e0503a264f2a1616d9968c5b (patch) | |
tree | 44a725905eeb65adf8a0cd5c942a9949137c9c18 /media/audio | |
parent | cb54251f28bcf5eb249e19af85d01480f2dde1cf (diff) | |
download | chromium_src-4062d0f4e7e83c14e0503a264f2a1616d9968c5b.zip chromium_src-4062d0f4e7e83c14e0503a264f2a1616d9968c5b.tar.gz chromium_src-4062d0f4e7e83c14e0503a264f2a1616d9968c5b.tar.bz2 |
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
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/audio_util.cc | 57 | ||||
-rw-r--r-- | media/audio/audio_util_unittest.cc | 33 | ||||
-rw-r--r-- | media/audio/win/waveout_output_win.cc | 4 |
3 files changed, 29 insertions, 65 deletions
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<class Format, class Fixed, int bias> -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<Format>(ScaleChannel<Fixed>(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<class Fixed, int min_value, int max_value> -static int AddChannel(int val, int adder) { +static int AddChannel(int val, + int adder) { Fixed sum = static_cast<Fixed>(val) + static_cast<Fixed>(adder); if (sum > max_value) return max_value; @@ -66,9 +62,9 @@ static int AddChannel(int val, int adder) { template<class Format, class Fixed, int min_value, int max_value, int bias> 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<int>(volume * 0.707f * 65536); const int fixed_volume = static_cast<int>(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<float*>(buf), - sample_count, - volume); + AdjustVolume<int32, int64, 0>(reinterpret_cast<int32*>(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<float*>(buf), + FoldChannels<int32, int64, 0x80000000, 0x7fffffff, 0>( + reinterpret_cast<int32*>(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<int16>(12 * .707 + 1), + static_cast<int16>(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 <windows.h> -#include <mmreg.h> #include <mmsystem.h> #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; |