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

Side by Side 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 unified diff | Download patch
OLDNEW
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
11 #include "webrtc/audio/utility/audio_frame_operations.h" 11 #include "webrtc/audio/utility/audio_frame_operations.h"
12 #include "webrtc/base/checks.h" 12 #include "webrtc/base/checks.h"
13 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" 13 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h"
14 #include "webrtc/modules/include/module_common_types.h" 14 #include "webrtc/modules/include/module_common_types.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 17
18 uint32_t AudioMixerCalculateEnergy(const AudioFrame& audio_frame) { 18 uint32_t AudioMixerCalculateEnergy(const AudioFrame& audio_frame) {
19 if (audio_frame.muted()) {
20 return 0;
21 }
22
19 uint32_t energy = 0; 23 uint32_t energy = 0;
24 const int16_t* frame_data = audio_frame.data();
20 for (size_t position = 0; position < audio_frame.samples_per_channel_; 25 for (size_t position = 0; position < audio_frame.samples_per_channel_;
21 position++) { 26 position++) {
22 // TODO(aleloi): This can overflow. Convert to floats. 27 // TODO(aleloi): This can overflow. Convert to floats.
23 energy += audio_frame.data_[position] * audio_frame.data_[position]; 28 energy += frame_data[position] * frame_data[position];
24 } 29 }
25 return energy; 30 return energy;
26 } 31 }
27 32
28 void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) { 33 void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) {
29 RTC_DCHECK(audio_frame); 34 RTC_DCHECK(audio_frame);
30 RTC_DCHECK_GE(start_gain, 0.0f); 35 RTC_DCHECK_GE(start_gain, 0.0f);
31 RTC_DCHECK_GE(target_gain, 0.0f); 36 RTC_DCHECK_GE(target_gain, 0.0f);
32 if (start_gain == target_gain) { 37 if (start_gain == target_gain || audio_frame->muted()) {
33 return; 38 return;
34 } 39 }
35 40
36 size_t samples = audio_frame->samples_per_channel_; 41 size_t samples = audio_frame->samples_per_channel_;
37 RTC_DCHECK_LT(0, samples); 42 RTC_DCHECK_LT(0, samples);
38 float increment = (target_gain - start_gain) / samples; 43 float increment = (target_gain - start_gain) / samples;
39 float gain = start_gain; 44 float gain = start_gain;
45 int16_t* frame_data = audio_frame->mutable_data();
40 for (size_t i = 0; i < samples; ++i) { 46 for (size_t i = 0; i < samples; ++i) {
41 // If the audio is interleaved of several channels, we want to 47 // If the audio is interleaved of several channels, we want to
42 // apply the same gain change to the ith sample of every channel. 48 // apply the same gain change to the ith sample of every channel.
43 for (size_t ch = 0; ch < audio_frame->num_channels_; ++ch) { 49 for (size_t ch = 0; ch < audio_frame->num_channels_; ++ch) {
44 audio_frame->data_[audio_frame->num_channels_ * i + ch] *= gain; 50 frame_data[audio_frame->num_channels_ * i + ch] *= gain;
45 } 51 }
46 gain += increment; 52 gain += increment;
47 } 53 }
48 } 54 }
49 55
50 void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) { 56 void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) {
51 RTC_DCHECK_GE(target_number_of_channels, 1); 57 RTC_DCHECK_GE(target_number_of_channels, 1);
52 RTC_DCHECK_LE(target_number_of_channels, 2); 58 RTC_DCHECK_LE(target_number_of_channels, 2);
53 if (frame->num_channels_ == 1 && target_number_of_channels == 2) { 59 if (frame->num_channels_ == 1 && target_number_of_channels == 2) {
54 AudioFrameOperations::MonoToStereo(frame); 60 AudioFrameOperations::MonoToStereo(frame);
55 } else if (frame->num_channels_ == 2 && target_number_of_channels == 1) { 61 } else if (frame->num_channels_ == 2 && target_number_of_channels == 1) {
56 AudioFrameOperations::StereoToMono(frame); 62 AudioFrameOperations::StereoToMono(frame);
57 } 63 }
58 } 64 }
59 } // namespace webrtc 65 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698