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 num_channels_(num_channels), | 116 num_channels_(num_channels), |
117 num_samples_(0), | 117 num_samples_(0), |
118 file_handle_(fopen(filename.c_str(), "wb")) { | 118 file_handle_(fopen(filename.c_str(), "wb")) { |
119 RTC_CHECK(file_handle_) << "Could not open wav file for writing."; | 119 RTC_CHECK(file_handle_) << "Could not open wav file for writing."; |
120 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, | 120 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, |
121 kBytesPerSample, num_samples_)); | 121 kBytesPerSample, num_samples_)); |
122 | 122 |
123 // Write a blank placeholder header, since we need to know the total number | 123 // Write a blank placeholder header, since we need to know the total number |
124 // of samples before we can fill in the real data. | 124 // of samples before we can fill in the real data. |
125 static const uint8_t blank_header[kWavHeaderSize] = {0}; | 125 static const uint8_t blank_header[kWavHeaderSize] = {0}; |
126 RTC_CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_)); | 126 RTC_CHECK_EQ(1, fwrite(blank_header, kWavHeaderSize, 1, file_handle_)); |
127 } | 127 } |
128 | 128 |
129 WavWriter::~WavWriter() { | 129 WavWriter::~WavWriter() { |
130 Close(); | 130 Close(); |
131 } | 131 } |
132 | 132 |
133 int WavWriter::sample_rate() const { | 133 int WavWriter::sample_rate() const { |
134 return sample_rate_; | 134 return sample_rate_; |
135 } | 135 } |
136 | 136 |
(...skipping 24 matching lines...) Expand all Loading... |
161 FloatS16ToS16(samples + i, chunk, isamples); | 161 FloatS16ToS16(samples + i, chunk, isamples); |
162 WriteSamples(isamples, chunk); | 162 WriteSamples(isamples, chunk); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 void WavWriter::Close() { | 166 void WavWriter::Close() { |
167 RTC_CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET)); | 167 RTC_CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET)); |
168 uint8_t header[kWavHeaderSize]; | 168 uint8_t header[kWavHeaderSize]; |
169 WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat, | 169 WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat, |
170 kBytesPerSample, num_samples_); | 170 kBytesPerSample, num_samples_); |
171 RTC_CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_)); | 171 RTC_CHECK_EQ(1, fwrite(header, kWavHeaderSize, 1, file_handle_)); |
172 RTC_CHECK_EQ(0, fclose(file_handle_)); | 172 RTC_CHECK_EQ(0, fclose(file_handle_)); |
173 file_handle_ = NULL; | 173 file_handle_ = NULL; |
174 } | 174 } |
175 | 175 |
176 } // namespace webrtc | 176 } // namespace webrtc |
177 | 177 |
178 rtc_WavWriter* rtc_WavOpen(const char* filename, | 178 rtc_WavWriter* rtc_WavOpen(const char* filename, |
179 int sample_rate, | 179 int sample_rate, |
180 size_t num_channels) { | 180 size_t num_channels) { |
181 return reinterpret_cast<rtc_WavWriter*>( | 181 return reinterpret_cast<rtc_WavWriter*>( |
(...skipping 14 matching lines...) Expand all Loading... |
196 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); | 196 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
197 } | 197 } |
198 | 198 |
199 size_t rtc_WavNumChannels(const rtc_WavWriter* wf) { | 199 size_t rtc_WavNumChannels(const rtc_WavWriter* wf) { |
200 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); | 200 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
201 } | 201 } |
202 | 202 |
203 size_t rtc_WavNumSamples(const rtc_WavWriter* wf) { | 203 size_t rtc_WavNumSamples(const rtc_WavWriter* wf) { |
204 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); | 204 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); |
205 } | 205 } |
OLD | NEW |