| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/media/cma/backend/alsa/slew_volume.h" | 5 #include "chromecast/media/cma/backend/alsa/slew_volume.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/vector_math.h" | 10 #include "media/base/vector_math.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 void SlewVolume::SetSampleRate(int sample_rate) { | 33 void SlewVolume::SetSampleRate(int sample_rate) { |
| 34 sample_rate_ = sample_rate; | 34 sample_rate_ = sample_rate; |
| 35 SetVolume(volume_scale_); | 35 SetVolume(volume_scale_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Slew rate should be volume_to_slew / slew_time / sample_rate | 38 // Slew rate should be volume_to_slew / slew_time / sample_rate |
| 39 void SlewVolume::SetVolume(double volume_scale) { | 39 void SlewVolume::SetVolume(double volume_scale) { |
| 40 volume_scale_ = volume_scale; | 40 volume_scale_ = volume_scale; |
| 41 if (interrupted_) { |
| 42 current_volume_ = volume_scale_; |
| 43 } |
| 41 if (volume_scale_ > current_volume_) { | 44 if (volume_scale_ > current_volume_) { |
| 42 max_slew_up_ = (volume_scale_ - current_volume_) * 1000.0 / | 45 max_slew_up_ = (volume_scale_ - current_volume_) * 1000.0 / |
| 43 (max_slew_time_up_ms_ * sample_rate_); | 46 (max_slew_time_up_ms_ * sample_rate_); |
| 44 } else { | 47 } else { |
| 45 max_slew_down_ = (current_volume_ - volume_scale_) * 1000.0 / | 48 max_slew_down_ = (current_volume_ - volume_scale_) * 1000.0 / |
| 46 (max_slew_time_down_ms_ * sample_rate_); | 49 (max_slew_time_down_ms_ * sample_rate_); |
| 47 } | 50 } |
| 48 } | 51 } |
| 49 | 52 |
| 53 void SlewVolume::Interrupted() { |
| 54 interrupted_ = true; |
| 55 current_volume_ = volume_scale_; |
| 56 } |
| 57 |
| 50 void SlewVolume::ProcessFMAC(bool repeat_transition, | 58 void SlewVolume::ProcessFMAC(bool repeat_transition, |
| 51 const float* src, | 59 const float* src, |
| 52 int frames, | 60 int frames, |
| 53 float* dest) { | 61 float* dest) { |
| 54 DCHECK(src); | 62 DCHECK(src); |
| 55 DCHECK(dest); | 63 DCHECK(dest); |
| 56 // Ensure |src| and |dest| are 16-byte aligned. | 64 // Ensure |src| and |dest| are 16-byte aligned. |
| 57 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & | 65 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & |
| 58 (::media::vector_math::kRequiredAlignment - 1)); | 66 (::media::vector_math::kRequiredAlignment - 1)); |
| 59 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & | 67 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & |
| 60 (::media::vector_math::kRequiredAlignment - 1)); | 68 (::media::vector_math::kRequiredAlignment - 1)); |
| 61 | 69 |
| 62 if (!frames) { | 70 if (!frames) { |
| 63 return; | 71 return; |
| 64 } | 72 } |
| 65 | 73 |
| 74 interrupted_ = false; |
| 66 if (repeat_transition) { | 75 if (repeat_transition) { |
| 67 current_volume_ = last_starting_volume_; | 76 current_volume_ = last_starting_volume_; |
| 68 } else { | 77 } else { |
| 69 last_starting_volume_ = current_volume_; | 78 last_starting_volume_ = current_volume_; |
| 70 } | 79 } |
| 71 | 80 |
| 72 if (current_volume_ == volume_scale_) { | 81 if (current_volume_ == volume_scale_) { |
| 73 if (current_volume_ == 0.0) { | 82 if (current_volume_ == 0.0) { |
| 74 return; | 83 return; |
| 75 } | 84 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 // Scaling samples naively like this takes 0.2% of the CPU's time @ 44100hz | 114 // Scaling samples naively like this takes 0.2% of the CPU's time @ 44100hz |
| 106 // on pineapple. | 115 // on pineapple. |
| 107 // Assumes 2 channel audio. | 116 // Assumes 2 channel audio. |
| 108 bool SlewVolume::ProcessInterleaved(int32_t* data, int frames) { | 117 bool SlewVolume::ProcessInterleaved(int32_t* data, int frames) { |
| 109 DCHECK(data); | 118 DCHECK(data); |
| 110 | 119 |
| 111 if (!frames) { | 120 if (!frames) { |
| 112 return true; | 121 return true; |
| 113 } | 122 } |
| 114 | 123 |
| 124 interrupted_ = false; |
| 115 if (current_volume_ == volume_scale_) { | 125 if (current_volume_ == volume_scale_) { |
| 116 if (current_volume_ == 1.0) { | 126 if (current_volume_ == 1.0) { |
| 117 return true; | 127 return true; |
| 118 } | 128 } |
| 119 for (int i = 0; i < 2 * frames; ++i) { | 129 for (int i = 0; i < 2 * frames; ++i) { |
| 120 data[i] *= current_volume_; | 130 data[i] *= current_volume_; |
| 121 } | 131 } |
| 122 return true; | 132 return true; |
| 123 } else if (current_volume_ < volume_scale_) { | 133 } else if (current_volume_ < volume_scale_) { |
| 124 do { | 134 do { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 } | 162 } |
| 153 | 163 |
| 154 for (int i = 0; i < 2 * frames; ++i) { | 164 for (int i = 0; i < 2 * frames; ++i) { |
| 155 data[i] *= current_volume_; | 165 data[i] *= current_volume_; |
| 156 } | 166 } |
| 157 return true; | 167 return true; |
| 158 } | 168 } |
| 159 | 169 |
| 160 } // namespace media | 170 } // namespace media |
| 161 } // namespace chromecast | 171 } // namespace chromecast |
| OLD | NEW |