diff options
Diffstat (limited to 'Source/WebCore/platform/audio/AudioBus.cpp')
-rw-r--r-- | Source/WebCore/platform/audio/AudioBus.cpp | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/Source/WebCore/platform/audio/AudioBus.cpp b/Source/WebCore/platform/audio/AudioBus.cpp index d6aa35002..e7f8902f7 100644 --- a/Source/WebCore/platform/audio/AudioBus.cpp +++ b/Source/WebCore/platform/audio/AudioBus.cpp @@ -225,6 +225,32 @@ void AudioBus::copyFrom(const AudioBus& sourceBus) vadd(sourceL, 1, sourceR, 1, destination, 1, length()); float scale = 0.5; vsmul(destination, 1, &scale, destination, 1, length()); + } else if (numberOfDestinationChannels == 6 && numberOfSourceChannels == 1) { + // Handle mono -> 5.1 case, copy mono channel to center. + channel(2)->copyFrom(sourceBus.channel(0)); + channel(0)->zero(); + channel(1)->zero(); + channel(3)->zero(); + channel(4)->zero(); + channel(5)->zero(); + } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 6) { + // Handle 5.1 -> mono case, copy center channel into mono. + // FIXME: We should have a better algorithm for this down mixing. + channel(0)->copyFrom(sourceBus.channel(2)); + } else if (numberOfDestinationChannels < numberOfSourceChannels) { + // Default down mixing handling, just match the source channels with the first available destination channels. + // 5.1 -> stereo case covered here. + // FIXME: We should have a better algorithm for down mixing 5.1 to stereo. + // https://bugs.webkit.org/show_bug.cgi?id=79192 + for (unsigned i = 0; i < numberOfDestinationChannels; ++i) + channel(i)->copyFrom(sourceBus.channel(i)); + } else if (numberOfDestinationChannels > numberOfSourceChannels) { + // Default up mixing handling, just match the destination channels with the first available source channels. + // Stereo -> 5.1 case covered here. + for (unsigned i = 0; i < numberOfSourceChannels; ++i) + channel(i)->copyFrom(sourceBus.channel(i)); + for (unsigned i = numberOfSourceChannels; i < numberOfDestinationChannels; ++i) + channel(i)->zero(); } else { // Case not handled ASSERT_NOT_REACHED(); @@ -256,6 +282,25 @@ void AudioBus::sumFrom(const AudioBus &sourceBus) float scale = 0.5; vsma(sourceL, 1, &scale, destination, 1, length()); vsma(sourceR, 1, &scale, destination, 1, length()); + } else if (numberOfDestinationChannels == 6 && numberOfSourceChannels == 1) { + // Handle mono -> 5.1 case, sum mono channel into center. + channel(2)->sumFrom(sourceBus.channel(0)); + } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 6) { + // Handle 5.1 -> mono case, sum center channel into mono. + // FIXME: We should have a better algorithm for this down mixing. + channel(0)->sumFrom(sourceBus.channel(2)); + } else if (numberOfDestinationChannels < numberOfSourceChannels) { + // Default down mixing, just summing the first available destination channels. + // 5.1 -> stereo case covered here. + // FIXME: We should have a better algorithm for down mixing 5.1 to stereo. + // https://bugs.webkit.org/show_bug.cgi?id=79192 + for (unsigned i = 0; i < numberOfDestinationChannels; ++i) + channel(i)->sumFrom(sourceBus.channel(i)); + } else if (numberOfDestinationChannels > numberOfSourceChannels) { + // Default up mixing, just summing the first available source channels. + // stereo -> 5.1 case covered here. + for (unsigned i = 0; i < numberOfSourceChannels; ++i) + channel(i)->sumFrom(sourceBus.channel(i)); } else { // Case not handled ASSERT_NOT_REACHED(); @@ -409,10 +454,6 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, float* l } } else { // Process directly (without summing) to our bus - // If it is from the same bus and no need to change gain, just return - if (this == &sourceBus && *lastMixGain == targetGain && targetGain == 1.0) - return; - if (sourceR && destinationR) { // Stereo PROCESS_WITH_GAIN(STEREO_NO_SUM) @@ -437,6 +478,9 @@ void AudioBus::processWithGainFrom(const AudioBus &sourceBus, float* lastMixGain ASSERT_NOT_REACHED(); return; } + // If it is copying from the same bus and no need to change gain, just return + if (!sumToBus && this == &sourceBus && *lastMixGain == targetGain && targetGain == 1.0) + return; // Dispatch for different channel layouts switch (numberOfChannels()) { |