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 |
(...skipping 13 matching lines...) Expand all Loading... | |
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 ChannelBufferWavWriter::ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file) | |
35 : file_(file.Pass()) {} | |
36 | |
37 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) { | |
aluebs-webrtc
2015/10/24 00:53:35
Check the sample rate and number of channels corre
Andrew MacDonald
2015/10/29 00:44:50
ChannelBuffer doesn't know about sample rate, but
aluebs-webrtc
2015/10/29 01:03:20
Great point about sample rate.
| |
38 interleaved_.resize(buffer.size()); | |
39 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(), | |
40 &interleaved_[0]); | |
41 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]); | |
42 file_->WriteSamples(&interleaved_[0], interleaved_.size()); | |
43 } | |
44 | |
34 void WriteIntData(const int16_t* data, | 45 void WriteIntData(const int16_t* data, |
35 size_t length, | 46 size_t length, |
36 WavWriter* wav_file, | 47 WavWriter* wav_file, |
37 RawFile* raw_file) { | 48 RawFile* raw_file) { |
38 if (wav_file) { | 49 if (wav_file) { |
39 wav_file->WriteSamples(data, length); | 50 wav_file->WriteSamples(data, length); |
40 } | 51 } |
41 if (raw_file) { | 52 if (raw_file) { |
42 raw_file->WriteSamples(data, length); | 53 raw_file->WriteSamples(data, length); |
43 } | 54 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 case 1: | 101 case 1: |
91 return AudioProcessing::kMono; | 102 return AudioProcessing::kMono; |
92 case 2: | 103 case 2: |
93 return AudioProcessing::kStereo; | 104 return AudioProcessing::kStereo; |
94 default: | 105 default: |
95 assert(false); | 106 assert(false); |
96 return AudioProcessing::kMono; | 107 return AudioProcessing::kMono; |
97 } | 108 } |
98 } | 109 } |
99 | 110 |
100 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, | 111 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions) { |
101 size_t num_mics) { | |
102 const std::vector<float> values = ParseList<float>(mic_positions); | 112 const std::vector<float> values = ParseList<float>(mic_positions); |
103 RTC_CHECK_EQ(values.size(), 3 * num_mics) | 113 const size_t num_mics = |
104 << "Could not parse mic_positions or incorrect number of points."; | 114 rtc::CheckedDivExact(values.size(), static_cast<size_t>(3)); |
115 RTC_CHECK_GT(num_mics, 0u); | |
aluebs-webrtc
2015/10/24 00:53:34
Maybe add a fancy error message here too?
Andrew MacDonald
2015/10/29 00:44:50
Done.
| |
105 | 116 |
106 std::vector<Point> result; | 117 std::vector<Point> result; |
107 result.reserve(num_mics); | 118 result.reserve(num_mics); |
108 for (size_t i = 0; i < values.size(); i += 3) { | 119 for (size_t i = 0; i < values.size(); i += 3) { |
109 double x = values[i + 0]; | 120 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 } | 121 } |
114 | 122 |
115 return result; | 123 return result; |
116 } | 124 } |
117 | 125 |
126 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, | |
127 size_t num_mics) { | |
128 std::vector<Point> result = ParseArrayGeometry(mic_positions); | |
129 RTC_CHECK_EQ(result.size(), num_mics) | |
130 << "Could not parse mic_positions or incorrect number of points."; | |
131 return result; | |
132 } | |
118 | 133 |
119 } // namespace webrtc | 134 } // namespace webrtc |
OLD | NEW |