diff options
author | Ben Murdoch <benm@google.com> | 2013-07-10 11:40:50 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2013-07-10 11:40:50 +0100 |
commit | eb525c5499e34cc9c4b825d6d9e75bb07cc06ace (patch) | |
tree | d908ce4bfe1717d2cd53f41327d8b9ba8304355f /media/base/audio_buffer_unittest.cc | |
parent | 3c54152607de4272b3da0c146b71dcba8a0e5610 (diff) | |
download | chromium_org-eb525c5499e34cc9c4b825d6d9e75bb07cc06ace.tar.gz |
Merge from Chromium at DEPS revision r210036
This commit was generated by merge_to_master.py.
Change-Id: Ib0e33a83ad5dfa541481e83d7acfc6970e68f471
Diffstat (limited to 'media/base/audio_buffer_unittest.cc')
-rw-r--r-- | media/base/audio_buffer_unittest.cc | 86 |
1 files changed, 9 insertions, 77 deletions
diff --git a/media/base/audio_buffer_unittest.cc b/media/base/audio_buffer_unittest.cc index f4f9ebf9db..1c0135490f 100644 --- a/media/base/audio_buffer_unittest.cc +++ b/media/base/audio_buffer_unittest.cc @@ -2,83 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/string_util.h" +#include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "media/base/audio_buffer.h" #include "media/base/audio_bus.h" +#include "media/base/test_helpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace media { -template <class T> -static scoped_refptr<AudioBuffer> MakeInterleavedBuffer( - SampleFormat format, - int channels, - T start, - T increment, - int frames, - const base::TimeDelta start_time) { - DCHECK(format == kSampleFormatU8 || format == kSampleFormatS16 || - format == kSampleFormatS32 || format == kSampleFormatF32); - - // Create a block of memory with values: - // start - // start + increment - // start + 2 * increment, ... - // Since this is interleaved data, channel 0 data will be: - // start - // start + channels * increment - // start + 2 * channels * increment, ... - int buffer_size = frames * channels * sizeof(T); - uint8* memory = new uint8[buffer_size]; - uint8* data[] = { memory }; - T* buffer = reinterpret_cast<T*>(memory); - for (int i = 0; i < frames * channels; ++i) { - buffer[i] = start; - start += increment; - } - // Duration is 1 second per frame (for simplicity). - base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); - return AudioBuffer::CopyFrom( - format, channels, frames, data, start_time, duration); -} - -template <class T> -static scoped_refptr<AudioBuffer> MakePlanarBuffer( - SampleFormat format, - int channels, - T start, - T increment, - int frames, - const base::TimeDelta start_time) { - DCHECK(format == kSampleFormatPlanarF32 || format == kSampleFormatPlanarS16); - - // Create multiple blocks of data, once for each channel. - // Values in channel 0 will be: - // start - // start + increment - // start + 2 * increment, ... - // Values in channel 1 will be: - // start + frames * increment - // start + (frames + 1) * increment - // start + (frames + 2) * increment, ... - uint8** data = new uint8*[channels]; - int buffer_size = frames * sizeof(T); - for (int i = 0; i < channels; ++i) { - uint8* memory = new uint8[buffer_size]; - data[i] = memory; - T* buffer = reinterpret_cast<T*>(memory); - for (int j = 0; j < frames; ++j) { - buffer[j] = start; - start += increment; - } - } - // Duration is 1 second per frame (for simplicity). - base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); - return AudioBuffer::CopyFrom( - format, channels, frames, data, start_time, duration); -} - static void VerifyResult(float* channel_data, int frames, float start, @@ -95,7 +27,7 @@ TEST(AudioBufferTest, CopyFrom) { const int channels = 1; const int frames = 8; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakeInterleavedBuffer<uint8>( + scoped_refptr<AudioBuffer> buffer = MakeInterleavedAudioBuffer<uint8>( kSampleFormatU8, channels, 1, 1, frames, start_time); EXPECT_EQ(frames, buffer->frame_count()); EXPECT_EQ(buffer->timestamp(), start_time); @@ -129,7 +61,7 @@ TEST(AudioBufferTest, ReadU8) { const int channels = 4; const int frames = 4; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakeInterleavedBuffer<uint8>( + scoped_refptr<AudioBuffer> buffer = MakeInterleavedAudioBuffer<uint8>( kSampleFormatU8, channels, 128, 1, frames, start_time); // Read all 4 frames from the buffer. Data is interleaved, so ch[0] should be @@ -148,7 +80,7 @@ TEST(AudioBufferTest, ReadS16) { const int channels = 2; const int frames = 10; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakeInterleavedBuffer<int16>( + scoped_refptr<AudioBuffer> buffer = MakeInterleavedAudioBuffer<int16>( kSampleFormatS16, channels, 1, 1, frames, start_time); // Read 6 frames from the buffer. Data is interleaved, so ch[0] should be 1, @@ -172,7 +104,7 @@ TEST(AudioBufferTest, ReadS32) { const int channels = 2; const int frames = 6; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakeInterleavedBuffer<int32>( + scoped_refptr<AudioBuffer> buffer = MakeInterleavedAudioBuffer<int32>( kSampleFormatS32, channels, 1, 1, frames, start_time); // Read 6 frames from the buffer. Data is interleaved, so ch[0] should be 1, @@ -194,7 +126,7 @@ TEST(AudioBufferTest, ReadF32) { const int channels = 2; const int frames = 20; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakeInterleavedBuffer<float>( + scoped_refptr<AudioBuffer> buffer = MakeInterleavedAudioBuffer<float>( kSampleFormatF32, channels, 1.0f, 1.0f, frames, start_time); // Read first 10 frames from the buffer. F32 is interleaved, so ch[0] should @@ -215,7 +147,7 @@ TEST(AudioBufferTest, ReadS16Planar) { const int channels = 2; const int frames = 20; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakePlanarBuffer<int16>( + scoped_refptr<AudioBuffer> buffer = MakePlanarAudioBuffer<int16>( kSampleFormatPlanarS16, channels, 1, 1, frames, start_time); // Read 6 frames from the buffer. Data is planar, so ch[0] should be 1, 2, 3, @@ -247,7 +179,7 @@ TEST(AudioBufferTest, ReadF32Planar) { const int channels = 4; const int frames = 100; const base::TimeDelta start_time; - scoped_refptr<AudioBuffer> buffer = MakePlanarBuffer<float>( + scoped_refptr<AudioBuffer> buffer = MakePlanarAudioBuffer<float>( kSampleFormatPlanarF32, channels, 1.0f, 1.0f, frames, start_time); // Read all 100 frames from the buffer. F32 is planar, so ch[0] should be 1, |