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_)); | |
131 } | 126 } |
132 | 127 |
133 void WavWriter::WriteSamples(const float* samples, size_t num_samples) { | 128 void WavWriter::WriteSamples(const float* samples, size_t num_samples) { |
134 static const size_t kChunksize = 4096 / sizeof(uint16_t); | 129 static const size_t kChunksize = 4096 / sizeof(uint16_t); |
135 for (size_t i = 0; i < num_samples; i += kChunksize) { | 130 for (size_t i = 0; i < num_samples; i += kChunksize) { |
136 int16_t isamples[kChunksize]; | 131 int16_t isamples[kChunksize]; |
137 const size_t chunk = std::min(kChunksize, num_samples - i); | 132 const size_t chunk = std::min(kChunksize, num_samples - i); |
138 FloatS16ToS16(samples + i, chunk, isamples); | 133 FloatS16ToS16(samples + i, chunk, isamples); |
139 WriteSamples(isamples, chunk); | 134 WriteSamples(isamples, chunk); |
140 } | 135 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); | 168 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
174 } | 169 } |
175 | 170 |
176 int rtc_WavNumChannels(const rtc_WavWriter* wf) { | 171 int rtc_WavNumChannels(const rtc_WavWriter* wf) { |
177 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); | 172 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
178 } | 173 } |
179 | 174 |
180 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { | 175 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { |
181 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); | 176 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); |
182 } | 177 } |
OLD | NEW |