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 15 matching lines...) Expand all Loading... |
26 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN | 26 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN |
27 #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" |
28 #endif | 28 #endif |
29 fwrite(samples, sizeof(*samples), num_samples, file_handle_); | 29 fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
30 } | 30 } |
31 | 31 |
32 void RawFile::WriteSamples(const float* samples, size_t num_samples) { | 32 void RawFile::WriteSamples(const float* samples, size_t num_samples) { |
33 fwrite(samples, sizeof(*samples), num_samples, file_handle_); | 33 fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
34 } | 34 } |
35 | 35 |
36 ChannelBufferWavReader::ChannelBufferWavReader(rtc::scoped_ptr<WavReader> file) | 36 ChannelBufferWavReader::ChannelBufferWavReader(std::unique_ptr<WavReader> file) |
37 : file_(std::move(file)) {} | 37 : file_(std::move(file)) {} |
38 | 38 |
39 bool ChannelBufferWavReader::Read(ChannelBuffer<float>* buffer) { | 39 bool ChannelBufferWavReader::Read(ChannelBuffer<float>* buffer) { |
40 RTC_CHECK_EQ(file_->num_channels(), buffer->num_channels()); | 40 RTC_CHECK_EQ(file_->num_channels(), buffer->num_channels()); |
41 interleaved_.resize(buffer->size()); | 41 interleaved_.resize(buffer->size()); |
42 if (file_->ReadSamples(interleaved_.size(), &interleaved_[0]) != | 42 if (file_->ReadSamples(interleaved_.size(), &interleaved_[0]) != |
43 interleaved_.size()) { | 43 interleaved_.size()) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 FloatS16ToFloat(&interleaved_[0], interleaved_.size(), &interleaved_[0]); | 47 FloatS16ToFloat(&interleaved_[0], interleaved_.size(), &interleaved_[0]); |
48 Deinterleave(&interleaved_[0], buffer->num_frames(), buffer->num_channels(), | 48 Deinterleave(&interleaved_[0], buffer->num_frames(), buffer->num_channels(), |
49 buffer->channels()); | 49 buffer->channels()); |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 ChannelBufferWavWriter::ChannelBufferWavWriter(rtc::scoped_ptr<WavWriter> file) | 53 ChannelBufferWavWriter::ChannelBufferWavWriter(std::unique_ptr<WavWriter> file) |
54 : file_(std::move(file)) {} | 54 : file_(std::move(file)) {} |
55 | 55 |
56 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) { | 56 void ChannelBufferWavWriter::Write(const ChannelBuffer<float>& buffer) { |
57 RTC_CHECK_EQ(file_->num_channels(), buffer.num_channels()); | 57 RTC_CHECK_EQ(file_->num_channels(), buffer.num_channels()); |
58 interleaved_.resize(buffer.size()); | 58 interleaved_.resize(buffer.size()); |
59 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(), | 59 Interleave(buffer.channels(), buffer.num_frames(), buffer.num_channels(), |
60 &interleaved_[0]); | 60 &interleaved_[0]); |
61 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]); | 61 FloatToFloatS16(&interleaved_[0], interleaved_.size(), &interleaved_[0]); |
62 file_->WriteSamples(&interleaved_[0], interleaved_.size()); | 62 file_->WriteSamples(&interleaved_[0], interleaved_.size()); |
63 } | 63 } |
64 | 64 |
65 void WriteIntData(const int16_t* data, | 65 void WriteIntData(const int16_t* data, |
66 size_t length, | 66 size_t length, |
67 WavWriter* wav_file, | 67 WavWriter* wav_file, |
68 RawFile* raw_file) { | 68 RawFile* raw_file) { |
69 if (wav_file) { | 69 if (wav_file) { |
70 wav_file->WriteSamples(data, length); | 70 wav_file->WriteSamples(data, length); |
71 } | 71 } |
72 if (raw_file) { | 72 if (raw_file) { |
73 raw_file->WriteSamples(data, length); | 73 raw_file->WriteSamples(data, length); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void WriteFloatData(const float* const* data, | 77 void WriteFloatData(const float* const* data, |
78 size_t samples_per_channel, | 78 size_t samples_per_channel, |
79 size_t num_channels, | 79 size_t num_channels, |
80 WavWriter* wav_file, | 80 WavWriter* wav_file, |
81 RawFile* raw_file) { | 81 RawFile* raw_file) { |
82 size_t length = num_channels * samples_per_channel; | 82 size_t length = num_channels * samples_per_channel; |
83 rtc::scoped_ptr<float[]> buffer(new float[length]); | 83 std::unique_ptr<float[]> buffer(new float[length]); |
84 Interleave(data, samples_per_channel, num_channels, buffer.get()); | 84 Interleave(data, samples_per_channel, num_channels, buffer.get()); |
85 if (raw_file) { | 85 if (raw_file) { |
86 raw_file->WriteSamples(buffer.get(), length); | 86 raw_file->WriteSamples(buffer.get(), length); |
87 } | 87 } |
88 // TODO(aluebs): Use ScaleToInt16Range() from audio_util | 88 // TODO(aluebs): Use ScaleToInt16Range() from audio_util |
89 for (size_t i = 0; i < length; ++i) { | 89 for (size_t i = 0; i < length; ++i) { |
90 buffer[i] = buffer[i] > 0 ? | 90 buffer[i] = buffer[i] > 0 ? |
91 buffer[i] * std::numeric_limits<int16_t>::max() : | 91 buffer[i] * std::numeric_limits<int16_t>::max() : |
92 -buffer[i] * std::numeric_limits<int16_t>::min(); | 92 -buffer[i] * std::numeric_limits<int16_t>::min(); |
93 } | 93 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, | 146 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, |
147 size_t num_mics) { | 147 size_t num_mics) { |
148 std::vector<Point> result = ParseArrayGeometry(mic_positions); | 148 std::vector<Point> result = ParseArrayGeometry(mic_positions); |
149 RTC_CHECK_EQ(result.size(), num_mics) | 149 RTC_CHECK_EQ(result.size(), num_mics) |
150 << "Could not parse mic_positions or incorrect number of points."; | 150 << "Could not parse mic_positions or incorrect number of points."; |
151 return result; | 151 return result; |
152 } | 152 } |
153 | 153 |
154 } // namespace webrtc | 154 } // namespace webrtc |
OLD | NEW |