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

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

Issue 10918098: Introduce AudioOutputResampler for browser side resampling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: First draft! Created 8 years, 3 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 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Verify requesting ChunkSize() frames causes a single callback. 51 // Verify requesting ChunkSize() frames causes a single callback.
52 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1); 52 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1);
53 resampler.Resample(resampled_destination.get(), resampler.ChunkSize()); 53 resampler.Resample(resampled_destination.get(), resampler.ChunkSize());
54 54
55 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. 55 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks.
56 testing::Mock::VerifyAndClear(&mock_source); 56 testing::Mock::VerifyAndClear(&mock_source);
57 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(kChunks); 57 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(kChunks);
58 resampler.Resample(resampled_destination.get(), max_chunk_size); 58 resampler.Resample(resampled_destination.get(), max_chunk_size);
59 } 59 }
60 60
61 // Test flush resets the internal state properly.
62 TEST(SincResamplerTest, Flush) {
63 MockSource mock_source;
64 SincResampler resampler(
65 kSampleRateRatio,
66 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
67 scoped_array<float> resampled_destination(new float[resampler.ChunkSize()]);
68
69 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1);
70 resampler.Resample(resampled_destination.get(), resampler.ChunkSize());
71
72 // Figure out buffer size from internal buffer layout.
73 int buffer_size_float = reinterpret_cast<int>(
74 resampler.r4_ + (resampler.r4_ - resampler.r3_) - resampler.r1_);
scherkus (not reviewing) 2012/09/07 13:30:17 instead of friend test + poking around internals,
DaleCurtis 2012/09/07 14:17:35 I like this idea. Will change.
DaleCurtis 2012/09/10 12:06:24 Found a better way => Prime with junk data, Flush(
75 int buffer_size_bytes = buffer_size_float * sizeof(*(
scherkus (not reviewing) 2012/09/07 13:30:17 looks bizarre -- drop sizeof to next line?
DaleCurtis 2012/09/10 12:06:24 Removed.
76 resampler.input_buffer_.get()));
77
78 // Fill input buffer with junk data so we can if it's cleared afterwards.
79 memset(resampler.input_buffer_.get(), 0xFF, buffer_size_bytes);
80
81 EXPECT_TRUE(resampler.buffer_primed_);
82 EXPECT_NE(resampler.virtual_source_idx_, 0);
83
84 resampler.Flush();
85 EXPECT_FALSE(resampler.buffer_primed_);
86 EXPECT_EQ(resampler.virtual_source_idx_, 0);
87 for (int i = 0; i < buffer_size_float; ++i)
88 ASSERT_FLOAT_EQ(resampler.input_buffer_.get()[i], 0);
89 }
90
61 // Ensure various optimized Convolve() methods return the same value. Only run 91 // Ensure various optimized Convolve() methods return the same value. Only run
62 // this test if other optimized methods exist, otherwise the default Convolve() 92 // this test if other optimized methods exist, otherwise the default Convolve()
63 // will be tested by the parameterized SincResampler tests below. 93 // will be tested by the parameterized SincResampler tests below.
64 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) 94 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
65 TEST(SincResamplerTest, Convolve) { 95 TEST(SincResamplerTest, Convolve) {
66 // Initialize a dummy resampler. 96 // Initialize a dummy resampler.
67 MockSource mock_source; 97 MockSource mock_source;
68 SincResampler resampler( 98 SincResampler resampler(
69 kSampleRateRatio, 99 kSampleRateRatio,
70 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 100 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), 376 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61),
347 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), 377 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14),
348 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), 378 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42),
349 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), 379 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38),
350 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), 380 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63),
351 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), 381 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44),
352 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), 382 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52),
353 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); 383 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52)));
354 384
355 } // namespace media 385 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698