Index: webrtc/voice_engine/file_recorder.cc |
diff --git a/webrtc/voice_engine/file_recorder.cc b/webrtc/voice_engine/file_recorder.cc |
index 5448451a05bfd9a6bd454e6c6bd5302255b15b6b..eed3c0799a28cbf6171a13835abb961a392965ad 100644 |
--- a/webrtc/voice_engine/file_recorder.cc |
+++ b/webrtc/voice_engine/file_recorder.cc |
@@ -12,6 +12,7 @@ |
#include <list> |
+#include "webrtc/audio/utility/audio_frame_operations.h" |
#include "webrtc/base/logging.h" |
#include "webrtc/base/platform_thread.h" |
#include "webrtc/common_audio/resampler/include/resampler.h" |
@@ -159,12 +160,10 @@ int32_t FileRecorderImpl::RecordAudioToFile( |
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; |
tempAudioFrame.samples_per_channel_ = |
incomingAudioFrame.samples_per_channel_; |
- for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) { |
- // Sample value is the average of left and right buffer rounded to |
- // closest integer value. Note samples can be either 1 or 2 byte. |
- tempAudioFrame.data_[i] = ((incomingAudioFrame.data_[2 * i] + |
- incomingAudioFrame.data_[(2 * i) + 1] + 1) >> |
- 1); |
+ if (!incomingAudioFrame.muted()) { |
+ AudioFrameOperations::StereoToMono( |
+ incomingAudioFrame.data(), incomingAudioFrame.samples_per_channel_, |
+ tempAudioFrame.mutable_data()); |
} |
} else if (incomingAudioFrame.num_channels_ == 1 && _moduleFile->IsStereo()) { |
// Recording stereo but incoming audio is mono. |
@@ -172,10 +171,10 @@ int32_t FileRecorderImpl::RecordAudioToFile( |
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; |
tempAudioFrame.samples_per_channel_ = |
incomingAudioFrame.samples_per_channel_; |
- for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) { |
- // Duplicate sample to both channels |
- tempAudioFrame.data_[2 * i] = incomingAudioFrame.data_[i]; |
- tempAudioFrame.data_[2 * i + 1] = incomingAudioFrame.data_[i]; |
+ if (!incomingAudioFrame.muted()) { |
+ AudioFrameOperations::MonoToStereo( |
+ incomingAudioFrame.data(), incomingAudioFrame.samples_per_channel_, |
+ tempAudioFrame.mutable_data()); |
} |
} |
@@ -204,8 +203,9 @@ int32_t FileRecorderImpl::RecordAudioToFile( |
_audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_, |
codec_info_.plfreq, |
ptrAudioFrame->num_channels_); |
+ // TODO(yujo): skip resample if frame is muted. |
_audioResampler.Push( |
- ptrAudioFrame->data_, |
+ ptrAudioFrame->data(), |
ptrAudioFrame->samples_per_channel_ * ptrAudioFrame->num_channels_, |
reinterpret_cast<int16_t*>(_audioBuffer), MAX_AUDIO_BUFFER_IN_BYTES, |
outLen); |