diff options
author | Steve Block <steveblock@google.com> | 2011-06-08 08:26:01 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-08 08:26:01 -0700 |
commit | 3742ac093d35d923c81693096ab6671e9b147700 (patch) | |
tree | c2add9100f789dad45ef1ec5328bddde02c47a4c /Source/WebCore/platform/audio/AudioBus.cpp | |
parent | 901401d90459bc22580842455d4588b9a697514d (diff) | |
parent | e5926f4a0d6adc9ad4a75824129f117181953560 (diff) | |
download | external_webkit-3742ac093d35d923c81693096ab6671e9b147700.zip external_webkit-3742ac093d35d923c81693096ab6671e9b147700.tar.gz external_webkit-3742ac093d35d923c81693096ab6671e9b147700.tar.bz2 |
Merge changes I55c6d71a,Ifb3277d4,Ia1b847a2,I7ba9cf3f,Ida2b2a8a,I1280ec90,I72f818d5,I2e3b588b,I9a4e6289,Ia724c78b,Icd8612c8,Ie31b15d7,Ie125edae,I77941a88,I89dae78b,I3516e5ca,I1a4c17b5,I2c4ecc1a,I9c8e6537,Ifac13115,Ie1f80e09,Ia541ed77,I60ce9d78
* changes:
Merge WebKit at r82507: Update ThirdPartyProject.prop
Merge WebKit at r82507: Cherry-pick change r88166 to add INSPECTOR guards to ScriptProfiler
Merge WebKit at r82507: Work around a V8 bug
Merge WebKit at r82507: JNIType renamed to JavaType
Merge WebKit at r82507: IconDatabaseClient interface expanded
Merge WebKit at r82507: Don't use new loss-free code path in HTMLCanvasElement::toDataURL()
Merge WebKit at r82507: IcondDatabaseBase::iconForPageURL() renamed
Merge WebKit at r82507: IconDatabaseBase::Open() signature changed
Merge WebKit at r82507: Node::isContentEditable() renamed
Merge WebKit at r82507: Use icon database through IconDatabaseBase
Merge WebKit at r82507: toInputElement() is now a member of Node
Merge WebKit at r82507: FrameLoaderClient::objectContentType() signature changed
Merge WebKit at r82507: StringImpl::computeHash() removed
Merge WebKit at r82507: Stub out FontPlatformData::setOrientation()
Merge WebKit at r82507: Path::strokeBoundingRect() is now const
Merge WebKit at r82507: Add missing UnusedParam.h include in ApplicationCacheGroup.cpp
Merge WebKit at r82507: Continue to use Android's version of FontPlatformData.h
Merge WebKit at r82507: Update signature of FontCustomPlatformData::fontPlatformData()
Merge WebKit at r82507: Fix conflicts due to JNI refactoring
Merge WebKit at r82507: Fix conflicts due to new StorageTracker
Merge WebKit at r82507: Fix conflicts
Merge WebKit at r82507: Fix makefiles
Merge WebKit at r82507: Initial merge by git
Diffstat (limited to 'Source/WebCore/platform/audio/AudioBus.cpp')
-rw-r--r-- | Source/WebCore/platform/audio/AudioBus.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Source/WebCore/platform/audio/AudioBus.cpp b/Source/WebCore/platform/audio/AudioBus.cpp index dd4746d..6f74471 100644 --- a/Source/WebCore/platform/audio/AudioBus.cpp +++ b/Source/WebCore/platform/audio/AudioBus.cpp @@ -32,6 +32,9 @@ #include "AudioBus.h" +#if !PLATFORM(MAC) +#include "SincResampler.h" +#endif #include "VectorMath.h" #include <algorithm> #include <assert.h> @@ -360,6 +363,90 @@ void AudioBus::sumWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, d processWithGainFrom(sourceBus, lastMixGain, targetGain, true); } +#if !PLATFORM(MAC) +PassOwnPtr<AudioBus> AudioBus::createBySampleRateConverting(AudioBus* sourceBus, bool mixToMono, double newSampleRate) +{ + // sourceBus's sample-rate must be known. + ASSERT(sourceBus && sourceBus->sampleRate()); + if (!sourceBus || !sourceBus->sampleRate()) + return 0; + + double sourceSampleRate = sourceBus->sampleRate(); + double destinationSampleRate = newSampleRate; + unsigned numberOfSourceChannels = sourceBus->numberOfChannels(); + + if (numberOfSourceChannels == 1) + mixToMono = false; // already mono + + if (sourceSampleRate == destinationSampleRate) { + // No sample-rate conversion is necessary. + if (mixToMono) + return AudioBus::createByMixingToMono(sourceBus); + + // Return exact copy. + return AudioBus::createBufferFromRange(sourceBus, 0, sourceBus->length()); + } + + // First, mix to mono (if necessary) then sample-rate convert. + AudioBus* resamplerSourceBus; + OwnPtr<AudioBus> mixedMonoBus; + if (mixToMono) { + mixedMonoBus = AudioBus::createByMixingToMono(sourceBus); + resamplerSourceBus = mixedMonoBus.get(); + } else { + // Directly resample without down-mixing. + resamplerSourceBus = sourceBus; + } + + // Calculate destination length based on the sample-rates. + double sampleRateRatio = sourceSampleRate / destinationSampleRate; + int sourceLength = resamplerSourceBus->length(); + int destinationLength = sourceLength / sampleRateRatio; + + // Create destination bus with same number of channels. + unsigned numberOfDestinationChannels = resamplerSourceBus->numberOfChannels(); + OwnPtr<AudioBus> destinationBus(adoptPtr(new AudioBus(numberOfDestinationChannels, destinationLength))); + + // Sample-rate convert each channel. + for (unsigned i = 0; i < numberOfDestinationChannels; ++i) { + float* source = resamplerSourceBus->channel(i)->data(); + float* destination = destinationBus->channel(i)->data(); + + SincResampler resampler(sampleRateRatio); + resampler.process(source, destination, sourceLength); + } + + return destinationBus.release(); +} +#endif // !PLATFORM(MAC) + +PassOwnPtr<AudioBus> AudioBus::createByMixingToMono(AudioBus* sourceBus) +{ + switch (sourceBus->numberOfChannels()) { + case 1: + // Simply create an exact copy. + return AudioBus::createBufferFromRange(sourceBus, 0, sourceBus->length()); + case 2: + { + unsigned n = sourceBus->length(); + OwnPtr<AudioBus> destinationBus(adoptPtr(new AudioBus(1, n))); + + float* sourceL = sourceBus->channel(0)->data(); + float* sourceR = sourceBus->channel(1)->data(); + float* destination = destinationBus->channel(0)->data(); + + // Do the mono mixdown. + for (unsigned i = 0; i < n; ++i) + destination[i] = 0.5 * (sourceL[i] + sourceR[i]); + + return destinationBus.release(); + } + } + + ASSERT_NOT_REACHED(); + return 0; +} + } // WebCore #endif // ENABLE(WEB_AUDIO) |