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

Side by Side Diff: webrtc/modules/audio_processing/test/test_utils.h

Issue 1694423002: Replace scoped_ptr with unique_ptr in webrtc/modules/audio_processing/test/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_
13 13
14 #include <math.h> 14 #include <math.h>
15 #include <iterator> 15 #include <iterator>
16 #include <limits> 16 #include <limits>
17 #include <memory>
17 #include <string> 18 #include <string>
18 #include <vector> 19 #include <vector>
19 20
20 #include "webrtc/base/constructormagic.h" 21 #include "webrtc/base/constructormagic.h"
21 #include "webrtc/base/scoped_ptr.h"
22 #include "webrtc/common_audio/channel_buffer.h" 22 #include "webrtc/common_audio/channel_buffer.h"
23 #include "webrtc/common_audio/wav_file.h" 23 #include "webrtc/common_audio/wav_file.h"
24 #include "webrtc/modules/audio_processing/include/audio_processing.h" 24 #include "webrtc/modules/audio_processing/include/audio_processing.h"
25 #include "webrtc/modules/include/module_common_types.h" 25 #include "webrtc/modules/include/module_common_types.h"
26 26
27 namespace webrtc { 27 namespace webrtc {
28 28
29 static const AudioProcessing::Error kNoErr = AudioProcessing::kNoError; 29 static const AudioProcessing::Error kNoErr = AudioProcessing::kNoError;
30 #define EXPECT_NOERR(expr) EXPECT_EQ(kNoErr, (expr)) 30 #define EXPECT_NOERR(expr) EXPECT_EQ(kNoErr, (expr))
31 31
32 class RawFile final { 32 class RawFile final {
33 public: 33 public:
34 explicit RawFile(const std::string& filename); 34 explicit RawFile(const std::string& filename);
35 ~RawFile(); 35 ~RawFile();
36 36
37 void WriteSamples(const int16_t* samples, size_t num_samples); 37 void WriteSamples(const int16_t* samples, size_t num_samples);
38 void WriteSamples(const float* samples, size_t num_samples); 38 void WriteSamples(const float* samples, size_t num_samples);
39 39
40 private: 40 private:
41 FILE* file_handle_; 41 FILE* file_handle_;
42 42
43 RTC_DISALLOW_COPY_AND_ASSIGN(RawFile); 43 RTC_DISALLOW_COPY_AND_ASSIGN(RawFile);
44 }; 44 };
45 45
46 // Reads ChannelBuffers from a provided WavReader. 46 // Reads ChannelBuffers from a provided WavReader.
47 class ChannelBufferWavReader final { 47 class ChannelBufferWavReader final {
48 public: 48 public:
49 explicit ChannelBufferWavReader(rtc::scoped_ptr<WavReader> file); 49 explicit ChannelBufferWavReader(std::unique_ptr<WavReader> file);
50 50
51 // Reads data from the file according to the |buffer| format. Returns false if 51 // Reads data from the file according to the |buffer| format. Returns false if
52 // a full buffer can't be read from the file. 52 // a full buffer can't be read from the file.
53 bool Read(ChannelBuffer<float>* buffer); 53 bool Read(ChannelBuffer<float>* buffer);
54 54
55 private: 55 private:
56 rtc::scoped_ptr<WavReader> file_; 56 std::unique_ptr<WavReader> file_;
57 std::vector<float> interleaved_; 57 std::vector<float> interleaved_;
58 58
59 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelBufferWavReader); 59 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelBufferWavReader);
60 }; 60 };
61 61
62 // Writes ChannelBuffers to a provided WavWriter. 62 // Writes ChannelBuffers to a provided WavWriter.
63 class ChannelBufferWavWriter final { 63 class ChannelBufferWavWriter final {
64 public: 64 public:
65 explicit ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file); 65 explicit ChannelBufferWavWriter(std::unique_ptr<WavWriter> file);
66 void Write(const ChannelBuffer<float>& buffer); 66 void Write(const ChannelBuffer<float>& buffer);
67 67
68 private: 68 private:
69 rtc::scoped_ptr<WavWriter> file_; 69 std::unique_ptr<WavWriter> file_;
70 std::vector<float> interleaved_; 70 std::vector<float> interleaved_;
71 71
72 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelBufferWavWriter); 72 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelBufferWavWriter);
73 }; 73 };
74 74
75 void WriteIntData(const int16_t* data, 75 void WriteIntData(const int16_t* data,
76 size_t length, 76 size_t length,
77 WavWriter* wav_file, 77 WavWriter* wav_file,
78 RawFile* raw_file); 78 RawFile* raw_file);
79 79
80 void WriteFloatData(const float* const* data, 80 void WriteFloatData(const float* const* data,
81 size_t samples_per_channel, 81 size_t samples_per_channel,
82 size_t num_channels, 82 size_t num_channels,
83 WavWriter* wav_file, 83 WavWriter* wav_file,
84 RawFile* raw_file); 84 RawFile* raw_file);
85 85
86 // Exits on failure; do not use in unit tests. 86 // Exits on failure; do not use in unit tests.
87 FILE* OpenFile(const std::string& filename, const char* mode); 87 FILE* OpenFile(const std::string& filename, const char* mode);
88 88
89 size_t SamplesFromRate(int rate); 89 size_t SamplesFromRate(int rate);
90 90
91 void SetFrameSampleRate(AudioFrame* frame, 91 void SetFrameSampleRate(AudioFrame* frame,
92 int sample_rate_hz); 92 int sample_rate_hz);
93 93
94 template <typename T> 94 template <typename T>
95 void SetContainerFormat(int sample_rate_hz, 95 void SetContainerFormat(int sample_rate_hz,
96 size_t num_channels, 96 size_t num_channels,
97 AudioFrame* frame, 97 AudioFrame* frame,
98 rtc::scoped_ptr<ChannelBuffer<T> >* cb) { 98 std::unique_ptr<ChannelBuffer<T> >* cb) {
99 SetFrameSampleRate(frame, sample_rate_hz); 99 SetFrameSampleRate(frame, sample_rate_hz);
100 frame->num_channels_ = num_channels; 100 frame->num_channels_ = num_channels;
101 cb->reset(new ChannelBuffer<T>(frame->samples_per_channel_, num_channels)); 101 cb->reset(new ChannelBuffer<T>(frame->samples_per_channel_, num_channels));
102 } 102 }
103 103
104 AudioProcessing::ChannelLayout LayoutFromChannels(size_t num_channels); 104 AudioProcessing::ChannelLayout LayoutFromChannels(size_t num_channels);
105 105
106 template <typename T> 106 template <typename T>
107 float ComputeSNR(const T* ref, const T* test, size_t length, float* variance) { 107 float ComputeSNR(const T* ref, const T* test, size_t length, float* variance) {
108 float mse = 0; 108 float mse = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // appropriate error message has been printed to stdout. 146 // appropriate error message has been printed to stdout.
147 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, 147 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions,
148 size_t num_mics); 148 size_t num_mics);
149 149
150 // Same as above, but without the num_mics check for when it isn't available. 150 // Same as above, but without the num_mics check for when it isn't available.
151 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions); 151 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions);
152 152
153 } // namespace webrtc 153 } // namespace webrtc
154 154
155 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_ 155 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/protobuf_utils.cc ('k') | webrtc/modules/audio_processing/test/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698