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 // 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 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/shared_memory.h" | 16 #include "base/shared_memory.h" |
17 #include "base/time.h" | |
17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
18 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
19 #endif | 20 #endif |
21 #include "media/audio/audio_parameters.h" | |
20 #include "media/audio/audio_util.h" | 22 #include "media/audio/audio_util.h" |
21 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
22 #include "media/audio/mac/audio_low_latency_input_mac.h" | 24 #include "media/audio/mac/audio_low_latency_input_mac.h" |
23 #include "media/audio/mac/audio_low_latency_output_mac.h" | 25 #include "media/audio/mac/audio_low_latency_output_mac.h" |
24 #endif | 26 #endif |
25 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
26 #include "media/audio/win/audio_low_latency_input_win.h" | 28 #include "media/audio/win/audio_low_latency_input_win.h" |
27 #include "media/audio/win/audio_low_latency_output_win.h" | 29 #include "media/audio/win/audio_low_latency_output_win.h" |
28 #endif | 30 #endif |
29 | 31 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 break; | 431 break; |
430 case 1: | 432 case 1: |
431 DoCrossfade(bytes_to_crossfade, number_of_channels, bytes_per_channel, | 433 DoCrossfade(bytes_to_crossfade, number_of_channels, bytes_per_channel, |
432 src, dest); | 434 src, dest); |
433 break; | 435 break; |
434 default: | 436 default: |
435 NOTREACHED() << "Unsupported audio bit depth in crossfade."; | 437 NOTREACHED() << "Unsupported audio bit depth in crossfade."; |
436 } | 438 } |
437 } | 439 } |
438 | 440 |
441 // The minimum number of samples in a hardware packet. | |
442 // This value is selected so that we can handle down to 5khz sample rate. | |
443 static const int kMinSamplesPerHardwarePacket = 1024; | |
444 | |
445 // The maximum number of samples in a hardware packet. | |
446 // This value is selected so that we can handle up to 192khz sample rate. | |
447 static const int kMaxSamplesPerHardwarePacket = 64 * 1024; | |
448 | |
449 // This constant governs the hardware audio buffer size, this value should be | |
450 // chosen carefully. | |
451 // This value is selected so that we have 8192 samples for 48khz streams. | |
452 static const int kMillisecondsPerHardwarePacket = 170; | |
453 | |
454 uint32 SelectSamplesPerPacket(int sample_rate) { | |
455 // Select the number of samples that can provide at least | |
456 // |kMillisecondsPerHardwarePacket| worth of audio data. | |
457 int samples = kMinSamplesPerHardwarePacket; | |
458 while (samples <= kMaxSamplesPerHardwarePacket && | |
459 samples * base::Time::kMillisecondsPerSecond < | |
460 sample_rate * kMillisecondsPerHardwarePacket) { | |
461 samples *= 2; | |
462 } | |
463 return samples; | |
464 } | |
465 | |
Chris Rogers
2012/02/22 23:08:53
It would be great to put this function in content/
| |
439 } // namespace media | 466 } // namespace media |
OLD | NEW |