Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: media/base/test_helpers.cc

Issue 265943002: Revert of Remove AudioBuffer::set_duration(), instead base on frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_algorithm_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/test_helpers.cc
diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc
index 929b2f3c725c70ee4fa26fc770ee0e9e827112d6..98d4971795a05291c96a31a7ae600fb681acfee6 100644
--- a/media/base/test_helpers.cc
+++ b/media/base/test_helpers.cc
@@ -151,25 +151,29 @@
template <class T>
scoped_refptr<AudioBuffer> MakeAudioBuffer(SampleFormat format,
ChannelLayout channel_layout,
- size_t channel_count,
+ int channel_count,
int sample_rate,
T start,
T increment,
- size_t frames,
- base::TimeDelta timestamp) {
- const size_t channels = ChannelLayoutToChannelCount(channel_layout);
- scoped_refptr<AudioBuffer> output =
- AudioBuffer::CreateBuffer(format,
- channel_layout,
- static_cast<int>(channel_count),
- sample_rate,
- static_cast<int>(frames));
+ int frames,
+ base::TimeDelta timestamp,
+ base::TimeDelta duration) {
+ int channels = ChannelLayoutToChannelCount(channel_layout);
+ scoped_refptr<AudioBuffer> output = AudioBuffer::CreateBuffer(
+ format, channel_layout, channel_count, sample_rate, frames);
output->set_timestamp(timestamp);
-
- const bool is_planar =
- format == kSampleFormatPlanarS16 || format == kSampleFormatPlanarF32;
-
- // Values in channel 0 will be:
+ output->set_duration(duration);
+
+ // Create a block of memory with values:
+ // start
+ // start + increment
+ // start + 2 * increment, ...
+ // For interleaved data, raw data will be:
+ // start
+ // start + channels * increment
+ // start + 2 * channels * increment, ...
+ //
+ // For planar data, values in channel 0 will be:
// start
// start + increment
// start + 2 * increment, ...
@@ -177,13 +181,13 @@
// start + frames * increment
// start + (frames + 1) * increment
// start + (frames + 2) * increment, ...
- for (size_t ch = 0; ch < channels; ++ch) {
- T* buffer =
- reinterpret_cast<T*>(output->channel_data()[is_planar ? ch : 0]);
- const T v = static_cast<T>(start + ch * frames * increment);
- for (size_t i = 0; i < frames; ++i) {
- buffer[is_planar ? i : ch + i * channels] =
- static_cast<T>(v + i * increment);
+ const size_t output_size =
+ output->channel_data().size() == 1 ? frames * channels : frames;
+ for (size_t ch = 0; ch < output->channel_data().size(); ++ch) {
+ T* buffer = reinterpret_cast<T*>(output->channel_data()[ch]);
+ const T v = static_cast<T>(start + ch * output_size * increment);
+ for (size_t i = 0; i < output_size; ++i) {
+ buffer[i] = static_cast<T>(v + i * increment);
}
}
return output;
@@ -195,12 +199,13 @@
template scoped_refptr<AudioBuffer> MakeAudioBuffer<type>( \
SampleFormat format, \
ChannelLayout channel_layout, \
- size_t channel_count, \
+ int channel_count, \
int sample_rate, \
type start, \
type increment, \
- size_t frames, \
- base::TimeDelta start_time)
+ int frames, \
+ base::TimeDelta start_time, \
+ base::TimeDelta duration)
DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(uint8);
DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int16);
DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int32);
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_algorithm_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698