| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/cras/cras_input.h" | 5 #include "media/audio/cras/cras_input.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 timespec latency_ts = {0, 0}; | 291 timespec latency_ts = {0, 0}; |
| 292 | 292 |
| 293 // Determine latency and pass that on to the sink. sample_ts is the wall time | 293 // Determine latency and pass that on to the sink. sample_ts is the wall time |
| 294 // indicating when the first sample in the buffer was captured. Convert that | 294 // indicating when the first sample in the buffer was captured. Convert that |
| 295 // to latency in bytes. | 295 // to latency in bytes. |
| 296 cras_client_calc_capture_latency(sample_ts, &latency_ts); | 296 cras_client_calc_capture_latency(sample_ts, &latency_ts); |
| 297 double latency_usec = | 297 double latency_usec = |
| 298 latency_ts.tv_sec * base::Time::kMicrosecondsPerSecond + | 298 latency_ts.tv_sec * base::Time::kMicrosecondsPerSecond + |
| 299 latency_ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond; | 299 latency_ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond; |
| 300 double frames_latency = | |
| 301 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; | |
| 302 unsigned int bytes_latency = | |
| 303 static_cast<unsigned int>(frames_latency * bytes_per_frame_); | |
| 304 | 300 |
| 305 // Update the AGC volume level once every second. Note that, |volume| is | 301 // Update the AGC volume level once every second. Note that, |volume| is |
| 306 // also updated each time SetVolume() is called through IPC by the | 302 // also updated each time SetVolume() is called through IPC by the |
| 307 // render-side AGC. | 303 // render-side AGC. |
| 308 double normalized_volume = 0.0; | 304 double normalized_volume = 0.0; |
| 309 GetAgcVolume(&normalized_volume); | 305 GetAgcVolume(&normalized_volume); |
| 310 | 306 |
| 311 audio_bus_->FromInterleaved( | 307 audio_bus_->FromInterleaved( |
| 312 buffer, audio_bus_->frames(), params_.bits_per_sample() / 8); | 308 buffer, audio_bus_->frames(), params_.bits_per_sample() / 8); |
| 313 callback_->OnData(this, audio_bus_.get(), bytes_latency, normalized_volume); | 309 callback_->OnData(this, audio_bus_.get(), |
| 310 base::TimeDelta::FromMicroseconds(latency_usec), |
| 311 base::TimeTicks::Now(), normalized_volume); |
| 314 } | 312 } |
| 315 | 313 |
| 316 void CrasInputStream::NotifyStreamError(int err) { | 314 void CrasInputStream::NotifyStreamError(int err) { |
| 317 if (callback_) | 315 if (callback_) |
| 318 callback_->OnError(this); | 316 callback_->OnError(this); |
| 319 } | 317 } |
| 320 | 318 |
| 321 double CrasInputStream::GetMaxVolume() { | 319 double CrasInputStream::GetMaxVolume() { |
| 322 DCHECK(client_); | 320 DCHECK(client_); |
| 323 | 321 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 354 |
| 357 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 355 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
| 358 return pow(10, dB / 20.0); | 356 return pow(10, dB / 20.0); |
| 359 } | 357 } |
| 360 | 358 |
| 361 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 359 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
| 362 return 20 * log10(volume_ratio); | 360 return 20 * log10(volume_ratio); |
| 363 } | 361 } |
| 364 | 362 |
| 365 } // namespace media | 363 } // namespace media |
| OLD | NEW |