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 11 matching lines...) Expand all Loading... | |
22 // TODO(aleloi): This can overflow. Convert to floats. | 22 // TODO(aleloi): This can overflow. Convert to floats. |
23 energy += audio_frame.data_[position] * audio_frame.data_[position]; | 23 energy += audio_frame.data_[position] * audio_frame.data_[position]; |
24 } | 24 } |
25 return energy; | 25 return energy; |
26 } | 26 } |
27 | 27 |
28 void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) { | 28 void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) { |
29 RTC_DCHECK(audio_frame); | 29 RTC_DCHECK(audio_frame); |
30 RTC_DCHECK_GE(start_gain, 0.0f); | 30 RTC_DCHECK_GE(start_gain, 0.0f); |
31 RTC_DCHECK_GE(target_gain, 0.0f); | 31 RTC_DCHECK_GE(target_gain, 0.0f); |
32 if (start_gain == target_gain) { | |
the sun
2017/02/07 08:53:22
Comparing floats is fuzzy and operator == is not t
hlundin-webrtc
2017/02/07 21:34:51
No, I know of no such function in our codebase.
| |
33 return; | |
34 } | |
32 | 35 |
33 size_t samples = audio_frame->samples_per_channel_; | 36 size_t samples = audio_frame->samples_per_channel_; |
34 RTC_DCHECK_LT(0, samples); | 37 RTC_DCHECK_LT(0, samples); |
35 float increment = (target_gain - start_gain) / samples; | 38 float increment = (target_gain - start_gain) / samples; |
36 float gain = start_gain; | 39 float gain = start_gain; |
37 for (size_t i = 0; i < samples; ++i) { | 40 for (size_t i = 0; i < samples; ++i) { |
38 // If the audio is interleaved of several channels, we want to | 41 // If the audio is interleaved of several channels, we want to |
39 // apply the same gain change to the ith sample of every channel. | 42 // apply the same gain change to the ith sample of every channel. |
40 for (size_t ch = 0; ch < audio_frame->num_channels_; ++ch) { | 43 for (size_t ch = 0; ch < audio_frame->num_channels_; ++ch) { |
41 audio_frame->data_[audio_frame->num_channels_ * i + ch] *= gain; | 44 audio_frame->data_[audio_frame->num_channels_ * i + ch] *= gain; |
42 } | 45 } |
43 gain += increment; | 46 gain += increment; |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) { | 50 void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) { |
48 RTC_DCHECK_GE(target_number_of_channels, 1); | 51 RTC_DCHECK_GE(target_number_of_channels, 1); |
49 RTC_DCHECK_LE(target_number_of_channels, 2); | 52 RTC_DCHECK_LE(target_number_of_channels, 2); |
50 if (frame->num_channels_ == 1 && target_number_of_channels == 2) { | 53 if (frame->num_channels_ == 1 && target_number_of_channels == 2) { |
51 AudioFrameOperations::MonoToStereo(frame); | 54 AudioFrameOperations::MonoToStereo(frame); |
52 } else if (frame->num_channels_ == 2 && target_number_of_channels == 1) { | 55 } else if (frame->num_channels_ == 2 && target_number_of_channels == 1) { |
53 AudioFrameOperations::StereoToMono(frame); | 56 AudioFrameOperations::StereoToMono(frame); |
54 } | 57 } |
55 } | 58 } |
56 } // namespace webrtc | 59 } // namespace webrtc |
OLD | NEW |