OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "media/audio/audio_parameters.h" | 8 #include "media/audio/audio_parameters.h" |
9 #include "media/base/audio_bus.h" | 9 #include "media/base/audio_bus.h" |
10 #include "media/base/channel_layout.h" | 10 #include "media/base/channel_layout.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 // Verify Zero() and ZeroFrames(...) utility methods work as advertised. | 201 // Verify Zero() and ZeroFrames(...) utility methods work as advertised. |
202 TEST_F(AudioBusTest, Zero) { | 202 TEST_F(AudioBusTest, Zero) { |
203 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount); | 203 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount); |
204 | 204 |
205 // Fill the bus with dummy data. | 205 // Fill the bus with dummy data. |
206 for (int i = 0; i < bus->channels(); ++i) | 206 for (int i = 0; i < bus->channels(); ++i) |
207 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); | 207 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); |
| 208 EXPECT_FALSE(bus->AreFramesZero()); |
208 | 209 |
209 // Zero first half the frames of each channel. | 210 // Zero first half the frames of each channel. |
210 bus->ZeroFrames(kFrameCount / 2); | 211 bus->ZeroFrames(kFrameCount / 2); |
211 for (int i = 0; i < bus->channels(); ++i) { | 212 for (int i = 0; i < bus->channels(); ++i) { |
212 SCOPED_TRACE("First Half Zero"); | 213 SCOPED_TRACE("First Half Zero"); |
213 VerifyValue(bus->channel(i), kFrameCount / 2, 0); | 214 VerifyValue(bus->channel(i), kFrameCount / 2, 0); |
214 VerifyValue(bus->channel(i) + kFrameCount / 2, | 215 VerifyValue(bus->channel(i) + kFrameCount / 2, |
215 kFrameCount - kFrameCount / 2, i + 1); | 216 kFrameCount - kFrameCount / 2, i + 1); |
216 } | 217 } |
| 218 EXPECT_FALSE(bus->AreFramesZero()); |
217 | 219 |
218 // Fill the bus with dummy data. | 220 // Fill the bus with dummy data. |
219 for (int i = 0; i < bus->channels(); ++i) | 221 for (int i = 0; i < bus->channels(); ++i) |
220 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); | 222 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); |
221 | 223 |
222 // Zero the last half of the frames. | 224 // Zero the last half of the frames. |
223 bus->ZeroFramesPartial(kFrameCount / 2, kFrameCount - kFrameCount / 2); | 225 bus->ZeroFramesPartial(kFrameCount / 2, kFrameCount - kFrameCount / 2); |
224 for (int i = 0; i < bus->channels(); ++i) { | 226 for (int i = 0; i < bus->channels(); ++i) { |
225 SCOPED_TRACE("Last Half Zero"); | 227 SCOPED_TRACE("Last Half Zero"); |
226 VerifyValue(bus->channel(i) + kFrameCount / 2, | 228 VerifyValue(bus->channel(i) + kFrameCount / 2, |
227 kFrameCount - kFrameCount / 2, 0); | 229 kFrameCount - kFrameCount / 2, 0); |
228 VerifyValue(bus->channel(i), kFrameCount / 2, i + 1); | 230 VerifyValue(bus->channel(i), kFrameCount / 2, i + 1); |
229 } | 231 } |
| 232 EXPECT_FALSE(bus->AreFramesZero()); |
230 | 233 |
231 // Fill the bus with dummy data. | 234 // Fill the bus with dummy data. |
232 for (int i = 0; i < bus->channels(); ++i) | 235 for (int i = 0; i < bus->channels(); ++i) |
233 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); | 236 std::fill(bus->channel(i), bus->channel(i) + bus->frames(), i + 1); |
234 | 237 |
235 // Zero all the frames of each channel. | 238 // Zero all the frames of each channel. |
236 bus->Zero(); | 239 bus->Zero(); |
237 for (int i = 0; i < bus->channels(); ++i) { | 240 for (int i = 0; i < bus->channels(); ++i) { |
238 SCOPED_TRACE("All Zero"); | 241 SCOPED_TRACE("All Zero"); |
239 VerifyValue(bus->channel(i), bus->frames(), 0); | 242 VerifyValue(bus->channel(i), bus->frames(), 0); |
240 } | 243 } |
| 244 EXPECT_TRUE(bus->AreFramesZero()); |
241 } | 245 } |
242 | 246 |
243 // Each test vector represents two channels of data in the following arbitrary | 247 // Each test vector represents two channels of data in the following arbitrary |
244 // layout: <min, zero, max, min, max / 2, min / 2, zero, max, zero, zero>. | 248 // layout: <min, zero, max, min, max / 2, min / 2, zero, max, zero, zero>. |
245 static const int kTestVectorSize = 10; | 249 static const int kTestVectorSize = 10; |
246 static const uint8 kTestVectorUint8[kTestVectorSize] = { | 250 static const uint8 kTestVectorUint8[kTestVectorSize] = { |
247 0, -kint8min, kuint8max, 0, kint8max / 2 + 128, kint8min / 2 + 128, | 251 0, -kint8min, kuint8max, 0, kint8max / 2 + 128, kint8min / 2 + 128, |
248 -kint8min, kuint8max, -kint8min, -kint8min }; | 252 -kint8min, kuint8max, -kint8min, -kint8min }; |
249 static const int16 kTestVectorInt16[kTestVectorSize] = { | 253 static const int16 kTestVectorInt16[kTestVectorSize] = { |
250 kint16min, 0, kint16max, kint16min, kint16max / 2, kint16min / 2, | 254 kint16min, 0, kint16max, kint16min, kint16max / 2, kint16min / 2, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 411 |
408 // Verify zero volume case. | 412 // Verify zero volume case. |
409 bus->Scale(0); | 413 bus->Scale(0); |
410 for (int i = 0; i < bus->channels(); ++i) { | 414 for (int i = 0; i < bus->channels(); ++i) { |
411 SCOPED_TRACE("Zero Scale"); | 415 SCOPED_TRACE("Zero Scale"); |
412 VerifyValue(bus->channel(i), bus->frames(), 0); | 416 VerifyValue(bus->channel(i), bus->frames(), 0); |
413 } | 417 } |
414 } | 418 } |
415 | 419 |
416 } // namespace media | 420 } // namespace media |
OLD | NEW |