OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 void PCMFile::Write10MsData(AudioFrame& audio_frame) { | 143 void PCMFile::Write10MsData(AudioFrame& audio_frame) { |
144 if (audio_frame.num_channels_ == 1) { | 144 if (audio_frame.num_channels_ == 1) { |
145 if (!save_stereo_) { | 145 if (!save_stereo_) { |
146 if (fwrite(audio_frame.data_, sizeof(uint16_t), | 146 if (fwrite(audio_frame.data_, sizeof(uint16_t), |
147 audio_frame.samples_per_channel_, pcm_file_) != | 147 audio_frame.samples_per_channel_, pcm_file_) != |
148 static_cast<size_t>(audio_frame.samples_per_channel_)) { | 148 static_cast<size_t>(audio_frame.samples_per_channel_)) { |
149 return; | 149 return; |
150 } | 150 } |
151 } else { | 151 } else { |
152 int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_]; | 152 int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_]; |
153 for (int k = 0; k < audio_frame.samples_per_channel_; k++) { | 153 for (size_t k = 0; k < audio_frame.samples_per_channel_; k++) { |
154 stereo_audio[k << 1] = audio_frame.data_[k]; | 154 stereo_audio[k << 1] = audio_frame.data_[k]; |
155 stereo_audio[(k << 1) + 1] = audio_frame.data_[k]; | 155 stereo_audio[(k << 1) + 1] = audio_frame.data_[k]; |
156 } | 156 } |
157 if (fwrite(stereo_audio, sizeof(int16_t), | 157 if (fwrite(stereo_audio, sizeof(int16_t), |
158 2 * audio_frame.samples_per_channel_, pcm_file_) != | 158 2 * audio_frame.samples_per_channel_, pcm_file_) != |
159 static_cast<size_t>(2 * audio_frame.samples_per_channel_)) { | 159 static_cast<size_t>(2 * audio_frame.samples_per_channel_)) { |
160 return; | 160 return; |
161 } | 161 } |
162 delete[] stereo_audio; | 162 delete[] stereo_audio; |
163 } | 163 } |
164 } else { | 164 } else { |
165 if (fwrite(audio_frame.data_, sizeof(int16_t), | 165 if (fwrite(audio_frame.data_, sizeof(int16_t), |
166 audio_frame.num_channels_ * audio_frame.samples_per_channel_, | 166 audio_frame.num_channels_ * audio_frame.samples_per_channel_, |
167 pcm_file_) != | 167 pcm_file_) != |
168 static_cast<size_t>(audio_frame.num_channels_ * | 168 static_cast<size_t>(audio_frame.num_channels_ * |
169 audio_frame.samples_per_channel_)) { | 169 audio_frame.samples_per_channel_)) { |
170 return; | 170 return; |
171 } | 171 } |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void PCMFile::Write10MsData(int16_t* playout_buffer, uint16_t length_smpls) { | 175 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) { |
176 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) != | 176 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) != |
177 length_smpls) { | 177 length_smpls) { |
178 return; | 178 return; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void PCMFile::Close() { | 182 void PCMFile::Close() { |
183 fclose(pcm_file_); | 183 fclose(pcm_file_); |
184 pcm_file_ = NULL; | 184 pcm_file_ = NULL; |
185 } | 185 } |
186 | 186 |
187 void PCMFile::Rewind() { | 187 void PCMFile::Rewind() { |
188 rewind(pcm_file_); | 188 rewind(pcm_file_); |
189 end_of_file_ = false; | 189 end_of_file_ = false; |
190 } | 190 } |
191 | 191 |
192 bool PCMFile::Rewinded() { | 192 bool PCMFile::Rewinded() { |
193 return rewinded_; | 193 return rewinded_; |
194 } | 194 } |
195 | 195 |
196 void PCMFile::SaveStereo(bool is_stereo) { | 196 void PCMFile::SaveStereo(bool is_stereo) { |
197 save_stereo_ = is_stereo; | 197 save_stereo_ = is_stereo; |
198 } | 198 } |
199 | 199 |
200 void PCMFile::ReadStereo(bool is_stereo) { | 200 void PCMFile::ReadStereo(bool is_stereo) { |
201 read_stereo_ = is_stereo; | 201 read_stereo_ = is_stereo; |
202 } | 202 } |
203 | 203 |
204 } // namespace webrtc | 204 } // namespace webrtc |
OLD | NEW |