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

Unified Diff: webrtc/modules/utility/source/audio_frame_operations.cc

Issue 1810413002: Avoid clicks when muting/unmuting a voe::Channel. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/utility/source/audio_frame_operations.cc
diff --git a/webrtc/modules/utility/source/audio_frame_operations.cc b/webrtc/modules/utility/source/audio_frame_operations.cc
index fe09d7972f7fa2dd77fd25708b3e05fefa6b5625..beb5ba6277ca3b19fb28cf54bd8728e10a7677c4 100644
--- a/webrtc/modules/utility/source/audio_frame_operations.cc
+++ b/webrtc/modules/utility/source/audio_frame_operations.cc
@@ -10,8 +10,15 @@
#include "webrtc/modules/include/module_common_types.h"
#include "webrtc/modules/utility/include/audio_frame_operations.h"
+#include "webrtc/base/checks.h"
namespace webrtc {
+namespace {
tlegrand-webrtc 2016/03/23 13:42:41 Is the extra namespace needed?
the sun 2016/03/23 14:25:59 Yes, anything internal to the implementation shoul
+
+// 2.7ms @ 48kHz, 4ms @ 32kHz, 8ms @ 16kHz.
+const size_t kMuteFadeFrames = 128;
+const float kMuteFadeInc = 1.0f / kMuteFadeFrames;
tlegrand-webrtc 2016/03/23 13:42:41 Not sure what the style guide says, but I'd find i
the sun 2016/03/23 14:25:59 Done.
+} // namespace {
void AudioFrameOperations::MonoToStereo(const int16_t* src_audio,
size_t samples_per_channel,
@@ -69,9 +76,48 @@ void AudioFrameOperations::SwapStereoChannels(AudioFrame* frame) {
}
}
-void AudioFrameOperations::Mute(AudioFrame& frame) {
- memset(frame.data_, 0, sizeof(int16_t) *
- frame.samples_per_channel_ * frame.num_channels_);
+void AudioFrameOperations::Mute(AudioFrame* frame, bool start_muted,
peah-webrtc 2016/03/23 15:57:04 I think the naming of start_muted and end_muted ma
peah-webrtc 2016/03/23 15:57:04 Having looked closer at the function, I think it w
peah-webrtc 2016/03/23 15:57:04 Why not split this function in two versions, one c
the sun 2016/03/23 21:30:52 I think it makes sense to keep the logic within on
the sun 2016/03/23 21:30:52 Hmm... "!(!previous_frame_was_muted && !current_fr
the sun 2016/03/23 21:30:53 Good suggestion. Makes the code much easier to rea
peah-webrtc 2016/03/24 07:04:54 I agree with the explosion. But your revised varia
peah-webrtc 2016/03/24 07:04:54 I think that with the parameter name changes that
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
+ bool end_muted) {
tlegrand-webrtc 2016/03/23 13:42:41 It's not super clear what start_muted and end_mute
the sun 2016/03/23 14:25:59 Added in the .h.
+ RTC_DCHECK(frame);
+ if (!start_muted && !end_muted) {
+ // Not muted.
+ } else if (start_muted && end_muted) {
+ // Frame fully muted.
+ memset(frame->data_, 0, sizeof(int16_t) *
peah-webrtc 2016/03/23 15:57:04 Since you know the size of data in this case (it i
peah-webrtc 2016/03/23 15:57:04 I would prefer the sizeof to be done on frame->dat
the sun 2016/03/23 21:30:52 Yes, I blame copy+paste from the old version. :)
the sun 2016/03/23 21:30:52 Good idea! Done.
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
+ frame->samples_per_channel_ * frame->num_channels_);
+ } else {
+ // Limit number of samples to fade, if frame isn't long enough.
+ size_t count = kMuteFadeFrames;
+ float inc = kMuteFadeInc;
+ if (frame->samples_per_channel_ < kMuteFadeFrames) {
peah-webrtc 2016/03/23 15:57:04 If frame->samples_per_channel_ == 0 is treated as
the sun 2016/03/23 21:30:52 No, we still need to do the division in case we ha
peah-webrtc 2016/03/24 07:04:54 Yes, I agree. I looked at it a bit broader though
the sun 2016/03/24 09:33:15 What I'd REALLY like to do instead is to send arou
+ count = frame->samples_per_channel_;
+ if (count > 0) {
peah-webrtc 2016/03/23 15:57:04 This should always be true, right? Afaics count ==
the sun 2016/03/23 21:30:52 There's nothing in AudioFrame that prevents it fro
peah-webrtc 2016/03/24 07:04:54 True, but you anyway need to do that check for the
the sun 2016/03/24 09:33:15 Yes, but that is not the common case.
+ inc = 1.0f / count;
peah-webrtc 2016/03/23 15:57:04 How common is it that frame->samples_per_channel_
the sun 2016/03/23 21:30:53 Given that we usually store 10ms of data (though w
peah-webrtc 2016/03/24 07:04:54 Would it be possible to reduce the fading time to
the sun 2016/03/24 09:33:15 That would be nice, but AudioFrame doesn't give us
+ }
+ }
+
+ // Ramp up the first N samples of frame.
tlegrand-webrtc 2016/03/23 13:42:41 N-> "count", or? The comment should probably ment
the sun 2016/03/23 14:25:59 Done.
+ size_t start = 0;
+ float g = 0.0f;
+ if (!start_muted && end_muted) {
+ // Ramp down the last N samples of frame.
+ start = frame->samples_per_channel_ - count;
+ g = 1.0f;
+ inc = -inc;
+ } else {
+ RTC_DCHECK(start_muted && !end_muted);
peah-webrtc 2016/03/23 15:57:04 Why do you assert on this? Should it not be allowe
the sun 2016/03/23 21:30:52 Good call, I've simplified the logic a bit. This a
+ }
+
peah-webrtc 2016/03/23 15:57:04 If you change the code so that you in this block k
the sun 2016/03/23 21:30:52 You leave out the check for frame->samples_per_cha
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
+ // Perform fade.
+ const size_t end = (start + count);
peah-webrtc 2016/03/23 15:57:04 This should always be start = frame->samples_per_c
the sun 2016/03/23 21:30:52 end will be 'count' or 'frame->samples_per_channel
peah-webrtc 2016/03/24 07:04:54 True, it feels a bit backward though to recompute
the sun 2016/03/24 09:33:15 You're right, the code is nicer if I just set up e
+ const size_t channels = frame->num_channels_;
+ for (size_t i = start * channels; i < end * channels; i += channels) {
+ g += inc;
peah-webrtc 2016/03/23 15:57:04 You should ideally bound the gain to 0<=g<=1 using
the sun 2016/03/23 21:30:52 No, it is designed to never shoot outside, and the
peah-webrtc 2016/03/24 07:04:54 Acknowledged.
+ for (size_t j = 0; j < channels; ++j) {
+ frame->data_[i + j] = static_cast<int16_t>(g * frame->data_[i + j]);
+ }
peah-webrtc 2016/03/23 15:57:04 Since the number of channels typically is much sma
the sun 2016/03/23 21:30:52 I think that is evil to caches. For a 320 sample s
peah-webrtc 2016/03/24 07:04:54 Great find! We should probably deprecated that API
the sun 2016/03/24 09:33:15 https://codereview.webrtc.org/1830713003/
+ }
+ }
}
int AudioFrameOperations::Scale(float left, float right, AudioFrame& frame) {

Powered by Google App Engine
This is Rietveld 408576698