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

Side by Side Diff: webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Address review comments Created 3 years, 9 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
(...skipping 24 matching lines...) Expand all
35 0.8608f, 0.8734f, 0.8861f, 0.8987f, 35 0.8608f, 0.8734f, 0.8861f, 0.8987f,
36 0.9114f, 0.9241f, 0.9367f, 0.9494f, 36 0.9114f, 0.9241f, 0.9367f, 0.9494f,
37 0.9620f, 0.9747f, 0.9873f, 1.0000f}; 37 0.9620f, 0.9747f, 0.9873f, 1.0000f};
38 const size_t rampSize = sizeof(rampArray)/sizeof(rampArray[0]); 38 const size_t rampSize = sizeof(rampArray)/sizeof(rampArray[0]);
39 } // namespace 39 } // namespace
40 40
41 namespace webrtc { 41 namespace webrtc {
42 uint32_t CalculateEnergy(const AudioFrame& audioFrame) 42 uint32_t CalculateEnergy(const AudioFrame& audioFrame)
43 { 43 {
44 uint32_t energy = 0; 44 uint32_t energy = 0;
45 for(size_t position = 0; position < audioFrame.samples_per_channel_; 45 if (!audioFrame.muted())
hlundin-webrtc 2017/03/17 14:29:39 I think I would prefer an early return when muted.
yujo 2017/03/17 23:55:54 Done.
46 position++)
47 { 46 {
48 // TODO(andrew): this can easily overflow. 47 const int16_t* frame_data = audioFrame.data();
49 energy += audioFrame.data_[position] * audioFrame.data_[position]; 48 for(size_t position = 0; position < audioFrame.samples_per_channel_;
49 position++)
50 {
51 // TODO(andrew): this can easily overflow.
52 energy += frame_data[position] * frame_data[position];
53 }
50 } 54 }
51 return energy; 55 return energy;
52 } 56 }
53 57
54 void RampIn(AudioFrame& audioFrame) 58 void RampIn(AudioFrame& audioFrame)
55 { 59 {
56 assert(rampSize <= audioFrame.samples_per_channel_); 60 assert(rampSize <= audioFrame.samples_per_channel_);
57 for(size_t i = 0; i < rampSize; i++) 61 if (!audioFrame.muted())
hlundin-webrtc 2017/03/17 14:29:39 Early return.
yujo 2017/03/17 23:55:54 Done.
58 { 62 {
59 audioFrame.data_[i] = static_cast<int16_t>(rampArray[i] * 63 int16_t* frame_data = audioFrame.mutable_data();
60 audioFrame.data_[i]); 64 for(size_t i = 0; i < rampSize; i++)
65 {
66 frame_data[i] = static_cast<int16_t>(rampArray[i] * frame_data[i]);
67 }
61 } 68 }
62 } 69 }
63 70
64 void RampOut(AudioFrame& audioFrame) 71 void RampOut(AudioFrame& audioFrame)
65 { 72 {
66 assert(rampSize <= audioFrame.samples_per_channel_); 73 assert(rampSize <= audioFrame.samples_per_channel_);
67 for(size_t i = 0; i < rampSize; i++) 74 if (!audioFrame.muted())
hlundin-webrtc 2017/03/17 14:29:39 Early return.
yujo 2017/03/17 23:55:54 Done.
68 { 75 {
69 const size_t rampPos = rampSize - 1 - i; 76 int16_t* frame_data = audioFrame.mutable_data();
70 audioFrame.data_[i] = static_cast<int16_t>(rampArray[rampPos] * 77 for(size_t i = 0; i < rampSize; i++)
71 audioFrame.data_[i]); 78 {
79 const size_t rampPos = rampSize - 1 - i;
80 frame_data[i] = static_cast<int16_t>(rampArray[rampPos] *
81 frame_data[i]);
82 }
83 memset(&frame_data[rampSize], 0,
84 (audioFrame.samples_per_channel_ - rampSize) *
85 sizeof(frame_data[0]));
72 } 86 }
73 memset(&audioFrame.data_[rampSize], 0,
74 (audioFrame.samples_per_channel_ - rampSize) *
75 sizeof(audioFrame.data_[0]));
76 } 87 }
77 } // namespace webrtc 88 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698