Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: webrtc/modules/audio_mixer/audio_frame_manipulator.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_mixer/audio_frame_manipulator.cc
diff --git a/webrtc/modules/audio_mixer/audio_frame_manipulator.cc b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc
index 8aa0b5ce02dc35c6bd3a9d4a90de48ca82f015d8..fff79a38cf6b4e68f13e30c43a56e31a49dd1efc 100644
--- a/webrtc/modules/audio_mixer/audio_frame_manipulator.cc
+++ b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc
@@ -16,11 +16,16 @@
namespace webrtc {
uint32_t AudioMixerCalculateEnergy(const AudioFrame& audio_frame) {
+ if (audio_frame.muted()) {
+ return 0;
+ }
+
uint32_t energy = 0;
+ const int16_t* frame_data = audio_frame.data();
for (size_t position = 0; position < audio_frame.samples_per_channel_;
position++) {
// TODO(aleloi): This can overflow. Convert to floats.
- energy += audio_frame.data_[position] * audio_frame.data_[position];
+ energy += frame_data[position] * frame_data[position];
}
return energy;
}
@@ -29,7 +34,7 @@ void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) {
RTC_DCHECK(audio_frame);
RTC_DCHECK_GE(start_gain, 0.0f);
RTC_DCHECK_GE(target_gain, 0.0f);
- if (start_gain == target_gain) {
+ if (start_gain == target_gain || audio_frame->muted()) {
return;
}
@@ -37,11 +42,12 @@ void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) {
RTC_DCHECK_LT(0, samples);
float increment = (target_gain - start_gain) / samples;
float gain = start_gain;
+ int16_t* frame_data = audio_frame->mutable_data();
for (size_t i = 0; i < samples; ++i) {
// If the audio is interleaved of several channels, we want to
// apply the same gain change to the ith sample of every channel.
for (size_t ch = 0; ch < audio_frame->num_channels_; ++ch) {
- audio_frame->data_[audio_frame->num_channels_ * i + ch] *= gain;
+ frame_data[audio_frame->num_channels_ * i + ch] *= gain;
}
gain += increment;
}

Powered by Google App Engine
This is Rietveld 408576698