| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 AudioFrame tempAudioFrame; | 149 AudioFrame tempAudioFrame; |
| 150 tempAudioFrame.samples_per_channel_ = 0; | 150 tempAudioFrame.samples_per_channel_ = 0; |
| 151 if( incomingAudioFrame.num_channels_ == 2 && | 151 if( incomingAudioFrame.num_channels_ == 2 && |
| 152 !_moduleFile->IsStereo()) | 152 !_moduleFile->IsStereo()) |
| 153 { | 153 { |
| 154 // Recording mono but incoming audio is (interleaved) stereo. | 154 // Recording mono but incoming audio is (interleaved) stereo. |
| 155 tempAudioFrame.num_channels_ = 1; | 155 tempAudioFrame.num_channels_ = 1; |
| 156 tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; | 156 tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; |
| 157 tempAudioFrame.samples_per_channel_ = | 157 tempAudioFrame.samples_per_channel_ = |
| 158 incomingAudioFrame.samples_per_channel_; | 158 incomingAudioFrame.samples_per_channel_; |
| 159 for (uint16_t i = 0; | 159 for (size_t i = 0; |
| 160 i < (incomingAudioFrame.samples_per_channel_); i++) | 160 i < (incomingAudioFrame.samples_per_channel_); i++) |
| 161 { | 161 { |
| 162 // Sample value is the average of left and right buffer rounded to | 162 // Sample value is the average of left and right buffer rounded to |
| 163 // closest integer value. Note samples can be either 1 or 2 byte. | 163 // closest integer value. Note samples can be either 1 or 2 byte. |
| 164 tempAudioFrame.data_[i] = | 164 tempAudioFrame.data_[i] = |
| 165 ((incomingAudioFrame.data_[2 * i] + | 165 ((incomingAudioFrame.data_[2 * i] + |
| 166 incomingAudioFrame.data_[(2 * i) + 1] + 1) >> 1); | 166 incomingAudioFrame.data_[(2 * i) + 1] + 1) >> 1); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 else if( incomingAudioFrame.num_channels_ == 1 && | 169 else if( incomingAudioFrame.num_channels_ == 1 && |
| 170 _moduleFile->IsStereo()) | 170 _moduleFile->IsStereo()) |
| 171 { | 171 { |
| 172 // Recording stereo but incoming audio is mono. | 172 // Recording stereo but incoming audio is mono. |
| 173 tempAudioFrame.num_channels_ = 2; | 173 tempAudioFrame.num_channels_ = 2; |
| 174 tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; | 174 tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; |
| 175 tempAudioFrame.samples_per_channel_ = | 175 tempAudioFrame.samples_per_channel_ = |
| 176 incomingAudioFrame.samples_per_channel_; | 176 incomingAudioFrame.samples_per_channel_; |
| 177 for (uint16_t i = 0; | 177 for (size_t i = 0; |
| 178 i < (incomingAudioFrame.samples_per_channel_); i++) | 178 i < (incomingAudioFrame.samples_per_channel_); i++) |
| 179 { | 179 { |
| 180 // Duplicate sample to both channels | 180 // Duplicate sample to both channels |
| 181 tempAudioFrame.data_[2*i] = | 181 tempAudioFrame.data_[2*i] = |
| 182 incomingAudioFrame.data_[i]; | 182 incomingAudioFrame.data_[i]; |
| 183 tempAudioFrame.data_[2*i+1] = | 183 tempAudioFrame.data_[2*i+1] = |
| 184 incomingAudioFrame.data_[i]; | 184 incomingAudioFrame.data_[i]; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 203 { | 203 { |
| 204 if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer, | 204 if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer, |
| 205 encodedLenInBytes) == -1) | 205 encodedLenInBytes) == -1) |
| 206 { | 206 { |
| 207 LOG(LS_WARNING) << "RecordAudioToFile() codec " | 207 LOG(LS_WARNING) << "RecordAudioToFile() codec " |
| 208 << codec_info_.plname | 208 << codec_info_.plname |
| 209 << " not supported or failed to encode stream."; | 209 << " not supported or failed to encode stream."; |
| 210 return -1; | 210 return -1; |
| 211 } | 211 } |
| 212 } else { | 212 } else { |
| 213 int outLen = 0; | 213 size_t outLen = 0; |
| 214 _audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_, | 214 _audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_, |
| 215 codec_info_.plfreq, | 215 codec_info_.plfreq, |
| 216 ptrAudioFrame->num_channels_); | 216 ptrAudioFrame->num_channels_); |
| 217 _audioResampler.Push(ptrAudioFrame->data_, | 217 _audioResampler.Push(ptrAudioFrame->data_, |
| 218 ptrAudioFrame->samples_per_channel_ * | 218 ptrAudioFrame->samples_per_channel_ * |
| 219 ptrAudioFrame->num_channels_, | 219 ptrAudioFrame->num_channels_, |
| 220 (int16_t*)_audioBuffer, | 220 (int16_t*)_audioBuffer, |
| 221 MAX_AUDIO_BUFFER_IN_BYTES, outLen); | 221 MAX_AUDIO_BUFFER_IN_BYTES, outLen); |
| 222 encodedLenInBytes = outLen * sizeof(int16_t); | 222 encodedLenInBytes = outLen * sizeof(int16_t); |
| 223 } | 223 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 codecInst = codec_info_; | 259 codecInst = codec_info_; |
| 260 return 0; | 260 return 0; |
| 261 } | 261 } |
| 262 | 262 |
| 263 int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer, | 263 int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer, |
| 264 size_t bufferLength) | 264 size_t bufferLength) |
| 265 { | 265 { |
| 266 return _moduleFile->IncomingAudioData(audioBuffer, bufferLength); | 266 return _moduleFile->IncomingAudioData(audioBuffer, bufferLength); |
| 267 } | 267 } |
| 268 } // namespace webrtc | 268 } // namespace webrtc |
| OLD | NEW |