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

Side by Side Diff: media/audio/audio_util.cc

Issue 10823175: Switch AudioRenderSink::Callback to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup MCR AudioBus usage. 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 | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('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 // Software adjust volume of samples, allows each audio stream its own 5 // Software adjust volume of samples, allows each audio stream its own
6 // volume without impacting master volume for chrome and other applications. 6 // volume without impacting master volume for chrome and other applications.
7 7
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. 8 // Implemented as templates to allow 8, 16 and 32 bit implementations.
9 // 8 bit is unsigned and biased by 128. 9 // 8 bit is unsigned and biased by 128.
10 10
11 // TODO(vrk): This file has been running pretty wild and free, and it's likely 11 // TODO(vrk): This file has been running pretty wild and free, and it's likely
12 // that a lot of the functions can be simplified and made more elegant. Revisit 12 // that a lot of the functions can be simplified and made more elegant. Revisit
13 // after other audio cleanup is done. (crbug.com/120319) 13 // after other audio cleanup is done. (crbug.com/120319)
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <limits> 16 #include <limits>
17 17
18 #include "base/atomicops.h" 18 #include "base/atomicops.h"
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/shared_memory.h" 21 #include "base/shared_memory.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "media/audio/audio_parameters.h" 23 #include "media/audio/audio_parameters.h"
24 #include "media/audio/audio_util.h" 24 #include "media/audio/audio_util.h"
25 #include "media/base/audio_bus.h"
25 26
26 #if defined(OS_MACOSX) 27 #if defined(OS_MACOSX)
27 #include "media/audio/mac/audio_low_latency_input_mac.h" 28 #include "media/audio/mac/audio_low_latency_input_mac.h"
28 #include "media/audio/mac/audio_low_latency_output_mac.h" 29 #include "media/audio/mac/audio_low_latency_output_mac.h"
29 #elif defined(OS_WIN) 30 #elif defined(OS_WIN)
30 #include "base/command_line.h" 31 #include "base/command_line.h"
31 #include "base/win/windows_version.h" 32 #include "base/win/windows_version.h"
32 #include "media/audio/audio_manager_base.h" 33 #include "media/audio/audio_manager_base.h"
33 #include "media/audio/win/audio_low_latency_input_win.h" 34 #include "media/audio/win/audio_low_latency_input_win.h"
34 #include "media/audio/win/audio_low_latency_output_win.h" 35 #include "media/audio/win/audio_low_latency_output_win.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 224
224 default: 225 default:
225 break; 226 break;
226 } 227 }
227 return false; 228 return false;
228 } 229 }
229 230
230 // |Format| is the destination type, |Fixed| is a type larger than |Format| 231 // |Format| is the destination type, |Fixed| is a type larger than |Format|
231 // such that operations can be made without overflowing. 232 // such that operations can be made without overflowing.
232 template<class Format, class Fixed> 233 template<class Format, class Fixed>
233 static void InterleaveFloatToInt(const std::vector<float*>& source, 234 static void InterleaveFloatToInt(const AudioBus* source,
234 void* dst_bytes, size_t number_of_frames) { 235 void* dst_bytes, size_t number_of_frames) {
235 Format* destination = reinterpret_cast<Format*>(dst_bytes); 236 Format* destination = reinterpret_cast<Format*>(dst_bytes);
236 Fixed max_value = std::numeric_limits<Format>::max(); 237 Fixed max_value = std::numeric_limits<Format>::max();
237 Fixed min_value = std::numeric_limits<Format>::min(); 238 Fixed min_value = std::numeric_limits<Format>::min();
238 239
239 Format bias = 0; 240 Format bias = 0;
240 if (!std::numeric_limits<Format>::is_signed) { 241 if (!std::numeric_limits<Format>::is_signed) {
241 bias = max_value / 2; 242 bias = max_value / 2;
242 max_value = bias; 243 max_value = bias;
243 min_value = -(bias - 1); 244 min_value = -(bias - 1);
244 } 245 }
245 246
246 int channels = source.size(); 247 int channels = source->channels();
247 for (int i = 0; i < channels; ++i) { 248 for (int i = 0; i < channels; ++i) {
248 float* channel_data = source[i]; 249 const float* channel_data = source->channel(i);
249 for (size_t j = 0; j < number_of_frames; ++j) { 250 for (size_t j = 0; j < number_of_frames; ++j) {
250 Fixed sample = max_value * channel_data[j]; 251 Fixed sample = max_value * channel_data[j];
251 if (sample > max_value) 252 if (sample > max_value)
252 sample = max_value; 253 sample = max_value;
253 else if (sample < min_value) 254 else if (sample < min_value)
254 sample = min_value; 255 sample = min_value;
255 256
256 destination[j * channels + i] = static_cast<Format>(sample) + bias; 257 destination[j * channels + i] = static_cast<Format>(sample) + bias;
257 } 258 }
258 } 259 }
259 } 260 }
260 261
261 void InterleaveFloatToInt(const std::vector<float*>& source, void* dst, 262 void InterleaveFloatToInt(const AudioBus* source, void* dst,
262 size_t number_of_frames, int bytes_per_sample) { 263 size_t number_of_frames, int bytes_per_sample) {
263 switch (bytes_per_sample) { 264 switch (bytes_per_sample) {
264 case 1: 265 case 1:
265 InterleaveFloatToInt<uint8, int32>(source, dst, number_of_frames); 266 InterleaveFloatToInt<uint8, int32>(source, dst, number_of_frames);
266 break; 267 break;
267 case 2: 268 case 2:
268 InterleaveFloatToInt<int16, int32>(source, dst, number_of_frames); 269 InterleaveFloatToInt<int16, int32>(source, dst, number_of_frames);
269 break; 270 break;
270 case 4: 271 case 4:
271 InterleaveFloatToInt<int32, int64>(source, dst, number_of_frames); 272 InterleaveFloatToInt<int32, int64>(source, dst, number_of_frames);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // out performance was degraded compared to XP. 547 // out performance was degraded compared to XP.
547 // - The regression was fixed in Windows 7 and most configurations will work 548 // - The regression was fixed in Windows 7 and most configurations will work
548 // with 2, but some (e.g., some Sound Blasters) still need 3. 549 // with 2, but some (e.g., some Sound Blasters) still need 3.
549 // - Some XP configurations (even multi-processor ones) also need 3. 550 // - Some XP configurations (even multi-processor ones) also need 3.
550 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 551 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
551 } 552 }
552 553
553 #endif 554 #endif
554 555
555 } // namespace media 556 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698