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

Side by Side Diff: webrtc/common_audio/resampler/sinc_resampler_unittest.cc

Issue 1712513002: Replace scoped_ptr with unique_ptr in webrtc/common_audio/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 10 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 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 // Modified from the Chromium original: 11 // Modified from the Chromium original:
12 // src/media/base/sinc_resampler_unittest.cc 12 // src/media/base/sinc_resampler_unittest.cc
13 13
14 // MSVC++ requires this to be set before any other includes to get M_PI. 14 // MSVC++ requires this to be set before any other includes to get M_PI.
15 #define _USE_MATH_DEFINES 15 #define _USE_MATH_DEFINES
16 16
17 #include <math.h> 17 #include <math.h>
18 18
19 #include <memory>
20
19 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webrtc/base/scoped_ptr.h"
22 #include "webrtc/common_audio/resampler/sinc_resampler.h" 23 #include "webrtc/common_audio/resampler/sinc_resampler.h"
23 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" 24 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h"
24 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" 25 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
25 #include "webrtc/system_wrappers/include/stringize_macros.h" 26 #include "webrtc/system_wrappers/include/stringize_macros.h"
26 #include "webrtc/system_wrappers/include/tick_util.h" 27 #include "webrtc/system_wrappers/include/tick_util.h"
27 #include "webrtc/test/test_suite.h" 28 #include "webrtc/test/test_suite.h"
28 29
29 using testing::_; 30 using testing::_;
30 31
31 namespace webrtc { 32 namespace webrtc {
(...skipping 23 matching lines...) Expand all
55 TEST(SincResamplerTest, ChunkedResample) { 56 TEST(SincResamplerTest, ChunkedResample) {
56 MockSource mock_source; 57 MockSource mock_source;
57 58
58 // Choose a high ratio of input to output samples which will result in quick 59 // Choose a high ratio of input to output samples which will result in quick
59 // exhaustion of SincResampler's internal buffers. 60 // exhaustion of SincResampler's internal buffers.
60 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, 61 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize,
61 &mock_source); 62 &mock_source);
62 63
63 static const int kChunks = 2; 64 static const int kChunks = 2;
64 size_t max_chunk_size = resampler.ChunkSize() * kChunks; 65 size_t max_chunk_size = resampler.ChunkSize() * kChunks;
65 rtc::scoped_ptr<float[]> resampled_destination(new float[max_chunk_size]); 66 std::unique_ptr<float[]> resampled_destination(new float[max_chunk_size]);
66 67
67 // Verify requesting ChunkSize() frames causes a single callback. 68 // Verify requesting ChunkSize() frames causes a single callback.
68 EXPECT_CALL(mock_source, Run(_, _)) 69 EXPECT_CALL(mock_source, Run(_, _))
69 .Times(1).WillOnce(ClearBuffer()); 70 .Times(1).WillOnce(ClearBuffer());
70 resampler.Resample(resampler.ChunkSize(), resampled_destination.get()); 71 resampler.Resample(resampler.ChunkSize(), resampled_destination.get());
71 72
72 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. 73 // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks.
73 testing::Mock::VerifyAndClear(&mock_source); 74 testing::Mock::VerifyAndClear(&mock_source);
74 EXPECT_CALL(mock_source, Run(_, _)) 75 EXPECT_CALL(mock_source, Run(_, _))
75 .Times(kChunks).WillRepeatedly(ClearBuffer()); 76 .Times(kChunks).WillRepeatedly(ClearBuffer());
76 resampler.Resample(max_chunk_size, resampled_destination.get()); 77 resampler.Resample(max_chunk_size, resampled_destination.get());
77 } 78 }
78 79
79 // Test flush resets the internal state properly. 80 // Test flush resets the internal state properly.
80 TEST(SincResamplerTest, Flush) { 81 TEST(SincResamplerTest, Flush) {
81 MockSource mock_source; 82 MockSource mock_source;
82 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, 83 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize,
83 &mock_source); 84 &mock_source);
84 rtc::scoped_ptr<float[]> resampled_destination( 85 std::unique_ptr<float[]> resampled_destination(
85 new float[resampler.ChunkSize()]); 86 new float[resampler.ChunkSize()]);
86 87
87 // Fill the resampler with junk data. 88 // Fill the resampler with junk data.
88 EXPECT_CALL(mock_source, Run(_, _)) 89 EXPECT_CALL(mock_source, Run(_, _))
89 .Times(1).WillOnce(FillBuffer()); 90 .Times(1).WillOnce(FillBuffer());
90 resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get()); 91 resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get());
91 ASSERT_NE(resampled_destination[0], 0); 92 ASSERT_NE(resampled_destination[0], 0);
92 93
93 // Flush and request more data, which should all be zeros now. 94 // Flush and request more data, which should all be zeros now.
94 resampler.Flush(); 95 resampler.Flush();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Source for data to be resampled. 263 // Source for data to be resampled.
263 SinusoidalLinearChirpSource resampler_source( 264 SinusoidalLinearChirpSource resampler_source(
264 input_rate_, input_samples, input_nyquist_freq, 0); 265 input_rate_, input_samples, input_nyquist_freq, 0);
265 266
266 const double io_ratio = input_rate_ / static_cast<double>(output_rate_); 267 const double io_ratio = input_rate_ / static_cast<double>(output_rate_);
267 SincResampler resampler(io_ratio, SincResampler::kDefaultRequestSize, 268 SincResampler resampler(io_ratio, SincResampler::kDefaultRequestSize,
268 &resampler_source); 269 &resampler_source);
269 270
270 // Force an update to the sample rate ratio to ensure dyanmic sample rate 271 // Force an update to the sample rate ratio to ensure dyanmic sample rate
271 // changes are working correctly. 272 // changes are working correctly.
272 rtc::scoped_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]); 273 std::unique_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]);
273 memcpy(kernel.get(), resampler.get_kernel_for_testing(), 274 memcpy(kernel.get(), resampler.get_kernel_for_testing(),
274 SincResampler::kKernelStorageSize); 275 SincResampler::kKernelStorageSize);
275 resampler.SetRatio(M_PI); 276 resampler.SetRatio(M_PI);
276 ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), 277 ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(),
277 SincResampler::kKernelStorageSize)); 278 SincResampler::kKernelStorageSize));
278 resampler.SetRatio(io_ratio); 279 resampler.SetRatio(io_ratio);
279 ASSERT_EQ(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), 280 ASSERT_EQ(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(),
280 SincResampler::kKernelStorageSize)); 281 SincResampler::kKernelStorageSize));
281 282
282 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to 283 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to
283 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes. 284 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes.
284 rtc::scoped_ptr<float[]> resampled_destination(new float[output_samples]); 285 std::unique_ptr<float[]> resampled_destination(new float[output_samples]);
285 rtc::scoped_ptr<float[]> pure_destination(new float[output_samples]); 286 std::unique_ptr<float[]> pure_destination(new float[output_samples]);
286 287
287 // Generate resampled signal. 288 // Generate resampled signal.
288 resampler.Resample(output_samples, resampled_destination.get()); 289 resampler.Resample(output_samples, resampled_destination.get());
289 290
290 // Generate pure signal. 291 // Generate pure signal.
291 SinusoidalLinearChirpSource pure_source( 292 SinusoidalLinearChirpSource pure_source(
292 output_rate_, output_samples, input_nyquist_freq, 0); 293 output_rate_, output_samples, input_nyquist_freq, 0);
293 pure_source.Run(output_samples, pure_destination.get()); 294 pure_source.Run(output_samples, pure_destination.get());
294 295
295 // Range of the Nyquist frequency (0.5 * min(input rate, output_rate)) which 296 // 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
380 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), 381 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61),
381 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), 382 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14),
382 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), 383 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42),
383 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), 384 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38),
384 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), 385 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63),
385 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), 386 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44),
386 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), 387 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52),
387 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); 388 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52)));
388 389
389 } // namespace webrtc 390 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/resampler/sinc_resampler.h ('k') | webrtc/common_audio/ring_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698