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

Unified Diff: chromecast/media/cma/backend/alsa/slew_volume.cc

Issue 2860673003: [Chromecast] Correct libcast_governor behavior. (Closed)
Patch Set: Remove debug logging Created 3 years, 8 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: chromecast/media/cma/backend/alsa/slew_volume.cc
diff --git a/chromecast/media/cma/backend/alsa/slew_volume.cc b/chromecast/media/cma/backend/alsa/slew_volume.cc
index 38ce1a72a186e43f64ebc3b301fb627e2013a2e2..0e6f2f70fdb67c5302f923b4066520e48a4c307c 100644
--- a/chromecast/media/cma/backend/alsa/slew_volume.cc
+++ b/chromecast/media/cma/backend/alsa/slew_volume.cc
@@ -14,7 +14,8 @@ namespace {
// The time to slew from current volume to target volume.
const int kMaxSlewTimeMs = 100;
const int kDefaultSampleRate = 44100;
-}
+
+} // namespace
namespace chromecast {
namespace media {
@@ -24,9 +25,7 @@ SlewVolume::SlewVolume() : SlewVolume(kMaxSlewTimeMs) {}
SlewVolume::SlewVolume(int max_slew_time_ms)
: sample_rate_(kDefaultSampleRate),
max_slew_time_ms_(max_slew_time_ms),
- max_slew_per_sample_(1000.0 / (max_slew_time_ms_ * sample_rate_)) {
- LOG(INFO) << "Creating a slew volume: " << max_slew_time_ms;
-}
+ max_slew_per_sample_(1000.0 / (max_slew_time_ms_ * sample_rate_)) {}
void SlewVolume::SetSampleRate(int sample_rate) {
sample_rate_ = sample_rate;
@@ -49,6 +48,8 @@ void SlewVolume::SetVolume(double volume_scale) {
}
void SlewVolume::SetMaxSlewTimeMs(int max_slew_time_ms) {
+ DCHECK_GE(max_slew_time_ms, 0);
+
max_slew_time_ms_ = max_slew_time_ms;
}
@@ -86,7 +87,10 @@ void SlewVolume::ProcessFMAC(bool repeat_transition,
}
::media::vector_math::FMAC(src, current_volume_, frames, dest);
return;
- } else if (current_volume_ < volume_scale_) {
+ }
+
+ int original_frames = frames;
+ if (current_volume_ < volume_scale_) {
do {
(*dest) += (*src) * current_volume_;
++src;
@@ -106,10 +110,78 @@ void SlewVolume::ProcessFMAC(bool repeat_transition,
current_volume_ = std::max(current_volume_, volume_scale_);
}
+ while (frames && ((original_frames - frames) % 4) != 0) {
bcf 2017/05/03 06:14:07 I think this would be more explict as: while (fra
bshaya 2017/05/03 16:51:56 Done.
bcf 2017/05/03 18:07:09 This LGTM, but FYI the compiler will realize kRequ
bshaya 2017/05/04 03:01:18 That's fine. This is the same code that vector_mat
+ (*dest) += (*src) * current_volume_;
+ ++src;
+ ++dest;
+ --frames;
+ }
if (frames) {
- for (int f = 0; f < frames; ++f) {
- dest[f] += src[f] * current_volume_;
+ ::media::vector_math::FMAC(src, current_volume_, frames, dest);
+ }
+}
+
+void SlewVolume::ProcessFMUL(bool repeat_transition,
+ const float* src,
+ int frames,
+ float* dest) {
+ DCHECK(src);
+ DCHECK(dest);
+ // Ensure |src| and |dest| are 16-byte aligned.
+ DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) &
+ (::media::vector_math::kRequiredAlignment - 1));
+ DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) &
+ (::media::vector_math::kRequiredAlignment - 1));
+
+ if (!frames) {
+ return;
+ }
+
+ interrupted_ = false;
+ if (repeat_transition) {
+ current_volume_ = last_starting_volume_;
+ } else {
+ last_starting_volume_ = current_volume_;
+ }
+
+ if (current_volume_ == volume_scale_) {
+ if (current_volume_ == 0.0) {
+ memset(dest, 0, frames * sizeof(*dest));
bcf 2017/05/03 06:14:07 return after this?
bshaya 2017/05/03 16:51:56 Done.
}
+ ::media::vector_math::FMUL(src, current_volume_, frames, dest);
+ return;
+ }
+
+ int original_frames = frames;
+ if (current_volume_ < volume_scale_) {
+ do {
+ (*dest) = (*src) * current_volume_;
+ ++src;
+ ++dest;
+ --frames;
+ current_volume_ += max_slew_per_sample_;
+ } while (current_volume_ < volume_scale_ && frames);
+ current_volume_ = std::min(current_volume_, volume_scale_);
+ } else { // current_volume_ > volume_scale_
+ do {
+ (*dest) = (*src) * current_volume_;
+ ++src;
+ ++dest;
+ --frames;
+ current_volume_ -= max_slew_per_sample_;
+ } while (current_volume_ > volume_scale_ && frames);
+ current_volume_ = std::max(current_volume_, volume_scale_);
+ }
+
+ // Re-align to 16 bytes.
+ while (frames && ((original_frames - frames) % 4) != 0) {
bcf 2017/05/03 06:14:07 ditto. Also the statement becomes self documenting
bshaya 2017/05/03 16:51:56 Done.
+ (*dest) = (*src) * current_volume_;
+ ++src;
+ ++dest;
+ --frames;
+ }
+ if (frames) {
+ ::media::vector_math::FMUL(src, current_volume_, frames, dest);
}
}

Powered by Google App Engine
This is Rietveld 408576698