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

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: Unittests! Bugs! 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 15 matching lines...) Expand all
26 26
27 // Command line switch for runtime adjustment of ConvolveBenchmark iterations. 27 // Command line switch for runtime adjustment of ConvolveBenchmark iterations.
28 static const char kConvolveIterations[] = "convolve-iterations"; 28 static const char kConvolveIterations[] = "convolve-iterations";
29 29
30 // Helper class to ensure ChunkedResample() functions properly. 30 // Helper class to ensure ChunkedResample() functions properly.
31 class MockSource { 31 class MockSource {
32 public: 32 public:
33 MOCK_METHOD2(ProvideInput, void(float* destination, int frames)); 33 MOCK_METHOD2(ProvideInput, void(float* destination, int frames));
34 }; 34 };
35 35
36 ACTION(ClearBuffer) {
37 memset(arg0, 0, arg1 * sizeof(float));
38 }
39
40 ACTION(FillBuffer) {
41 memset(arg0, 1, arg1 * sizeof(float));
42 }
43
36 // Test requesting multiples of ChunkSize() frames results in the proper number 44 // Test requesting multiples of ChunkSize() frames results in the proper number
37 // of callbacks. 45 // of callbacks.
38 TEST(SincResamplerTest, ChunkedResample) { 46 TEST(SincResamplerTest, ChunkedResample) {
39 MockSource mock_source; 47 MockSource mock_source;
40 48
41 // Choose a high ratio of input to output samples which will result in quick 49 // Choose a high ratio of input to output samples which will result in quick
42 // exhaustion of SincResampler's internal buffers. 50 // exhaustion of SincResampler's internal buffers.
43 SincResampler resampler( 51 SincResampler resampler(
44 kSampleRateRatio, 52 kSampleRateRatio,
45 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 53 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
46 54
47 static const int kChunks = 2; 55 static const int kChunks = 2;
48 int max_chunk_size = resampler.ChunkSize() * kChunks; 56 int max_chunk_size = resampler.ChunkSize() * kChunks;
49 scoped_array<float> resampled_destination(new float[max_chunk_size]); 57 scoped_array<float> resampled_destination(new float[max_chunk_size]);
50 58
51 // Verify requesting ChunkSize() frames causes a single callback. 59 // Verify requesting ChunkSize() frames causes a single callback.
52 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1); 60 EXPECT_CALL(mock_source, ProvideInput(_, _))
61 .Times(1).WillOnce(ClearBuffer());
53 resampler.Resample(resampled_destination.get(), resampler.ChunkSize()); 62 resampler.Resample(resampled_destination.get(), resampler.ChunkSize());
54 63
55 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. 64 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks.
56 testing::Mock::VerifyAndClear(&mock_source); 65 testing::Mock::VerifyAndClear(&mock_source);
57 EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(kChunks); 66 EXPECT_CALL(mock_source, ProvideInput(_, _))
67 .Times(kChunks).WillRepeatedly(ClearBuffer());
58 resampler.Resample(resampled_destination.get(), max_chunk_size); 68 resampler.Resample(resampled_destination.get(), max_chunk_size);
59 } 69 }
60 70
71 // Test flush resets the internal state properly.
72 TEST(SincResamplerTest, Flush) {
73 MockSource mock_source;
74 SincResampler resampler(
75 kSampleRateRatio,
76 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
77 scoped_array<float> resampled_destination(new float[resampler.ChunkSize()]);
78
79 // Fill the resampler with junk data.
80 EXPECT_CALL(mock_source, ProvideInput(_, _))
81 .Times(1).WillOnce(FillBuffer());
82 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2);
83 ASSERT_NE(resampled_destination[0], 0);
84
85 // Flush and request more data, which should all be zeros now.
86 resampler.Flush();
87 testing::Mock::VerifyAndClear(&mock_source);
88 EXPECT_CALL(mock_source, ProvideInput(_, _))
89 .Times(1).WillOnce(ClearBuffer());
90 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2);
91 for (int i = 0; i < resampler.ChunkSize() / 2; ++i)
92 ASSERT_EQ(resampled_destination[i], 0);
93 }
94
61 // Ensure various optimized Convolve() methods return the same value. Only run 95 // Ensure various optimized Convolve() methods return the same value. Only run
62 // this test if other optimized methods exist, otherwise the default Convolve() 96 // this test if other optimized methods exist, otherwise the default Convolve()
63 // will be tested by the parameterized SincResampler tests below. 97 // will be tested by the parameterized SincResampler tests below.
64 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) 98 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
65 TEST(SincResamplerTest, Convolve) { 99 TEST(SincResamplerTest, Convolve) {
66 // Initialize a dummy resampler. 100 // Initialize a dummy resampler.
67 MockSource mock_source; 101 MockSource mock_source;
68 SincResampler resampler( 102 SincResampler resampler(
69 kSampleRateRatio, 103 kSampleRateRatio,
70 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 104 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), 380 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61),
347 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), 381 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14),
348 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), 382 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42),
349 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), 383 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38),
350 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), 384 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63),
351 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), 385 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44),
352 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), 386 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52),
353 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); 387 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52)));
354 388
355 } // namespace media 389 } // namespace media
OLDNEW
« media/base/sinc_resampler.h ('K') | « media/base/sinc_resampler.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698