OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "media/base/audio_buffer.h" | 7 #include "media/base/audio_buffer.h" |
8 #include "media/base/audio_bus.h" | 8 #include "media/base/audio_bus.h" |
9 #include "media/base/test_helpers.h" | 9 #include "media/base/test_helpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 const static int kSampleRate = 44100; | 14 const static int kSampleRate = 44100; |
15 | 15 |
16 static void VerifyResult(float* channel_data, | 16 static void VerifyResult(float* channel_data, |
wolenetz
2014/04/28 23:02:02
At first glance, this seems to be incorrectly (re)
DaleCurtis
2014/04/28 23:11:58
It's always been there? https://code.google.com/p/
| |
17 int frames, | 17 int frames, |
18 float start, | 18 float start, |
19 float increment) { | 19 float increment) { |
20 for (int i = 0; i < frames; ++i) { | 20 for (int i = 0; i < frames; ++i) { |
21 SCOPED_TRACE(base::StringPrintf( | 21 SCOPED_TRACE(base::StringPrintf( |
22 "i=%d/%d start=%f, increment=%f", i, frames, start, increment)); | 22 "i=%d/%d start=%f, increment=%f", i, frames, start, increment)); |
23 ASSERT_EQ(channel_data[i], start); | 23 ASSERT_EQ(channel_data[i], start); |
24 start += increment; | 24 start += increment; |
25 } | 25 } |
26 } | 26 } |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 buffer->ReadFrames(10, 0, 0, bus.get()); | 351 buffer->ReadFrames(10, 0, 0, bus.get()); |
352 VerifyResult(bus->channel(0), 10, 61.0f, 1.0f); | 352 VerifyResult(bus->channel(0), 10, 61.0f, 1.0f); |
353 | 353 |
354 // Trim off the last 30 frames. | 354 // Trim off the last 30 frames. |
355 buffer->TrimEnd(30); | 355 buffer->TrimEnd(30); |
356 EXPECT_EQ(buffer->frame_count(), 0); | 356 EXPECT_EQ(buffer->frame_count(), 0); |
357 EXPECT_EQ(buffer->timestamp(), start_time + base::TimeDelta::FromSeconds(60)); | 357 EXPECT_EQ(buffer->timestamp(), start_time + base::TimeDelta::FromSeconds(60)); |
358 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(0)); | 358 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(0)); |
359 } | 359 } |
360 | 360 |
361 TEST(AudioBufferTest, TrimRange) { | |
362 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; | |
363 const int channels = ChannelLayoutToChannelCount(channel_layout); | |
364 const int frames = 100; | |
365 const base::TimeDelta start_time; | |
366 const base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); | |
367 const float step = 1.0f; | |
368 scoped_refptr<AudioBuffer> buffer = | |
369 MakeAudioBuffer<float>(kSampleFormatPlanarF32, | |
370 channel_layout, | |
371 channels, | |
372 kSampleRate, | |
373 0, | |
374 step, | |
375 frames, | |
376 start_time, | |
377 duration); | |
378 EXPECT_EQ(frames, buffer->frame_count()); | |
379 EXPECT_EQ(start_time, buffer->timestamp()); | |
380 EXPECT_EQ(frames, buffer->duration().InSeconds()); | |
381 | |
382 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); | |
383 | |
384 const int trim_start = 25; | |
385 const int trim_length = 50; | |
386 | |
387 // Verify the first 25 frames before trimming. | |
388 buffer->ReadFrames(trim_start, 0, 0, bus.get()); | |
389 VerifyResult(bus->channel(0), trim_start, 0, step); | |
390 | |
391 // Trim frames from the middle of the buffer. | |
392 buffer->TrimRange(trim_start, trim_start + trim_length); | |
393 EXPECT_EQ(buffer->frame_count(), frames - trim_length); | |
394 EXPECT_EQ(buffer->timestamp(), start_time); | |
395 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(50)); | |
396 | |
397 // Verify the first 25 frames. | |
398 buffer->ReadFrames(trim_start, 0, 0, bus.get()); | |
399 VerifyResult(bus->channel(0), trim_start, 0, step); | |
400 | |
401 // Verify the next 25 frames. | |
402 buffer->ReadFrames(trim_start, trim_start, 0, bus.get()); | |
403 VerifyResult(bus->channel(0), trim_start, trim_start + trim_length, step); | |
404 } | |
405 | |
361 } // namespace media | 406 } // namespace media |
OLD | NEW |