| 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 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 break; | 431 break; |
| 432 case 1: | 432 case 1: |
| 433 DoCrossfade(bytes_to_crossfade, number_of_channels, bytes_per_channel, | 433 DoCrossfade(bytes_to_crossfade, number_of_channels, bytes_per_channel, |
| 434 src, dest); | 434 src, dest); |
| 435 break; | 435 break; |
| 436 default: | 436 default: |
| 437 NOTREACHED() << "Unsupported audio bit depth in crossfade."; | 437 NOTREACHED() << "Unsupported audio bit depth in crossfade."; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 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 | |
| 466 } // namespace media | 441 } // namespace media |
| OLD | NEW |