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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . Created 4 years, 8 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 #include <memory>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "media/base/sinc_resampler.h" 17 #include "media/base/sinc_resampler.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 27 matching lines...) Expand all
46 MockSource mock_source; 47 MockSource mock_source;
47 48
48 // 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
49 // exhaustion of SincResampler's internal buffers. 50 // exhaustion of SincResampler's internal buffers.
50 SincResampler resampler( 51 SincResampler resampler(
51 kSampleRateRatio, SincResampler::kDefaultRequestSize, 52 kSampleRateRatio, SincResampler::kDefaultRequestSize,
52 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 53 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
53 54
54 static const int kChunks = 2; 55 static const int kChunks = 2;
55 int max_chunk_size = resampler.ChunkSize() * kChunks; 56 int max_chunk_size = resampler.ChunkSize() * kChunks;
56 scoped_ptr<float[]> resampled_destination(new float[max_chunk_size]); 57 std::unique_ptr<float[]> resampled_destination(new float[max_chunk_size]);
57 58
58 // Verify requesting ChunkSize() frames causes a single callback. 59 // Verify requesting ChunkSize() frames causes a single callback.
59 EXPECT_CALL(mock_source, ProvideInput(_, _)) 60 EXPECT_CALL(mock_source, ProvideInput(_, _))
60 .Times(1).WillOnce(ClearBuffer()); 61 .Times(1).WillOnce(ClearBuffer());
61 resampler.Resample(resampler.ChunkSize(), resampled_destination.get()); 62 resampler.Resample(resampler.ChunkSize(), resampled_destination.get());
62 63
63 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. 64 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks.
64 testing::Mock::VerifyAndClear(&mock_source); 65 testing::Mock::VerifyAndClear(&mock_source);
65 EXPECT_CALL(mock_source, ProvideInput(_, _)) 66 EXPECT_CALL(mock_source, ProvideInput(_, _))
66 .Times(kChunks).WillRepeatedly(ClearBuffer()); 67 .Times(kChunks).WillRepeatedly(ClearBuffer());
(...skipping 22 matching lines...) Expand all
89 (2 * kSampleRateRatio)))); 90 (2 * kSampleRateRatio))));
90 91
91 // Verify Flush() resets to an unprimed state. 92 // Verify Flush() resets to an unprimed state.
92 resampler.Flush(); 93 resampler.Flush();
93 EXPECT_EQ(first_chunk_size, resampler.ChunkSize()); 94 EXPECT_EQ(first_chunk_size, resampler.ChunkSize());
94 resampler.PrimeWithSilence(); 95 resampler.PrimeWithSilence();
95 EXPECT_EQ(max_chunk_size, resampler.ChunkSize()); 96 EXPECT_EQ(max_chunk_size, resampler.ChunkSize());
96 97
97 const int kChunks = 2; 98 const int kChunks = 2;
98 const int kMaxFrames = max_chunk_size * kChunks; 99 const int kMaxFrames = max_chunk_size * kChunks;
99 scoped_ptr<float[]> resampled_destination(new float[kMaxFrames]); 100 std::unique_ptr<float[]> resampled_destination(new float[kMaxFrames]);
100 101
101 // Verify requesting ChunkSize() frames causes a single callback. 102 // Verify requesting ChunkSize() frames causes a single callback.
102 EXPECT_CALL(mock_source, ProvideInput(_, _)) 103 EXPECT_CALL(mock_source, ProvideInput(_, _))
103 .Times(1).WillOnce(ClearBuffer()); 104 .Times(1).WillOnce(ClearBuffer());
104 resampler.Resample(max_chunk_size, resampled_destination.get()); 105 resampler.Resample(max_chunk_size, resampled_destination.get());
105 EXPECT_EQ(max_chunk_size, resampler.ChunkSize()); 106 EXPECT_EQ(max_chunk_size, resampler.ChunkSize());
106 107
107 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. 108 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks.
108 testing::Mock::VerifyAndClear(&mock_source); 109 testing::Mock::VerifyAndClear(&mock_source);
109 EXPECT_CALL(mock_source, ProvideInput(_, _)) 110 EXPECT_CALL(mock_source, ProvideInput(_, _))
110 .Times(kChunks).WillRepeatedly(ClearBuffer()); 111 .Times(kChunks).WillRepeatedly(ClearBuffer());
111 resampler.Resample(kMaxFrames, resampled_destination.get()); 112 resampler.Resample(kMaxFrames, resampled_destination.get());
112 EXPECT_EQ(max_chunk_size, resampler.ChunkSize()); 113 EXPECT_EQ(max_chunk_size, resampler.ChunkSize());
113 } 114 }
114 115
115 // Test flush resets the internal state properly. 116 // Test flush resets the internal state properly.
116 TEST(SincResamplerTest, Flush) { 117 TEST(SincResamplerTest, Flush) {
117 MockSource mock_source; 118 MockSource mock_source;
118 SincResampler resampler( 119 SincResampler resampler(
119 kSampleRateRatio, SincResampler::kDefaultRequestSize, 120 kSampleRateRatio, SincResampler::kDefaultRequestSize,
120 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 121 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
121 scoped_ptr<float[]> resampled_destination(new float[resampler.ChunkSize()]); 122 std::unique_ptr<float[]> resampled_destination(
123 new float[resampler.ChunkSize()]);
122 124
123 // Fill the resampler with junk data. 125 // Fill the resampler with junk data.
124 EXPECT_CALL(mock_source, ProvideInput(_, _)) 126 EXPECT_CALL(mock_source, ProvideInput(_, _))
125 .Times(1).WillOnce(FillBuffer()); 127 .Times(1).WillOnce(FillBuffer());
126 resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get()); 128 resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get());
127 ASSERT_NE(resampled_destination[0], 0); 129 ASSERT_NE(resampled_destination[0], 0);
128 130
129 // Flush and request more data, which should all be zeros now. 131 // Flush and request more data, which should all be zeros now.
130 resampler.Flush(); 132 resampler.Flush();
131 testing::Mock::VerifyAndClear(&mock_source); 133 testing::Mock::VerifyAndClear(&mock_source);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 input_rate_, input_samples, input_nyquist_freq); 285 input_rate_, input_samples, input_nyquist_freq);
284 286
285 const double io_ratio = input_rate_ / static_cast<double>(output_rate_); 287 const double io_ratio = input_rate_ / static_cast<double>(output_rate_);
286 SincResampler resampler( 288 SincResampler resampler(
287 io_ratio, SincResampler::kDefaultRequestSize, 289 io_ratio, SincResampler::kDefaultRequestSize,
288 base::Bind(&SinusoidalLinearChirpSource::ProvideInput, 290 base::Bind(&SinusoidalLinearChirpSource::ProvideInput,
289 base::Unretained(&resampler_source))); 291 base::Unretained(&resampler_source)));
290 292
291 // Force an update to the sample rate ratio to ensure dyanmic sample rate 293 // Force an update to the sample rate ratio to ensure dyanmic sample rate
292 // changes are working correctly. 294 // changes are working correctly.
293 scoped_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]); 295 std::unique_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]);
294 memcpy(kernel.get(), resampler.get_kernel_for_testing(), 296 memcpy(kernel.get(), resampler.get_kernel_for_testing(),
295 SincResampler::kKernelStorageSize); 297 SincResampler::kKernelStorageSize);
296 resampler.SetRatio(M_PI); 298 resampler.SetRatio(M_PI);
297 ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), 299 ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(),
298 SincResampler::kKernelStorageSize)); 300 SincResampler::kKernelStorageSize));
299 resampler.SetRatio(io_ratio); 301 resampler.SetRatio(io_ratio);
300 ASSERT_EQ(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), 302 ASSERT_EQ(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(),
301 SincResampler::kKernelStorageSize)); 303 SincResampler::kKernelStorageSize));
302 304
303 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to 305 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to
304 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes. 306 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes.
305 scoped_ptr<float[]> resampled_destination(new float[output_samples]); 307 std::unique_ptr<float[]> resampled_destination(new float[output_samples]);
306 scoped_ptr<float[]> pure_destination(new float[output_samples]); 308 std::unique_ptr<float[]> pure_destination(new float[output_samples]);
307 309
308 // Generate resampled signal. 310 // Generate resampled signal.
309 resampler.Resample(output_samples, resampled_destination.get()); 311 resampler.Resample(output_samples, resampled_destination.get());
310 312
311 // Generate pure signal. 313 // Generate pure signal.
312 SinusoidalLinearChirpSource pure_source( 314 SinusoidalLinearChirpSource pure_source(
313 output_rate_, output_samples, input_nyquist_freq); 315 output_rate_, output_samples, input_nyquist_freq);
314 pure_source.ProvideInput(output_samples, pure_destination.get()); 316 pure_source.ProvideInput(output_samples, pure_destination.get());
315 317
316 // Range of the Nyquist frequency (0.5 * min(input rate, output_rate)) which 318 // Range of the Nyquist frequency (0.5 * min(input rate, output_rate)) which
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), 403 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61),
402 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), 404 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14),
403 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), 405 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42),
404 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), 406 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38),
405 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), 407 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63),
406 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), 408 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44),
407 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), 409 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52),
408 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); 410 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52)));
409 411
410 } // namespace media 412 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698