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

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

Issue 1409943002: Add aecdump support to audioproc_f. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 1 month 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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
(...skipping 13 matching lines...) Expand all
24 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN 24 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN
25 #error "Need to convert samples to little-endian when writing to PCM file" 25 #error "Need to convert samples to little-endian when writing to PCM file"
26 #endif 26 #endif
27 fwrite(samples, sizeof(*samples), num_samples, file_handle_); 27 fwrite(samples, sizeof(*samples), num_samples, file_handle_);
28 } 28 }
29 29
30 void RawFile::WriteSamples(const float* samples, size_t num_samples) { 30 void RawFile::WriteSamples(const float* samples, size_t num_samples) {
31 fwrite(samples, sizeof(*samples), num_samples, file_handle_); 31 fwrite(samples, sizeof(*samples), num_samples, file_handle_);
32 } 32 }
33 33
34 ChannelBufferWavReader::ChannelBufferWavReader(rtc::scoped_ptr<WavReader> file)
35 : file_(file.Pass()) {}
36
37 bool ChannelBufferWavReader::Read(ChannelBuffer<float>* buffer) {
38 RTC_CHECK_EQ(file_->num_channels(), buffer->num_channels());
39 interleaved_.resize(buffer->size());
40 if (file_->ReadSamples(interleaved_.size(), &interleaved_[0]) !=
41 interleaved_.size()) {
42 return false;
43 }
44
45 FloatS16ToFloat(&interleaved_[0], interleaved_.size(), &interleaved_[0]);
46 Deinterleave(&interleaved_[0], buffer->num_frames(), buffer->num_channels(),
47 buffer->channels());
48 return true;
49 }
50
51 ChannelBufferWavWriter::ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file)
52 : file_(file.Pass()) {}
53
54 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) {
55 RTC_CHECK_EQ(file_->num_channels(), buffer.num_channels());
56 interleaved_.resize(buffer.size());
57 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(),
58 &interleaved_[0]);
59 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]);
60 file_->WriteSamples(&interleaved_[0], interleaved_.size());
61 }
62
34 void WriteIntData(const int16_t* data, 63 void WriteIntData(const int16_t* data,
35 size_t length, 64 size_t length,
36 WavWriter* wav_file, 65 WavWriter* wav_file,
37 RawFile* raw_file) { 66 RawFile* raw_file) {
38 if (wav_file) { 67 if (wav_file) {
39 wav_file->WriteSamples(data, length); 68 wav_file->WriteSamples(data, length);
40 } 69 }
41 if (raw_file) { 70 if (raw_file) {
42 raw_file->WriteSamples(data, length); 71 raw_file->WriteSamples(data, length);
43 } 72 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 sample_rate_hz / 1000; 114 sample_rate_hz / 1000;
86 } 115 }
87 116
88 AudioProcessing::ChannelLayout LayoutFromChannels(int num_channels) { 117 AudioProcessing::ChannelLayout LayoutFromChannels(int num_channels) {
89 switch (num_channels) { 118 switch (num_channels) {
90 case 1: 119 case 1:
91 return AudioProcessing::kMono; 120 return AudioProcessing::kMono;
92 case 2: 121 case 2:
93 return AudioProcessing::kStereo; 122 return AudioProcessing::kStereo;
94 default: 123 default:
95 assert(false); 124 RTC_CHECK(false);
96 return AudioProcessing::kMono; 125 return AudioProcessing::kMono;
97 } 126 }
98 } 127 }
99 128
100 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, 129 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions) {
101 size_t num_mics) {
102 const std::vector<float> values = ParseList<float>(mic_positions); 130 const std::vector<float> values = ParseList<float>(mic_positions);
103 RTC_CHECK_EQ(values.size(), 3 * num_mics) 131 const size_t num_mics =
104 << "Could not parse mic_positions or incorrect number of points."; 132 rtc::CheckedDivExact(values.size(), static_cast<size_t>(3));
133 RTC_CHECK_GT(num_mics, 0u) << "mic_positions is not large enough.";
105 134
106 std::vector<Point> result; 135 std::vector<Point> result;
107 result.reserve(num_mics); 136 result.reserve(num_mics);
108 for (size_t i = 0; i < values.size(); i += 3) { 137 for (size_t i = 0; i < values.size(); i += 3) {
109 double x = values[i + 0]; 138 result.push_back(Point(values[i + 0], values[i + 1], values[i + 2]));
110 double y = values[i + 1];
111 double z = values[i + 2];
112 result.push_back(Point(x, y, z));
113 } 139 }
114 140
115 return result; 141 return result;
116 } 142 }
117 143
144 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions,
145 size_t num_mics) {
146 std::vector<Point> result = ParseArrayGeometry(mic_positions);
147 RTC_CHECK_EQ(result.size(), num_mics)
148 << "Could not parse mic_positions or incorrect number of points.";
149 return result;
150 }
118 151
119 } // namespace webrtc 152 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/test_utils.h ('k') | webrtc/system_wrappers/include/tick_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698