Chromium Code Reviews| 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/audio_input_device.h" | 5 #include "media/audio/audio_input_device.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); | 290 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); |
| 291 ptr += current_segment_id_ * segment_length_; | 291 ptr += current_segment_id_ * segment_length_; |
| 292 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 292 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
| 293 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, | 293 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, |
| 294 // the buffer may be bigger (on mac at least)). | 294 // the buffer may be bigger (on mac at least)). |
| 295 DCHECK_GE(buffer->params.size, | 295 DCHECK_GE(buffer->params.size, |
| 296 segment_length_ - sizeof(AudioInputBufferParameters)); | 296 segment_length_ - sizeof(AudioInputBufferParameters)); |
| 297 double volume = buffer->params.volume; | 297 double volume = buffer->params.volume; |
| 298 bool key_pressed = buffer->params.key_pressed; | 298 bool key_pressed = buffer->params.key_pressed; |
| 299 | 299 |
| 300 // Create audio bus wrapping existing block of shared memory. | |
| 301 scoped_ptr<AudioBus> audio_bus = | |
|
DaleCurtis
2014/06/04 17:39:17
Again create these during construction.
| |
| 302 AudioBus::WrapMemory(audio_parameters_, &buffer->audio[0]); | |
| 303 | |
| 304 // Deliver captured data to the client in floating point format | |
| 305 // and update the audio-delay measurement. | |
| 300 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 306 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
| 301 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); | 307 capture_callback_->Capture( |
| 302 const int bytes_per_sample = sizeof(memory[0]); | 308 audio_bus.get(), audio_delay_milliseconds, volume, key_pressed); |
| 303 | 309 |
| 304 if (++current_segment_id_ >= total_segments_) | 310 if (++current_segment_id_ >= total_segments_) |
| 305 current_segment_id_ = 0; | 311 current_segment_id_ = 0; |
| 306 | |
| 307 // Deinterleave each channel and convert to 32-bit floating-point | |
| 308 // with nominal range -1.0 -> +1.0. | |
| 309 audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample); | |
| 310 | |
| 311 // Deliver captured data to the client in floating point format | |
| 312 // and update the audio-delay measurement. | |
| 313 capture_callback_->Capture( | |
| 314 audio_bus_.get(), audio_delay_milliseconds, volume, key_pressed); | |
| 315 } | 312 } |
| 316 | 313 |
| 317 } // namespace media | 314 } // namespace media |
| OLD | NEW |