| 365 | } |
| 366 | |
| 367 | void AudioBus::speakersSumFrom(const AudioBus & sourceBus) |
| 368 | { |
| 369 | // FIXME: Implement down mixing 5.1 && 7.1 to stereo. |
| 370 | // https://bugs.webkit.org/show_bug.cgi?id=79192 |
| 371 | |
| 372 | const int numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 373 | const int numberOfDestinationChannels = numberOfChannels(); |
| 374 | |
| 375 | if (numberOfDestinationChannels == Channels::Stereo && numberOfSourceChannels == Channels::Mono) |
| 376 | { |
| 377 | // Handle mono -> stereo case (summing mono channel into both left and right). |
| 378 | const AudioChannel * sourceChannel = sourceBus.channel(0); |
| 379 | channelByType(Channel::Left)->sumFrom(sourceChannel); |
| 380 | channelByType(Channel::Right)->sumFrom(sourceChannel); |
| 381 | } |
| 382 | else if (numberOfDestinationChannels == Channels::Mono && numberOfSourceChannels == Channels::Stereo) |
| 383 | { |
| 384 | // Handle stereo -> mono case. output += 0.5 * (input.L + input.R). |
| 385 | AudioBus & sourceBusSafe = const_cast<AudioBus &>(sourceBus); |
| 386 | |
| 387 | const float * sourceL = sourceBusSafe.channelByType(Channel::Left)->data(); |
| 388 | const float * sourceR = sourceBusSafe.channelByType(Channel::Right)->data(); |
| 389 | |
| 390 | float * destination = channelByType(Channel::Left)->mutableData(); |
| 391 | float scale = 0.5; |
| 392 | vsma(sourceL, 1, &scale, destination, 1, length()); |
| 393 | vsma(sourceR, 1, &scale, destination, 1, length()); |
| 394 | } |
| 395 | else if (numberOfDestinationChannels == Channels::Surround_5_1 && numberOfSourceChannels == Channels::Mono) |
| 396 | { |
| 397 | // Handle mono -> 5.1 case, sum mono channel into center. |
| 398 | channelByType(Channel::Center)->sumFrom(sourceBus.channel(0)); |
| 399 | } |
| 400 | else if (numberOfDestinationChannels == Channels::Mono && numberOfSourceChannels == Channels::Surround_5_1) |
| 401 | { |
| 402 | // Handle 5.1 -> mono case. |
| 403 | speakersSumFrom5_1_ToMono(sourceBus); |
| 404 | } |
| 405 | else if (numberOfDestinationChannels == Channels::Surround_7_1 && numberOfSourceChannels == Channels::Mono) |
| 406 | { |
| 407 | // Handle mono -> 7.1 case, sum mono channel into center. |
| 408 | channelByType(Channel::Center)->sumFrom(sourceBus.channel(0)); |
| 409 | } |
| 410 | else if (numberOfDestinationChannels == Channels::Mono && numberOfSourceChannels == Channels::Surround_7_1) |
| 411 | { |
| 412 | // Handle 7.1 -> mono case. |
| 413 | speakersSumFrom7_1_ToMono(sourceBus); |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | // Fallback for unknown combinations. |
| 418 | discreteSumFrom(sourceBus); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | void AudioBus::speakersSumFrom5_1_ToMono(const AudioBus & sourceBus) |
| 423 | { |
nothing calls this directly
no test coverage detected