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

Side by Side Diff: webrtc/modules/audio_processing/transient/transient_suppression_test.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_suppressor.h" 11 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h"
12 12
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <stdio.h> 14 #include <stdio.h>
15
16 #include <memory>
15 #include <string> 17 #include <string>
16 18
17 #include "gflags/gflags.h" 19 #include "gflags/gflags.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/common_audio/include/audio_util.h" 21 #include "webrtc/common_audio/include/audio_util.h"
21 #include "webrtc/modules/audio_processing/agc/agc.h" 22 #include "webrtc/modules/audio_processing/agc/agc.h"
22 #include "webrtc/modules/include/module_common_types.h" 23 #include "webrtc/modules/include/module_common_types.h"
23 #include "webrtc/test/testsupport/fileutils.h" 24 #include "webrtc/test/testsupport/fileutils.h"
24 #include "webrtc/typedefs.h" 25 #include "webrtc/typedefs.h"
25 26
26 DEFINE_string(in_file_name, "", "PCM file that contains the signal."); 27 DEFINE_string(in_file_name, "", "PCM file that contains the signal.");
27 DEFINE_string(detection_file_name, 28 DEFINE_string(detection_file_name,
28 "", 29 "",
29 "PCM file that contains the detection signal."); 30 "PCM file that contains the detection signal.");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // [-1,1]. Return true iff all the buffers were filled completely. 77 // [-1,1]. Return true iff all the buffers were filled completely.
77 bool ReadBuffers(FILE* in_file, 78 bool ReadBuffers(FILE* in_file,
78 size_t audio_buffer_size, 79 size_t audio_buffer_size,
79 int num_channels, 80 int num_channels,
80 int16_t* audio_buffer, 81 int16_t* audio_buffer,
81 FILE* detection_file, 82 FILE* detection_file,
82 size_t detection_buffer_size, 83 size_t detection_buffer_size,
83 float* detection_buffer, 84 float* detection_buffer,
84 FILE* reference_file, 85 FILE* reference_file,
85 float* reference_buffer) { 86 float* reference_buffer) {
86 rtc::scoped_ptr<int16_t[]> tmpbuf; 87 std::unique_ptr<int16_t[]> tmpbuf;
87 int16_t* read_ptr = audio_buffer; 88 int16_t* read_ptr = audio_buffer;
88 if (num_channels > 1) { 89 if (num_channels > 1) {
89 tmpbuf.reset(new int16_t[num_channels * audio_buffer_size]); 90 tmpbuf.reset(new int16_t[num_channels * audio_buffer_size]);
90 read_ptr = tmpbuf.get(); 91 read_ptr = tmpbuf.get();
91 } 92 }
92 if (fread(read_ptr, 93 if (fread(read_ptr,
93 sizeof(*read_ptr), 94 sizeof(*read_ptr),
94 num_channels * audio_buffer_size, 95 num_channels * audio_buffer_size,
95 in_file) != num_channels * audio_buffer_size) { 96 in_file) != num_channels * audio_buffer_size) {
96 return false; 97 return false;
97 } 98 }
98 // De-interleave. 99 // De-interleave.
99 if (num_channels > 1) { 100 if (num_channels > 1) {
100 for (int i = 0; i < num_channels; ++i) { 101 for (int i = 0; i < num_channels; ++i) {
101 for (size_t j = 0; j < audio_buffer_size; ++j) { 102 for (size_t j = 0; j < audio_buffer_size; ++j) {
102 audio_buffer[i * audio_buffer_size + j] = 103 audio_buffer[i * audio_buffer_size + j] =
103 read_ptr[i + j * num_channels]; 104 read_ptr[i + j * num_channels];
104 } 105 }
105 } 106 }
106 } 107 }
107 if (detection_file) { 108 if (detection_file) {
108 rtc::scoped_ptr<int16_t[]> ibuf(new int16_t[detection_buffer_size]); 109 std::unique_ptr<int16_t[]> ibuf(new int16_t[detection_buffer_size]);
109 if (fread(ibuf.get(), sizeof(ibuf[0]), detection_buffer_size, 110 if (fread(ibuf.get(), sizeof(ibuf[0]), detection_buffer_size,
110 detection_file) != detection_buffer_size) 111 detection_file) != detection_buffer_size)
111 return false; 112 return false;
112 for (size_t i = 0; i < detection_buffer_size; ++i) 113 for (size_t i = 0; i < detection_buffer_size; ++i)
113 detection_buffer[i] = ibuf[i]; 114 detection_buffer[i] = ibuf[i];
114 } 115 }
115 if (reference_file) { 116 if (reference_file) {
116 rtc::scoped_ptr<int16_t[]> ibuf(new int16_t[audio_buffer_size]); 117 std::unique_ptr<int16_t[]> ibuf(new int16_t[audio_buffer_size]);
117 if (fread(ibuf.get(), sizeof(ibuf[0]), audio_buffer_size, reference_file) 118 if (fread(ibuf.get(), sizeof(ibuf[0]), audio_buffer_size, reference_file)
118 != audio_buffer_size) 119 != audio_buffer_size)
119 return false; 120 return false;
120 S16ToFloat(ibuf.get(), audio_buffer_size, reference_buffer); 121 S16ToFloat(ibuf.get(), audio_buffer_size, reference_buffer);
121 } 122 }
122 return true; 123 return true;
123 } 124 }
124 125
125 // Write a number of samples to an open signed 16-bit host-endian PCM file. 126 // Write a number of samples to an open signed 16-bit host-endian PCM file.
126 static void WritePCM(FILE* f, 127 static void WritePCM(FILE* f,
127 size_t num_samples, 128 size_t num_samples,
128 int num_channels, 129 int num_channels,
129 const float* buffer) { 130 const float* buffer) {
130 rtc::scoped_ptr<int16_t[]> ibuf(new int16_t[num_channels * num_samples]); 131 std::unique_ptr<int16_t[]> ibuf(new int16_t[num_channels * num_samples]);
131 // Interleave. 132 // Interleave.
132 for (int i = 0; i < num_channels; ++i) { 133 for (int i = 0; i < num_channels; ++i) {
133 for (size_t j = 0; j < num_samples; ++j) { 134 for (size_t j = 0; j < num_samples; ++j) {
134 ibuf[i + j * num_channels] = FloatS16ToS16(buffer[i * num_samples + j]); 135 ibuf[i + j * num_channels] = FloatS16ToS16(buffer[i * num_samples + j]);
135 } 136 }
136 } 137 }
137 fwrite(ibuf.get(), sizeof(ibuf[0]), num_channels * num_samples, f); 138 fwrite(ibuf.get(), sizeof(ibuf[0]), num_channels * num_samples, f);
138 } 139 }
139 140
140 // This application tests the transient suppression by providing a processed 141 // This application tests the transient suppression by providing a processed
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 TransientSuppressor suppressor; 176 TransientSuppressor suppressor;
176 suppressor.Initialize( 177 suppressor.Initialize(
177 FLAGS_sample_rate_hz, detection_rate_hz, FLAGS_num_channels); 178 FLAGS_sample_rate_hz, detection_rate_hz, FLAGS_num_channels);
178 179
179 const size_t audio_buffer_size = 180 const size_t audio_buffer_size =
180 FLAGS_chunk_size_ms * FLAGS_sample_rate_hz / 1000; 181 FLAGS_chunk_size_ms * FLAGS_sample_rate_hz / 1000;
181 const size_t detection_buffer_size = 182 const size_t detection_buffer_size =
182 FLAGS_chunk_size_ms * detection_rate_hz / 1000; 183 FLAGS_chunk_size_ms * detection_rate_hz / 1000;
183 184
184 // int16 and float variants of the same data. 185 // int16 and float variants of the same data.
185 rtc::scoped_ptr<int16_t[]> audio_buffer_i( 186 std::unique_ptr<int16_t[]> audio_buffer_i(
186 new int16_t[FLAGS_num_channels * audio_buffer_size]); 187 new int16_t[FLAGS_num_channels * audio_buffer_size]);
187 rtc::scoped_ptr<float[]> audio_buffer_f( 188 std::unique_ptr<float[]> audio_buffer_f(
188 new float[FLAGS_num_channels * audio_buffer_size]); 189 new float[FLAGS_num_channels * audio_buffer_size]);
189 190
190 rtc::scoped_ptr<float[]> detection_buffer, reference_buffer; 191 std::unique_ptr<float[]> detection_buffer, reference_buffer;
191 192
192 if (detection_file) 193 if (detection_file)
193 detection_buffer.reset(new float[detection_buffer_size]); 194 detection_buffer.reset(new float[detection_buffer_size]);
194 if (reference_file) 195 if (reference_file)
195 reference_buffer.reset(new float[audio_buffer_size]); 196 reference_buffer.reset(new float[audio_buffer_size]);
196 197
197 while (ReadBuffers(in_file, 198 while (ReadBuffers(in_file,
198 audio_buffer_size, 199 audio_buffer_size,
199 FLAGS_num_channels, 200 FLAGS_num_channels,
200 audio_buffer_i.get(), 201 audio_buffer_i.get(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 242 }
242 243
243 } // namespace webrtc 244 } // namespace webrtc
244 245
245 int main(int argc, char* argv[]) { 246 int main(int argc, char* argv[]) {
246 google::SetUsageMessage(webrtc::kUsage); 247 google::SetUsageMessage(webrtc::kUsage);
247 google::ParseCommandLineFlags(&argc, &argv, true); 248 google::ParseCommandLineFlags(&argc, &argv, true);
248 webrtc::void_main(); 249 webrtc::void_main();
249 return 0; 250 return 0;
250 } 251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698