OLD | NEW |
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 |
| 11 #include <utility> |
| 12 |
11 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
12 #include "webrtc/modules/audio_processing/test/test_utils.h" | 14 #include "webrtc/modules/audio_processing/test/test_utils.h" |
13 | 15 |
14 namespace webrtc { | 16 namespace webrtc { |
15 | 17 |
16 RawFile::RawFile(const std::string& filename) | 18 RawFile::RawFile(const std::string& filename) |
17 : file_handle_(fopen(filename.c_str(), "wb")) {} | 19 : file_handle_(fopen(filename.c_str(), "wb")) {} |
18 | 20 |
19 RawFile::~RawFile() { | 21 RawFile::~RawFile() { |
20 fclose(file_handle_); | 22 fclose(file_handle_); |
21 } | 23 } |
22 | 24 |
23 void RawFile::WriteSamples(const int16_t* samples, size_t num_samples) { | 25 void RawFile::WriteSamples(const int16_t* samples, size_t num_samples) { |
24 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN | 26 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN |
25 #error "Need to convert samples to little-endian when writing to PCM file" | 27 #error "Need to convert samples to little-endian when writing to PCM file" |
26 #endif | 28 #endif |
27 fwrite(samples, sizeof(*samples), num_samples, file_handle_); | 29 fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
28 } | 30 } |
29 | 31 |
30 void RawFile::WriteSamples(const float* samples, size_t num_samples) { | 32 void RawFile::WriteSamples(const float* samples, size_t num_samples) { |
31 fwrite(samples, sizeof(*samples), num_samples, file_handle_); | 33 fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
32 } | 34 } |
33 | 35 |
34 ChannelBufferWavReader::ChannelBufferWavReader(rtc::scoped_ptr<WavReader> file) | 36 ChannelBufferWavReader::ChannelBufferWavReader(rtc::scoped_ptr<WavReader> file) |
35 : file_(file.Pass()) {} | 37 : file_(std::move(file)) {} |
36 | 38 |
37 bool ChannelBufferWavReader::Read(ChannelBuffer<float>* buffer) { | 39 bool ChannelBufferWavReader::Read(ChannelBuffer<float>* buffer) { |
38 RTC_CHECK_EQ(file_->num_channels(), buffer->num_channels()); | 40 RTC_CHECK_EQ(file_->num_channels(), buffer->num_channels()); |
39 interleaved_.resize(buffer->size()); | 41 interleaved_.resize(buffer->size()); |
40 if (file_->ReadSamples(interleaved_.size(), &interleaved_[0]) != | 42 if (file_->ReadSamples(interleaved_.size(), &interleaved_[0]) != |
41 interleaved_.size()) { | 43 interleaved_.size()) { |
42 return false; | 44 return false; |
43 } | 45 } |
44 | 46 |
45 FloatS16ToFloat(&interleaved_[0], interleaved_.size(), &interleaved_[0]); | 47 FloatS16ToFloat(&interleaved_[0], interleaved_.size(), &interleaved_[0]); |
46 Deinterleave(&interleaved_[0], buffer->num_frames(), buffer->num_channels(), | 48 Deinterleave(&interleaved_[0], buffer->num_frames(), buffer->num_channels(), |
47 buffer->channels()); | 49 buffer->channels()); |
48 return true; | 50 return true; |
49 } | 51 } |
50 | 52 |
51 ChannelBufferWavWriter::ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file) | 53 ChannelBufferWavWriter::ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file) |
52 : file_(file.Pass()) {} | 54 : file_(std::move(file)) {} |
53 | 55 |
54 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) { | 56 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) { |
55 RTC_CHECK_EQ(file_->num_channels(), buffer.num_channels()); | 57 RTC_CHECK_EQ(file_->num_channels(), buffer.num_channels()); |
56 interleaved_.resize(buffer.size()); | 58 interleaved_.resize(buffer.size()); |
57 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(), | 59 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(), |
58 &interleaved_[0]); | 60 &interleaved_[0]); |
59 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]); | 61 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]); |
60 file_->WriteSamples(&interleaved_[0], interleaved_.size()); | 62 file_->WriteSamples(&interleaved_[0], interleaved_.size()); |
61 } | 63 } |
62 | 64 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 145 |
144 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, | 146 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, |
145 size_t num_mics) { | 147 size_t num_mics) { |
146 std::vector<Point> result = ParseArrayGeometry(mic_positions); | 148 std::vector<Point> result = ParseArrayGeometry(mic_positions); |
147 RTC_CHECK_EQ(result.size(), num_mics) | 149 RTC_CHECK_EQ(result.size(), num_mics) |
148 << "Could not parse mic_positions or incorrect number of points."; | 150 << "Could not parse mic_positions or incorrect number of points."; |
149 return result; | 151 return result; |
150 } | 152 } |
151 | 153 |
152 } // namespace webrtc | 154 } // namespace webrtc |
OLD | NEW |