Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: content/renderer/media/webrtc_audio_device_impl.cc

Issue 10824304: Upgrade AudioBus to support wrapping, interleaving. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup! Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/audio/audio_input_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/media/webrtc_audio_device_impl.h" 5 #include "content/renderer/media/webrtc_audio_device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
11 #include "content/renderer/media/audio_device_factory.h" 11 #include "content/renderer/media/audio_device_factory.h"
12 #include "content/renderer/media/audio_hardware.h" 12 #include "content/renderer/media/audio_hardware.h"
13 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
14 #include "media/audio/audio_util.h"
15 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
16 #include "media/audio/sample_rates.h" 15 #include "media/audio/sample_rates.h"
17 16
18 using content::AudioDeviceFactory; 17 using content::AudioDeviceFactory;
19 using media::AudioParameters; 18 using media::AudioParameters;
20 19
21 static const int64 kMillisecondsBetweenProcessCalls = 5000; 20 static const int64 kMillisecondsBetweenProcessCalls = 5000;
22 static const double kMaxVolumeLevel = 255.0; 21 static const double kMaxVolumeLevel = 255.0;
23 22
24 // Supported hardware sample rates for input and output sides. 23 // Supported hardware sample rates for input and output sides.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 channels, 210 channels,
212 samples_per_sec, 211 samples_per_sec,
213 audio_byte_buffer, 212 audio_byte_buffer,
214 num_audio_samples); 213 num_audio_samples);
215 accumulated_audio_samples += num_audio_samples; 214 accumulated_audio_samples += num_audio_samples;
216 audio_byte_buffer += bytes_per_10_msec; 215 audio_byte_buffer += bytes_per_10_msec;
217 } 216 }
218 217
219 // Deinterleave each channel and convert to 32-bit floating-point 218 // Deinterleave each channel and convert to 32-bit floating-point
220 // with nominal range -1.0 -> +1.0 to match the callback format. 219 // with nominal range -1.0 -> +1.0 to match the callback format.
221 for (int channel_index = 0; channel_index < channels; ++channel_index) { 220 audio_bus->FromInterleaved(output_buffer_.get(), audio_bus->frames(),
henrika (OOO until Aug 14) 2012/08/17 13:47:42 Looks really nice ;-) Just in case. Did you run t
222 media::DeinterleaveAudioChannel( 221 bytes_per_sample_);
223 output_buffer_.get(),
224 audio_bus->channel(channel_index),
225 channels,
226 channel_index,
227 bytes_per_sample_,
228 audio_bus->frames());
229 }
230 return audio_bus->frames(); 222 return audio_bus->frames();
231 } 223 }
232 224
233 void WebRtcAudioDeviceImpl::OnRenderError() { 225 void WebRtcAudioDeviceImpl::OnRenderError() {
234 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); 226 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop());
235 // TODO(henrika): Implement error handling. 227 // TODO(henrika): Implement error handling.
236 LOG(ERROR) << "OnRenderError()"; 228 LOG(ERROR) << "OnRenderError()";
237 } 229 }
238 230
239 void WebRtcAudioDeviceImpl::Capture(media::AudioBus* audio_bus, 231 void WebRtcAudioDeviceImpl::Capture(media::AudioBus* audio_bus,
(...skipping 18 matching lines...) Expand all
258 input_delay_ms_ = audio_delay_milliseconds; 250 input_delay_ms_ = audio_delay_milliseconds;
259 output_delay_ms = output_delay_ms_; 251 output_delay_ms = output_delay_ms_;
260 } 252 }
261 253
262 const int channels = audio_bus->channels(); 254 const int channels = audio_bus->channels();
263 DCHECK_LE(channels, input_channels()); 255 DCHECK_LE(channels, input_channels());
264 uint32_t new_mic_level = 0; 256 uint32_t new_mic_level = 0;
265 257
266 // Interleave, scale, and clip input to int and store result in 258 // Interleave, scale, and clip input to int and store result in
267 // a local byte buffer. 259 // a local byte buffer.
268 media::InterleaveFloatToInt(audio_bus, 260 audio_bus->ToInterleaved(audio_bus->frames(),
269 input_buffer_.get(), 261 input_audio_parameters_.bits_per_sample() / 8,
270 audio_bus->frames(), 262 input_buffer_.get());
271 input_audio_parameters_.bits_per_sample() / 8);
272 263
273 int samples_per_sec = input_sample_rate(); 264 int samples_per_sec = input_sample_rate();
274 if (samples_per_sec == 44100) { 265 if (samples_per_sec == 44100) {
275 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. 266 // Even if the hardware runs at 44.1kHz, we use 44.0 internally.
276 samples_per_sec = 44000; 267 samples_per_sec = 44000;
277 } 268 }
278 const int samples_per_10_msec = (samples_per_sec / 100); 269 const int samples_per_10_msec = (samples_per_sec / 100);
279 const int bytes_per_10_msec = 270 const int bytes_per_10_msec =
280 channels * samples_per_10_msec * bytes_per_sample_; 271 channels * samples_per_10_msec * bytes_per_sample_;
281 int accumulated_audio_samples = 0; 272 int accumulated_audio_samples = 0;
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 } 1157 }
1167 1158
1168 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { 1159 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const {
1169 NOTIMPLEMENTED(); 1160 NOTIMPLEMENTED();
1170 return -1; 1161 return -1;
1171 } 1162 }
1172 1163
1173 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { 1164 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) {
1174 session_id_ = session_id; 1165 session_id_ = session_id;
1175 } 1166 }
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698