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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 return read; | 93 return read; |
94 } | 94 } |
95 | 95 |
96 void WavReader::Close() { | 96 void WavReader::Close() { |
97 RTC_CHECK_EQ(0, fclose(file_handle_)); | 97 RTC_CHECK_EQ(0, fclose(file_handle_)); |
98 file_handle_ = NULL; | 98 file_handle_ = NULL; |
99 } | 99 } |
100 | 100 |
101 WavWriter::WavWriter(const std::string& filename, int sample_rate, | 101 WavWriter::WavWriter(const std::string& filename, int sample_rate, |
102 int num_channels) | 102 size_t num_channels) |
103 : sample_rate_(sample_rate), | 103 : sample_rate_(sample_rate), |
104 num_channels_(num_channels), | 104 num_channels_(num_channels), |
105 num_samples_(0), | 105 num_samples_(0), |
106 file_handle_(fopen(filename.c_str(), "wb")) { | 106 file_handle_(fopen(filename.c_str(), "wb")) { |
107 RTC_CHECK(file_handle_) << "Could not open wav file for writing."; | 107 RTC_CHECK(file_handle_) << "Could not open wav file for writing."; |
108 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, | 108 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, |
109 kBytesPerSample, num_samples_)); | 109 kBytesPerSample, num_samples_)); |
110 | 110 |
111 // Write a blank placeholder header, since we need to know the total number | 111 // Write a blank placeholder header, since we need to know the total number |
112 // of samples before we can fill in the real data. | 112 // of samples before we can fill in the real data. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 kBytesPerSample, num_samples_); | 146 kBytesPerSample, num_samples_); |
147 RTC_CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_)); | 147 RTC_CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_)); |
148 RTC_CHECK_EQ(0, fclose(file_handle_)); | 148 RTC_CHECK_EQ(0, fclose(file_handle_)); |
149 file_handle_ = NULL; | 149 file_handle_ = NULL; |
150 } | 150 } |
151 | 151 |
152 } // namespace webrtc | 152 } // namespace webrtc |
153 | 153 |
154 rtc_WavWriter* rtc_WavOpen(const char* filename, | 154 rtc_WavWriter* rtc_WavOpen(const char* filename, |
155 int sample_rate, | 155 int sample_rate, |
156 int num_channels) { | 156 size_t num_channels) { |
157 return reinterpret_cast<rtc_WavWriter*>( | 157 return reinterpret_cast<rtc_WavWriter*>( |
158 new webrtc::WavWriter(filename, sample_rate, num_channels)); | 158 new webrtc::WavWriter(filename, sample_rate, num_channels)); |
159 } | 159 } |
160 | 160 |
161 void rtc_WavClose(rtc_WavWriter* wf) { | 161 void rtc_WavClose(rtc_WavWriter* wf) { |
162 delete reinterpret_cast<webrtc::WavWriter*>(wf); | 162 delete reinterpret_cast<webrtc::WavWriter*>(wf); |
163 } | 163 } |
164 | 164 |
165 void rtc_WavWriteSamples(rtc_WavWriter* wf, | 165 void rtc_WavWriteSamples(rtc_WavWriter* wf, |
166 const float* samples, | 166 const float* samples, |
167 size_t num_samples) { | 167 size_t num_samples) { |
168 reinterpret_cast<webrtc::WavWriter*>(wf)->WriteSamples(samples, num_samples); | 168 reinterpret_cast<webrtc::WavWriter*>(wf)->WriteSamples(samples, num_samples); |
169 } | 169 } |
170 | 170 |
171 int rtc_WavSampleRate(const rtc_WavWriter* wf) { | 171 int rtc_WavSampleRate(const rtc_WavWriter* wf) { |
172 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); | 172 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
173 } | 173 } |
174 | 174 |
175 int rtc_WavNumChannels(const rtc_WavWriter* wf) { | 175 size_t rtc_WavNumChannels(const rtc_WavWriter* wf) { |
176 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); | 176 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
177 } | 177 } |
178 | 178 |
179 size_t rtc_WavNumSamples(const rtc_WavWriter* wf) { | 179 size_t rtc_WavNumSamples(const rtc_WavWriter* wf) { |
180 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); | 180 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); |
181 } | 181 } |
OLD | NEW |