WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-70140-20111018092517.patch (text/plain), 8.88 KB, created by
Raymond Toy
on 2011-10-18 09:25:18 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Raymond Toy
Created:
2011-10-18 09:25:18 PDT
Size:
8.88 KB
patch
obsolete
>Subversion Revision: 97595 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index a5291224fa0d13f6d163f857cfa4b81267f2a5b5..ff5256421ecc54dcdfa338d3e39c067216ae90ed 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,18 @@ >+2011-10-17 Raymond Toy <rtoy@google.com> >+ >+ Flush denormals to zero on Windows. >+ https://bugs.webkit.org/show_bug.cgi?id=70140 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * platform/audio/AudioBus.cpp: >+ (WebCore::AudioBus::processWithGainFromMonoStereo): >+ Flush any denormals to zero before saving the result. Change >+ double gain to float gain to match existing float operations. >+ * platform/audio/DenormalDisabler.h: >+ (WebCore::FlushToFloatZero): >+ New function to flush the given float to zero, if it is a denormal >+ number. > 2011-10-17 Satish Sampath <satish@chromium.org> > > Avoid leaking document when leaving google.com due to geolocation >diff --git a/Source/WebCore/platform/audio/AudioBus.cpp b/Source/WebCore/platform/audio/AudioBus.cpp >index ad29af1aad237237091f55936227b931fe999cc8..5f4891982658175b53b3eccc5fe1baf11bf1f485 100644 >--- a/Source/WebCore/platform/audio/AudioBus.cpp >+++ b/Source/WebCore/platform/audio/AudioBus.cpp >@@ -32,6 +32,8 @@ > > #include "AudioBus.h" > >+#include "DenormalDisabler.h" >+ > #if !PLATFORM(MAC) > #include "SincResampler.h" > #endif >@@ -238,11 +240,13 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* > // FIXME: Need fast path here when gain has converged on targetGain. In this case, de-zippering is no longer needed. > // FIXME: Need fast path when this==sourceBus && lastMixGain==targetGain==1.0 && sumToBus==false (this is a NOP) > >+ // FIXME: targetGain and lastMixGain should be changed to floats instead of doubles. >+ > // Take master bus gain into account as well as the targetGain. >- double totalDesiredGain = m_busGain * targetGain; >+ float totalDesiredGain = static_cast<float>(m_busGain * targetGain); > > // First time, snap directly to totalDesiredGain. >- double gain = m_isFirstTime ? totalDesiredGain : *lastMixGain; >+ float gain = static_cast<float>(m_isFirstTime ? totalDesiredGain : *lastMixGain); > m_isFirstTime = false; > > int numberOfSourceChannels = sourceBus.numberOfChannels(); >@@ -255,7 +259,7 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* > float* destinationL = channelByType(ChannelLeft)->data(); > float* destinationR = numberOfDestinationChannels > 1 ? channelByType(ChannelRight)->data() : 0; > >- const double DezipperRate = 0.005; >+ const float DezipperRate = 0.005f; > int framesToProcess = length(); > > if (sumToBus) { >@@ -263,33 +267,39 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* > if (sourceR && destinationR) { > // Stereo > while (framesToProcess--) { >- float sampleL = *sourceL++; >- float sampleR = *sourceR++; >- *destinationL++ += static_cast<float>(gain * sampleL); >- *destinationR++ += static_cast<float>(gain * sampleR); >+ float sumL = DenormalDisabler::FlushDenormalFloatToZero(*destinationL + gain * *sourceL++); >+ float sumR = DenormalDisabler::FlushDenormalFloatToZero(*destinationR + gain * *sourceR++); >+ *destinationL++ = sumL; >+ *destinationR++ = sumR; > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } else if (destinationR) { > // 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... > while (framesToProcess--) { >- float sample = *sourceL++; >- *destinationL++ += static_cast<float>(gain * sample); >- *destinationR++ += static_cast<float>(gain * sample); >+ float scaled = gain * *sourceL++; >+ float sumL = DenormalDisabler::FlushDenormalFloatToZero(*destinationL + scaled); >+ float sumR = DenormalDisabler::FlushDenormalFloatToZero(*destinationR + scaled); >+ >+ *destinationL++ = sumL; >+ *destinationR++ = sumR; > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } else { > // Mono > while (framesToProcess--) { >- float sampleL = *sourceL++; >- *destinationL++ += static_cast<float>(gain * sampleL); >+ float sum = DenormalDisabler::FlushDenormalFloatToZero(*destinationL + gain * *sourceL++); >+ *destinationL++ = sum; > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } > } else { >@@ -299,37 +309,40 @@ void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* > while (framesToProcess--) { > float sampleL = *sourceL++; > float sampleR = *sourceR++; >- *destinationL++ = static_cast<float>(gain * sampleL); >- *destinationR++ = static_cast<float>(gain * sampleR); >+ *destinationL++ = DenormalDisabler::FlushDenormalFloatToZero(gain * sampleL); >+ *destinationR++ = DenormalDisabler::FlushDenormalFloatToZero(gain * sampleR); > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } else if (destinationR) { > // 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... > while (framesToProcess--) { > float sample = *sourceL++; >- *destinationL++ = static_cast<float>(gain * sample); >- *destinationR++ = static_cast<float>(gain * sample); >+ *destinationL++ = DenormalDisabler::FlushDenormalFloatToZero(gain * sample); >+ *destinationR++ = DenormalDisabler::FlushDenormalFloatToZero(gain * sample); > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } else { > // Mono > while (framesToProcess--) { > float sampleL = *sourceL++; >- *destinationL++ = static_cast<float>(gain * sampleL); >+ *destinationL++ = DenormalDisabler::FlushDenormalFloatToZero(gain * sampleL); > > // Slowly change gain to desired gain. > gain += (totalDesiredGain - gain) * DezipperRate; >+ gain = DenormalDisabler::FlushDenormalFloatToZero(gain); > } > } > } > > // Save the target gain as the starting point for next time around. >- *lastMixGain = gain; >+ *lastMixGain = static_cast<double>(gain); > } > > void AudioBus::processWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus) >diff --git a/Source/WebCore/platform/audio/DenormalDisabler.h b/Source/WebCore/platform/audio/DenormalDisabler.h >index 69d5eb37ee1b4d43b3155ee1ca2f673111ce360a..34932cb3f305c62e1241b87ed770060543e78c97 100644 >--- a/Source/WebCore/platform/audio/DenormalDisabler.h >+++ b/Source/WebCore/platform/audio/DenormalDisabler.h >@@ -25,6 +25,10 @@ > #ifndef DenormalDisabler_h > #define DenormalDisabler_h > >+#if OS(WINDOWS) && COMPILER(MSVC) && (_M_IX86_FP == 0) >+#include <wtf/MathExtras.h> >+#endif >+ > namespace WebCore { > > // Deal with denormals. They can very seriously impact performance on x86. >@@ -43,6 +47,11 @@ public: > setCSR(m_savedCSR); > } > >+ // This is a nop if we can flush denormals to zero in hardware. >+ static inline float FlushDenormalFloatToZero(float f) >+ { >+ return f; >+ } > private: > inline int getCSR() > { >@@ -65,6 +74,18 @@ private: > class DenormalDisabler { > public: > DenormalDisabler() { } >+ >+ static inline float FlushDenormalFloatToZero(float f) >+ { >+#if OS(WINDOWS) && COMPILER(MSVC) && (_M_IX86_FP == 0) >+ // For systems using x87 instead of sse, there's no hardware support >+ // to flush denormals automatically. Hence, we need to flush >+ // denormals to zero manually. >+ return (fabs(f) < FLT_MIN) ? 0.0f : f; >+#else >+ return f; >+#endif >+ } > }; > > #endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 70140
:
111070
|
111072
|
111105
|
111451
|
111467
|
111519
|
111643