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/mac/audio_low_latency_output_mac.h" | 5 #include "media/audio/mac/audio_low_latency_output_mac.h" |
6 | 6 |
7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_logging.h" | 12 #include "base/mac/mac_logging.h" |
13 #include "media/audio/audio_util.h" | |
14 #include "media/audio/mac/audio_manager_mac.h" | 13 #include "media/audio/mac/audio_manager_mac.h" |
15 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
16 | 15 |
17 namespace media { | 16 namespace media { |
18 | 17 |
19 static std::ostream& operator<<(std::ostream& os, | 18 static std::ostream& operator<<(std::ostream& os, |
20 const AudioStreamBasicDescription& format) { | 19 const AudioStreamBasicDescription& format) { |
21 os << "sample rate : " << format.mSampleRate << std::endl | 20 os << "sample rate : " << format.mSampleRate << std::endl |
22 << "format ID : " << format.mFormatID << std::endl | 21 << "format ID : " << format.mFormatID << std::endl |
23 << "format flags : " << format.mFormatFlags << std::endl | 22 << "format flags : " << format.mFormatFlags << std::endl |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 memset(audio_data, 0, number_of_frames * format_.mBytesPerFrame); | 276 memset(audio_data, 0, number_of_frames * format_.mBytesPerFrame); |
278 return noErr; | 277 return noErr; |
279 } | 278 } |
280 | 279 |
281 frames_filled = source_->OnMoreData( | 280 frames_filled = source_->OnMoreData( |
282 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes)); | 281 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes)); |
283 } | 282 } |
284 | 283 |
285 // Note: If this ever changes to output raw float the data must be clipped and | 284 // Note: If this ever changes to output raw float the data must be clipped and |
286 // sanitized since it may come from an untrusted source such as NaCl. | 285 // sanitized since it may come from an untrusted source such as NaCl. |
| 286 audio_bus_->Scale(volume_); |
287 audio_bus_->ToInterleaved( | 287 audio_bus_->ToInterleaved( |
288 frames_filled, format_.mBitsPerChannel / 8, audio_data); | 288 frames_filled, format_.mBitsPerChannel / 8, audio_data); |
289 uint32 filled = frames_filled * format_.mBytesPerFrame; | |
290 | |
291 // Perform in-place, software-volume adjustments. | |
292 media::AdjustVolume(audio_data, | |
293 filled, | |
294 audio_bus_->channels(), | |
295 format_.mBitsPerChannel / 8, | |
296 volume_); | |
297 | 289 |
298 return noErr; | 290 return noErr; |
299 } | 291 } |
300 | 292 |
301 // DefaultOutputUnit callback | 293 // DefaultOutputUnit callback |
302 OSStatus AUAudioOutputStream::InputProc(void* user_data, | 294 OSStatus AUAudioOutputStream::InputProc(void* user_data, |
303 AudioUnitRenderActionFlags*, | 295 AudioUnitRenderActionFlags*, |
304 const AudioTimeStamp* output_time_stamp, | 296 const AudioTimeStamp* output_time_stamp, |
305 UInt32, | 297 UInt32, |
306 UInt32 number_of_frames, | 298 UInt32 number_of_frames, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 if (now_ns > output_time_ns) | 404 if (now_ns > output_time_ns) |
413 return 0; | 405 return 0; |
414 | 406 |
415 double delay_frames = static_cast<double> | 407 double delay_frames = static_cast<double> |
416 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); | 408 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); |
417 | 409 |
418 return (delay_frames + hardware_latency_frames_); | 410 return (delay_frames + hardware_latency_frames_); |
419 } | 411 } |
420 | 412 |
421 } // namespace media | 413 } // namespace media |
OLD | NEW |