OLD | NEW |
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 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) { | 116 void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) { |
117 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN | 117 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN |
118 #error "Need to convert samples to little-endian when writing to WAV file" | 118 #error "Need to convert samples to little-endian when writing to WAV file" |
119 #endif | 119 #endif |
120 const size_t written = | 120 const size_t written = |
121 fwrite(samples, sizeof(*samples), num_samples, file_handle_); | 121 fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
122 CHECK_EQ(num_samples, written); | 122 CHECK_EQ(num_samples, written); |
123 num_samples_ += static_cast<uint32_t>(written); | 123 num_samples_ += static_cast<uint32_t>(written); |
124 CHECK(written <= std::numeric_limits<uint32_t>::max() || | 124 CHECK(written <= std::numeric_limits<uint32_t>::max() || |
125 num_samples_ >= written); // detect uint32_t overflow | 125 num_samples_ >= written); // detect uint32_t overflow |
| 126 CHECK(CheckWavParameters(num_channels_, |
| 127 sample_rate_, |
| 128 kWavFormat, |
| 129 kBytesPerSample, |
| 130 num_samples_)); |
126 } | 131 } |
127 | 132 |
128 void WavWriter::WriteSamples(const float* samples, size_t num_samples) { | 133 void WavWriter::WriteSamples(const float* samples, size_t num_samples) { |
129 static const size_t kChunksize = 4096 / sizeof(uint16_t); | 134 static const size_t kChunksize = 4096 / sizeof(uint16_t); |
130 for (size_t i = 0; i < num_samples; i += kChunksize) { | 135 for (size_t i = 0; i < num_samples; i += kChunksize) { |
131 int16_t isamples[kChunksize]; | 136 int16_t isamples[kChunksize]; |
132 const size_t chunk = std::min(kChunksize, num_samples - i); | 137 const size_t chunk = std::min(kChunksize, num_samples - i); |
133 FloatS16ToS16(samples + i, chunk, isamples); | 138 FloatS16ToS16(samples + i, chunk, isamples); |
134 WriteSamples(isamples, chunk); | 139 WriteSamples(isamples, chunk); |
135 } | 140 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); | 173 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
169 } | 174 } |
170 | 175 |
171 int rtc_WavNumChannels(const rtc_WavWriter* wf) { | 176 int rtc_WavNumChannels(const rtc_WavWriter* wf) { |
172 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); | 177 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
173 } | 178 } |
174 | 179 |
175 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { | 180 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { |
176 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); | 181 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); |
177 } | 182 } |
OLD | NEW |