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

Side by Side Diff: webrtc/modules/audio_processing/transient/transient_detector_unittest.cc

Issue 1698843003: Replace scoped_ptr with unique_ptr in webrtc/modules/audio_processing/transient/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: compile fix 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 #include "webrtc/modules/audio_processing/transient/transient_detector.h" 11 #include "webrtc/modules/audio_processing/transient/transient_detector.h"
12 12
13 #include <memory>
13 #include <sstream> 14 #include <sstream>
14 #include <string> 15 #include <string>
15 16
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/modules/audio_processing/transient/common.h" 18 #include "webrtc/modules/audio_processing/transient/common.h"
19 #include "webrtc/modules/audio_processing/transient/file_utils.h" 19 #include "webrtc/modules/audio_processing/transient/file_utils.h"
20 #include "webrtc/system_wrappers/include/file_wrapper.h" 20 #include "webrtc/system_wrappers/include/file_wrapper.h"
21 #include "webrtc/test/testsupport/fileutils.h" 21 #include "webrtc/test/testsupport/fileutils.h"
22 #include "webrtc/typedefs.h" 22 #include "webrtc/typedefs.h"
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 static const int kSampleRatesHz[] = {ts::kSampleRate8kHz, 26 static const int kSampleRatesHz[] = {ts::kSampleRate8kHz,
27 ts::kSampleRate16kHz, 27 ts::kSampleRate16kHz,
(...skipping 14 matching lines...) Expand all
42 TEST(TransientDetectorTest, CorrectnessBasedOnFiles) { 42 TEST(TransientDetectorTest, CorrectnessBasedOnFiles) {
43 #endif 43 #endif
44 for (size_t i = 0; i < kNumberOfSampleRates; ++i) { 44 for (size_t i = 0; i < kNumberOfSampleRates; ++i) {
45 int sample_rate_hz = kSampleRatesHz[i]; 45 int sample_rate_hz = kSampleRatesHz[i];
46 46
47 // Prepare detect file. 47 // Prepare detect file.
48 std::stringstream detect_file_name; 48 std::stringstream detect_file_name;
49 detect_file_name << "audio_processing/transient/detect" 49 detect_file_name << "audio_processing/transient/detect"
50 << (sample_rate_hz / 1000) << "kHz"; 50 << (sample_rate_hz / 1000) << "kHz";
51 51
52 rtc::scoped_ptr<FileWrapper> detect_file(FileWrapper::Create()); 52 std::unique_ptr<FileWrapper> detect_file(FileWrapper::Create());
53 53
54 detect_file->OpenFile( 54 detect_file->OpenFile(
55 test::ResourcePath(detect_file_name.str(), "dat").c_str(), 55 test::ResourcePath(detect_file_name.str(), "dat").c_str(),
56 true, // Read only. 56 true, // Read only.
57 false, // No loop. 57 false, // No loop.
58 false); // No text. 58 false); // No text.
59 59
60 bool file_opened = detect_file->Open(); 60 bool file_opened = detect_file->Open();
61 ASSERT_TRUE(file_opened) << "File could not be opened.\n" 61 ASSERT_TRUE(file_opened) << "File could not be opened.\n"
62 << detect_file_name.str().c_str(); 62 << detect_file_name.str().c_str();
63 63
64 // Prepare audio file. 64 // Prepare audio file.
65 std::stringstream audio_file_name; 65 std::stringstream audio_file_name;
66 audio_file_name << "audio_processing/transient/audio" 66 audio_file_name << "audio_processing/transient/audio"
67 << (sample_rate_hz / 1000) << "kHz"; 67 << (sample_rate_hz / 1000) << "kHz";
68 68
69 rtc::scoped_ptr<FileWrapper> audio_file(FileWrapper::Create()); 69 std::unique_ptr<FileWrapper> audio_file(FileWrapper::Create());
70 70
71 audio_file->OpenFile( 71 audio_file->OpenFile(
72 test::ResourcePath(audio_file_name.str(), "pcm").c_str(), 72 test::ResourcePath(audio_file_name.str(), "pcm").c_str(),
73 true, // Read only. 73 true, // Read only.
74 false, // No loop. 74 false, // No loop.
75 false); // No text. 75 false); // No text.
76 76
77 // Create detector. 77 // Create detector.
78 TransientDetector detector(sample_rate_hz); 78 TransientDetector detector(sample_rate_hz);
79 79
80 const size_t buffer_length = sample_rate_hz * ts::kChunkSizeMs / 1000; 80 const size_t buffer_length = sample_rate_hz * ts::kChunkSizeMs / 1000;
81 rtc::scoped_ptr<float[]> buffer(new float[buffer_length]); 81 std::unique_ptr<float[]> buffer(new float[buffer_length]);
82 82
83 const float kTolerance = 0.02f; 83 const float kTolerance = 0.02f;
84 84
85 size_t frames_read = 0; 85 size_t frames_read = 0;
86 86
87 while (ReadInt16FromFileToFloatBuffer(audio_file.get(), 87 while (ReadInt16FromFileToFloatBuffer(audio_file.get(),
88 buffer_length, 88 buffer_length,
89 buffer.get()) == buffer_length) { 89 buffer.get()) == buffer_length) {
90 ++frames_read; 90 ++frames_read;
91 91
92 float detector_value = 92 float detector_value =
93 detector.Detect(buffer.get(), buffer_length, NULL, 0); 93 detector.Detect(buffer.get(), buffer_length, NULL, 0);
94 double file_value; 94 double file_value;
95 ASSERT_EQ(1u, ReadDoubleBufferFromFile(detect_file.get(), 1, &file_value)) 95 ASSERT_EQ(1u, ReadDoubleBufferFromFile(detect_file.get(), 1, &file_value))
96 << "Detect test file is malformed.\n"; 96 << "Detect test file is malformed.\n";
97 97
98 // Compare results with data from the matlab test file. 98 // Compare results with data from the matlab test file.
99 EXPECT_NEAR(file_value, detector_value, kTolerance) << "Frame: " 99 EXPECT_NEAR(file_value, detector_value, kTolerance) << "Frame: "
100 << frames_read; 100 << frames_read;
101 } 101 }
102 102
103 detect_file->CloseFile(); 103 detect_file->CloseFile();
104 audio_file->CloseFile(); 104 audio_file->CloseFile();
105 } 105 }
106 } 106 }
107 107
108 } // namespace webrtc 108 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698