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

Side by Side Diff: media/base/audio_bus_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 unified diff | Download patch
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 TEST_F(AudioBusTest, FromInterleaved) { 273 TEST_F(AudioBusTest, FromInterleaved) {
274 scoped_ptr<AudioBus> bus = AudioBus::Create( 274 scoped_ptr<AudioBus> bus = AudioBus::Create(
275 kTestVectorChannels, kTestVectorFrames); 275 kTestVectorChannels, kTestVectorFrames);
276 scoped_ptr<AudioBus> expected = AudioBus::Create( 276 scoped_ptr<AudioBus> expected = AudioBus::Create(
277 kTestVectorChannels, kTestVectorFrames); 277 kTestVectorChannels, kTestVectorFrames);
278 for (int ch = 0; ch < kTestVectorChannels; ++ch) { 278 for (int ch = 0; ch < kTestVectorChannels; ++ch) {
279 memcpy(expected->channel(ch), kTestVectorResult[ch], 279 memcpy(expected->channel(ch), kTestVectorResult[ch],
280 kTestVectorFrames * sizeof(*expected->channel(ch))); 280 kTestVectorFrames * sizeof(*expected->channel(ch)));
281 } 281 }
282 { 282 {
283 SCOPED_TRACE("uint8"); 283 SCOPED_TRACE("uint8_t");
284 bus->Zero(); 284 bus->Zero();
285 bus->FromInterleaved( 285 bus->FromInterleaved(
286 kTestVectorUint8, kTestVectorFrames, sizeof(*kTestVectorUint8)); 286 kTestVectorUint8, kTestVectorFrames, sizeof(*kTestVectorUint8));
287 // Biased uint8_t calculations have poor precision, so the epsilon here is 287 // Biased uint8_t calculations have poor precision, so the epsilon here is
288 // slightly more permissive than int16_t and int32_t calculations. 288 // slightly more permissive than int16_t and int32_t calculations.
289 VerifyBusWithEpsilon(bus.get(), expected.get(), 289 VerifyBusWithEpsilon(bus.get(), expected.get(),
290 1.0f / (std::numeric_limits<uint8_t>::max() - 1)); 290 1.0f / (std::numeric_limits<uint8_t>::max() - 1));
291 } 291 }
292 { 292 {
293 SCOPED_TRACE("int16"); 293 SCOPED_TRACE("int16_t");
294 bus->Zero(); 294 bus->Zero();
295 bus->FromInterleaved( 295 bus->FromInterleaved(
296 kTestVectorInt16, kTestVectorFrames, sizeof(*kTestVectorInt16)); 296 kTestVectorInt16, kTestVectorFrames, sizeof(*kTestVectorInt16));
297 VerifyBusWithEpsilon(bus.get(), expected.get(), 297 VerifyBusWithEpsilon(bus.get(), expected.get(),
298 1.0f / (std::numeric_limits<uint16_t>::max() + 1.0f)); 298 1.0f / (std::numeric_limits<uint16_t>::max() + 1.0f));
299 } 299 }
300 { 300 {
301 SCOPED_TRACE("int32"); 301 SCOPED_TRACE("int32_t");
302 bus->Zero(); 302 bus->Zero();
303 bus->FromInterleaved( 303 bus->FromInterleaved(
304 kTestVectorInt32, kTestVectorFrames, sizeof(*kTestVectorInt32)); 304 kTestVectorInt32, kTestVectorFrames, sizeof(*kTestVectorInt32));
305 VerifyBusWithEpsilon(bus.get(), expected.get(), 305 VerifyBusWithEpsilon(bus.get(), expected.get(),
306 1.0f / (std::numeric_limits<uint32_t>::max() + 1.0f)); 306 1.0f / (std::numeric_limits<uint32_t>::max() + 1.0f));
307 } 307 }
308 } 308 }
309 309
310 // Verify FromInterleavedPartial() deinterleaves audio correctly. 310 // Verify FromInterleavedPartial() deinterleaves audio correctly.
311 TEST_F(AudioBusTest, FromInterleavedPartial) { 311 TEST_F(AudioBusTest, FromInterleavedPartial) {
(...skipping 23 matching lines...) Expand all
335 // Verify ToInterleaved() interleaves audio in suported formats correctly. 335 // Verify ToInterleaved() interleaves audio in suported formats correctly.
336 TEST_F(AudioBusTest, ToInterleaved) { 336 TEST_F(AudioBusTest, ToInterleaved) {
337 scoped_ptr<AudioBus> bus = AudioBus::Create( 337 scoped_ptr<AudioBus> bus = AudioBus::Create(
338 kTestVectorChannels, kTestVectorFrames); 338 kTestVectorChannels, kTestVectorFrames);
339 // Fill the bus with our test vector. 339 // Fill the bus with our test vector.
340 for (int ch = 0; ch < bus->channels(); ++ch) { 340 for (int ch = 0; ch < bus->channels(); ++ch) {
341 memcpy(bus->channel(ch), kTestVectorResult[ch], 341 memcpy(bus->channel(ch), kTestVectorResult[ch],
342 kTestVectorFrames * sizeof(*bus->channel(ch))); 342 kTestVectorFrames * sizeof(*bus->channel(ch)));
343 } 343 }
344 { 344 {
345 SCOPED_TRACE("uint8"); 345 SCOPED_TRACE("uint8_t");
346 uint8_t test_array[arraysize(kTestVectorUint8)]; 346 uint8_t test_array[arraysize(kTestVectorUint8)];
347 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorUint8), test_array); 347 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorUint8), test_array);
348 ASSERT_EQ(memcmp( 348 ASSERT_EQ(memcmp(
349 test_array, kTestVectorUint8, sizeof(kTestVectorUint8)), 0); 349 test_array, kTestVectorUint8, sizeof(kTestVectorUint8)), 0);
350 } 350 }
351 { 351 {
352 SCOPED_TRACE("int16"); 352 SCOPED_TRACE("int16_t");
353 int16_t test_array[arraysize(kTestVectorInt16)]; 353 int16_t test_array[arraysize(kTestVectorInt16)];
354 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt16), test_array); 354 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt16), test_array);
355 ASSERT_EQ(memcmp( 355 ASSERT_EQ(memcmp(
356 test_array, kTestVectorInt16, sizeof(kTestVectorInt16)), 0); 356 test_array, kTestVectorInt16, sizeof(kTestVectorInt16)), 0);
357 } 357 }
358 { 358 {
359 SCOPED_TRACE("int32"); 359 SCOPED_TRACE("int32_t");
360 int32_t test_array[arraysize(kTestVectorInt32)]; 360 int32_t test_array[arraysize(kTestVectorInt32)];
361 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt32), test_array); 361 bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt32), test_array);
362 362
363 // Some compilers get better precision than others on the half-max test, so 363 // Some compilers get better precision than others on the half-max test, so
364 // let the test pass with an off by one check on the half-max. 364 // let the test pass with an off by one check on the half-max.
365 int32_t fixed_test_array[arraysize(kTestVectorInt32)]; 365 int32_t fixed_test_array[arraysize(kTestVectorInt32)];
366 memcpy(fixed_test_array, kTestVectorInt32, sizeof(kTestVectorInt32)); 366 memcpy(fixed_test_array, kTestVectorInt32, sizeof(kTestVectorInt32));
367 ASSERT_EQ(fixed_test_array[4], std::numeric_limits<int32_t>::max() / 2); 367 ASSERT_EQ(fixed_test_array[4], std::numeric_limits<int32_t>::max() / 2);
368 fixed_test_array[4]++; 368 fixed_test_array[4]++;
369 369
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 // Verify zero volume case. 421 // Verify zero volume case.
422 bus->Scale(0); 422 bus->Scale(0);
423 for (int i = 0; i < bus->channels(); ++i) { 423 for (int i = 0; i < bus->channels(); ++i) {
424 SCOPED_TRACE("Zero Scale"); 424 SCOPED_TRACE("Zero Scale");
425 VerifyValue(bus->channel(i), bus->frames(), 0); 425 VerifyValue(bus->channel(i), bus->frames(), 0);
426 } 426 }
427 } 427 }
428 428
429 } // namespace media 429 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698