| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 else if (sample < min_value) | 253 else if (sample < min_value) |
| 254 sample = min_value; | 254 sample = min_value; |
| 255 | 255 |
| 256 destination[j * channels + i] = static_cast<Format>(sample) + bias; | 256 destination[j * channels + i] = static_cast<Format>(sample) + bias; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 void InterleaveFloatToInt(const std::vector<float*>& source, void* dst, | 261 void InterleaveFloatToInt(const std::vector<float*>& source, void* dst, |
| 262 size_t number_of_frames, int bytes_per_sample) { | 262 size_t number_of_frames, int bytes_per_sample) { |
| 263 switch(bytes_per_sample) { | 263 switch (bytes_per_sample) { |
| 264 case 1: | 264 case 1: |
| 265 InterleaveFloatToInt<uint8, int32>(source, dst, number_of_frames); | 265 InterleaveFloatToInt<uint8, int32>(source, dst, number_of_frames); |
| 266 break; | 266 break; |
| 267 case 2: | 267 case 2: |
| 268 InterleaveFloatToInt<int16, int32>(source, dst, number_of_frames); | 268 InterleaveFloatToInt<int16, int32>(source, dst, number_of_frames); |
| 269 break; | 269 break; |
| 270 case 4: | 270 case 4: |
| 271 InterleaveFloatToInt<int32, int64>(source, dst, number_of_frames); | 271 InterleaveFloatToInt<int32, int64>(source, dst, number_of_frames); |
| 272 break; | 272 break; |
| 273 default: | 273 default: |
| 274 break; | 274 break; |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 // TODO(enal): use template specialization and size-specific intrinsics. | 278 // TODO(enal): use template specialization and size-specific intrinsics. |
| 279 // Call is on the time-critical path, and by using SSE/AVX | 279 // Call is on the time-critical path, and by using SSE/AVX |
| 280 // instructions we can speed things up by ~4-8x, more for the case | 280 // instructions we can speed things up by ~4-8x, more for the case |
| 281 // when we have to adjust volume as well. | 281 // when we have to adjust volume as well. |
| 282 template<class Format, class Fixed, int min_value, int max_value, int bias> | 282 template<class Format, class Fixed, int min_value, int max_value, int bias> |
| 283 static void MixStreams(Format* dst, Format* src, int count, float volume) { | 283 static void MixStreams(Format* dst, Format* src, int count, float volume) { |
| 284 if (volume == 0.0f) |
| 285 return; |
| 284 if (volume == 1.0f) { | 286 if (volume == 1.0f) { |
| 285 // Most common case -- no need to adjust volume. | 287 // Most common case -- no need to adjust volume. |
| 286 for (int i = 0; i < count; ++i) { | 288 for (int i = 0; i < count; ++i) { |
| 287 Fixed value = AddSaturated<Fixed, min_value, max_value>(dst[i] - bias, | 289 Fixed value = AddSaturated<Fixed, min_value, max_value>(dst[i] - bias, |
| 288 src[i] - bias); | 290 src[i] - bias); |
| 289 dst[i] = static_cast<Format>(value + bias); | 291 dst[i] = static_cast<Format>(value + bias); |
| 290 } | 292 } |
| 291 } else { | 293 } else { |
| 292 // General case -- have to adjust volume before mixing. | 294 // General case -- have to adjust volume before mixing. |
| 293 const int fixed_volume = static_cast<int>(volume * 65536); | 295 const int fixed_volume = static_cast<int>(volume * 65536); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 515 |
| 514 bool IsWASAPISupported() { | 516 bool IsWASAPISupported() { |
| 515 // Note: that function correctly returns that Windows Server 2003 does not | 517 // Note: that function correctly returns that Windows Server 2003 does not |
| 516 // support WASAPI. | 518 // support WASAPI. |
| 517 return base::win::GetVersion() >= base::win::VERSION_VISTA; | 519 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
| 518 } | 520 } |
| 519 | 521 |
| 520 #endif | 522 #endif |
| 521 | 523 |
| 522 } // namespace media | 524 } // namespace media |
| OLD | NEW |