Use VectorMath lib when possible to optimize the processing in WebAudio AudioBus

https://bugs.webkit.org/show_bug.cgi?id=75334

Patch by Wei James <james.wei@intel.com> on 2012-01-06
Reviewed by Kenneth Russell.

* platform/audio/AudioBus.cpp:
(WebCore::AudioBus::processWithGainFromMonoStereo):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b12618b9
2012-01-06 Wei James <james.wei@intel.com>
Use VectorMath lib when possible to optimize the processing in WebAudio AudioBus
https://bugs.webkit.org/show_bug.cgi?id=75334
Reviewed by Kenneth Russell.
* platform/audio/AudioBus.cpp:
(WebCore::AudioBus::processWithGainFromMonoStereo):
2012-01-06 Jer Noble <jer.noble@apple.com>
Fullscreen video controller can't be dragged the first time I enter fullscreen
......@@ -244,8 +244,7 @@ void AudioBus::sumFrom(const AudioBus &sourceBus)
GAIN_DEZIPPER \
} \
gain = totalDesiredGain; \
for (; k < framesToProcess; ++k) \
OP
OP##_V
#define STEREO_SUM \
{ \
......@@ -255,6 +254,11 @@ void AudioBus::sumFrom(const AudioBus &sourceBus)
*destinationR++ = sumR; \
}
// FIXME: this can be optimized with additional VectorMath functions.
#define STEREO_SUM_V \
for (; k < framesToProcess; ++k) \
STEREO_SUM
// Mono -> stereo (mix equally into L and R)
// FIXME: Really we should apply an equal-power scaling factor here, since we're effectively panning center...
#define MONO2STEREO_SUM \
......@@ -266,12 +270,20 @@ void AudioBus::sumFrom(const AudioBus &sourceBus)
*destinationR++ = sumR; \
}
#define MONO2STEREO_SUM_V \
for (; k < framesToProcess; ++k) \
MONO2STEREO_SUM
#define MONO_SUM \
{ \
float sum = DenormalDisabler::flushDenormalFloatToZero(*destinationL + gain * *sourceL++); \
*destinationL++ = sum; \
}
#define MONO_SUM_V \
for (; k < framesToProcess; ++k) \
MONO_SUM
#define STEREO_NO_SUM \
{ \
float sampleL = *sourceL++; \
......@@ -280,6 +292,12 @@ void AudioBus::sumFrom(const AudioBus &sourceBus)
*destinationR++ = DenormalDisabler::flushDenormalFloatToZero(gain * sampleR); \
}
#define STEREO_NO_SUM_V \
{ \
vsmul(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
vsmul(sourceR, 1, &gain, destinationR, 1, framesToProcess - k); \
}
// Mono -> stereo (mix equally into L and R)
// FIXME: Really we should apply an equal-power scaling factor here, since we're effectively panning center...
#define MONO2STEREO_NO_SUM \
......@@ -289,18 +307,28 @@ void AudioBus::sumFrom(const AudioBus &sourceBus)
*destinationR++ = DenormalDisabler::flushDenormalFloatToZero(gain * sample); \
}
#define MONO2STEREO_NO_SUM_V \
{ \
vsmul(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
vsmul(sourceL, 1, &gain, destinationR, 1, framesToProcess - k); \
}
#define MONO_NO_SUM \
{ \
float sampleL = *sourceL++; \
*destinationL++ = DenormalDisabler::flushDenormalFloatToZero(gain * sampleL); \
}
#define MONO_NO_SUM_V \
{ \
vsmul(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
}
void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus)
{
// We don't want to suddenly change the gain from mixing one time slice to the next,
// so we "de-zipper" by slowly changing the gain each sample-frame until we've achieved the target gain.
// FIXME: optimize this method (SSE, etc.)
// FIXME: targetGain and lastMixGain should be changed to floats instead of doubles.
// Take master bus gain into account as well as the targetGain.
......@@ -351,8 +379,6 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double*
if (this == &sourceBus && *lastMixGain == targetGain && targetGain == 1.0)
return;
// FIXME: if (framesToDezipper == 0) and DenormalDisabler::flushDenormalFloatToZero() is a NOP (gcc vs. Visual Studio)
// then we can further optimize the PROCESS_WITH_GAIN codepaths below using vsmul().
if (sourceR && destinationR) {
// Stereo
PROCESS_WITH_GAIN(STEREO_NO_SUM)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment