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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
13 #include "media/audio/cras/audio_manager_cras.h" | 13 #include "media/audio/cras/audio_manager_cras.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 // Flag to indicate hotword stream. | |
18 static const uint32_t kHotwordParam = 1; | |
dgreid
2014/12/10 00:23:35
This will be 0x03. or even better HOTWORD_STREAM f
rpetterson
2014/12/10 00:37:43
Cool. When do you think that will land?
dgreid
2014/12/10 00:54:50
hopefully soon. I need to get a build without it a
rpetterson
2014/12/13 01:04:00
I've updated the way I think you mean. Let me know
| |
19 | |
17 CrasInputStream::CrasInputStream(const AudioParameters& params, | 20 CrasInputStream::CrasInputStream(const AudioParameters& params, |
18 AudioManagerCras* manager, | 21 AudioManagerCras* manager, |
19 const std::string& device_id) | 22 const std::string& device_id) |
20 : audio_manager_(manager), | 23 : audio_manager_(manager), |
21 bytes_per_frame_(0), | 24 bytes_per_frame_(0), |
22 callback_(NULL), | 25 callback_(NULL), |
23 client_(NULL), | 26 client_(NULL), |
24 params_(params), | 27 params_(params), |
25 started_(false), | 28 started_(false), |
26 stream_id_(0), | 29 stream_id_(0), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 for (size_t i = 0; i < arraysize(kChannelMap); ++i) { | 155 for (size_t i = 0; i < arraysize(kChannelMap); ++i) { |
153 layout[kChannelMap[i]] = ChannelOrder(params_.channel_layout(), | 156 layout[kChannelMap[i]] = ChannelOrder(params_.channel_layout(), |
154 static_cast<Channels>(i)); | 157 static_cast<Channels>(i)); |
155 } | 158 } |
156 if (cras_audio_format_set_channel_layout(audio_format, layout) != 0) { | 159 if (cras_audio_format_set_channel_layout(audio_format, layout) != 0) { |
157 DLOG(WARNING) << "Error setting channel layout."; | 160 DLOG(WARNING) << "Error setting channel layout."; |
158 callback->OnError(this); | 161 callback->OnError(this); |
159 return; | 162 return; |
160 } | 163 } |
161 | 164 |
165 uint32_t flags = 0; | |
166 if (params_.effects() & AudioParameters::PlatformEffectsMask::HOTWORD) | |
167 flags = kHotwordParam; | |
168 | |
162 unsigned int frames_per_packet = params_.frames_per_buffer(); | 169 unsigned int frames_per_packet = params_.frames_per_buffer(); |
163 cras_stream_params* stream_params = cras_client_stream_params_create( | 170 cras_stream_params* stream_params = cras_client_stream_params_create( |
164 stream_direction_, | 171 stream_direction_, |
165 frames_per_packet, // Total latency. | 172 frames_per_packet, // Total latency. |
166 frames_per_packet, // Call back when this many ready. | 173 frames_per_packet, // Call back when this many ready. |
167 frames_per_packet, // Minimum Callback level ignored for capture streams. | 174 frames_per_packet, // Minimum Callback level ignored for capture streams. |
168 CRAS_STREAM_TYPE_DEFAULT, | 175 CRAS_STREAM_TYPE_DEFAULT, |
169 0, // Unused flags. | 176 flags, |
170 this, | 177 this, |
171 CrasInputStream::SamplesReady, | 178 CrasInputStream::SamplesReady, |
172 CrasInputStream::StreamError, | 179 CrasInputStream::StreamError, |
173 audio_format); | 180 audio_format); |
174 if (!stream_params) { | 181 if (!stream_params) { |
175 DLOG(WARNING) << "Error setting up stream parameters."; | 182 DLOG(WARNING) << "Error setting up stream parameters."; |
176 callback_->OnError(this); | 183 callback_->OnError(this); |
177 callback_ = NULL; | 184 callback_ = NULL; |
178 cras_audio_format_destroy(audio_format); | 185 cras_audio_format_destroy(audio_format); |
179 return; | 186 return; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 | 310 |
304 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 311 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
305 return pow(10, dB / 20.0); | 312 return pow(10, dB / 20.0); |
306 } | 313 } |
307 | 314 |
308 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 315 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
309 return 20 * log10(volume_ratio); | 316 return 20 * log10(volume_ratio); |
310 } | 317 } |
311 | 318 |
312 } // namespace media | 319 } // namespace media |
OLD | NEW |