Diff
Modified: trunk/Source/WebCore/ChangeLog (104992 => 104993)
--- trunk/Source/WebCore/ChangeLog 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/ChangeLog 2012-01-13 22:42:46 UTC (rev 104993)
@@ -1,3 +1,29 @@
+2011-01-13 Jer Noble <jer.no...@apple.com>
+
+ WebAudio: Use float instead of double values for gain operations.
+ https://bugs.webkit.org/show_bug.cgi?id=74345
+
+ Reviewed by Sam Weinig.
+
+ No new tests; optimization of existing code, so covered by existing test cases.
+
+ The following functions now take or operate on floats instead of doubles:
+ (WebCore::AudioBus::scale):
+ (WebCore::AudioBus::processWithGainFrom):
+ (WebCore::AudioBus::copyWithGainFrom):
+ (WebCore::AudioBus::sumWithGainFrom):
+ * platform/audio/AudioBus.h:
+ (WebCore::AudioBus::setGain):
+ (WebCore::AudioBus::gain):
+ * platform/audio/AudioChannel.cpp:
+ (WebCore::AudioChannel::scale):
+ * platform/audio/AudioChannel.h:
+ * webaudio/AudioBufferSourceNode.cpp:
+ (WebCore::AudioBufferSourceNode::process):
+ * webaudio/AudioBufferSourceNode.h:
+ * webaudio/AudioGainNode.h:
+ * webaudio/AudioPannerNode.h:
+
2012-01-13 Greg Billock <gbill...@google.com>
Don't use pending activity notification in IntentRequest
Modified: trunk/Source/WebCore/platform/audio/AudioBus.cpp (104992 => 104993)
--- trunk/Source/WebCore/platform/audio/AudioBus.cpp 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/platform/audio/AudioBus.cpp 2012-01-13 22:42:46 UTC (rev 104993)
@@ -183,7 +183,7 @@
scale(1.0f / max);
}
-void AudioBus::scale(double scale)
+void AudioBus::scale(float scale)
{
for (unsigned i = 0; i < numberOfChannels(); ++i)
channel(i)->scale(scale);
@@ -326,12 +326,10 @@
vsmul(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
}
-void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus)
+void AudioBus::processWithGainFromMonoStereo(const AudioBus &sourceBus, float* lastMixGain, float 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: targetGain and lastMixGain should be changed to floats instead of doubles.
// Take master bus gain into account as well as the targetGain.
float totalDesiredGain = static_cast<float>(m_busGain * targetGain);
@@ -394,10 +392,10 @@
}
// Save the target gain as the starting point for next time around.
- *lastMixGain = static_cast<double>(gain);
+ *lastMixGain = gain;
}
-void AudioBus::processWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus)
+void AudioBus::processWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain, bool sumToBus)
{
// Make sure we're summing from same type of bus.
// We *are* able to sum from mono -> stereo
@@ -444,12 +442,12 @@
}
}
-void AudioBus::copyWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain)
+void AudioBus::copyWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain)
{
processWithGainFrom(sourceBus, lastMixGain, targetGain, false);
}
-void AudioBus::sumWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain)
+void AudioBus::sumWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain)
{
processWithGainFrom(sourceBus, lastMixGain, targetGain, true);
}
Modified: trunk/Source/WebCore/platform/audio/AudioBus.h (104992 => 104993)
--- trunk/Source/WebCore/platform/audio/AudioBus.h 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/platform/audio/AudioBus.h 2012-01-13 22:42:46 UTC (rev 104993)
@@ -100,11 +100,11 @@
static PassOwnPtr<AudioBus> createByMixingToMono(AudioBus* sourceBus);
// Scales all samples by the same amount.
- void scale(double scale);
+ void scale(float scale);
// Master gain for this bus - used with sumWithGainFrom() below
- void setGain(double gain) { m_busGain = gain; }
- double gain() { return m_busGain; }
+ void setGain(float gain) { m_busGain = gain; }
+ float gain() { return m_busGain; }
void reset() { m_isFirstTime = true; } // for de-zippering
@@ -119,8 +119,8 @@
// We scale by targetGain (and our own internal gain m_busGain), performing "de-zippering" to smoothly change from *lastMixGain to (targetGain*m_busGain).
// The caller is responsible for setting up lastMixGain to point to storage which is unique for every "stream" which will be summed to this bus.
// This represents the dezippering memory.
- void copyWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain);
- void sumWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain);
+ void copyWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain);
+ void sumWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain);
// Copies the sourceBus by scaling with sample-accurate gain values.
void copyWithSampleAccurateGainValuesFrom(const AudioBus &sourceBus, float* gainValues, unsigned numberOfGainValues);
@@ -136,8 +136,8 @@
protected:
AudioBus() { };
- void processWithGainFrom(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus);
- void processWithGainFromMonoStereo(const AudioBus &sourceBus, double* lastMixGain, double targetGain, bool sumToBus);
+ void processWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, float targetGain, bool sumToBus);
+ void processWithGainFromMonoStereo(const AudioBus &sourceBus, float* lastMixGain, float targetGain, bool sumToBus);
size_t m_length;
@@ -145,7 +145,7 @@
int m_layout;
- double m_busGain;
+ float m_busGain;
bool m_isFirstTime;
float m_sampleRate; // 0.0 if unknown or N/A
};
Modified: trunk/Source/WebCore/platform/audio/AudioChannel.cpp (104992 => 104993)
--- trunk/Source/WebCore/platform/audio/AudioChannel.cpp 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/platform/audio/AudioChannel.cpp 2012-01-13 22:42:46 UTC (rev 104993)
@@ -41,10 +41,9 @@
using namespace VectorMath;
-void AudioChannel::scale(double scale)
+void AudioChannel::scale(float scale)
{
- float s = static_cast<float>(scale);
- vsmul(data(), 1, &s, data(), 1, length());
+ vsmul(data(), 1, &scale, data(), 1, length());
}
void AudioChannel::copyFrom(const AudioChannel* sourceChannel)
Modified: trunk/Source/WebCore/platform/audio/AudioChannel.h (104992 => 104993)
--- trunk/Source/WebCore/platform/audio/AudioChannel.h 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/platform/audio/AudioChannel.h 2012-01-13 22:42:46 UTC (rev 104993)
@@ -86,7 +86,7 @@
}
// Scales all samples by the same amount.
- void scale(double scale);
+ void scale(float scale);
// A simple memcpy() from the source channel
void copyFrom(const AudioChannel* sourceChannel);
Modified: trunk/Source/WebCore/webaudio/AudioBufferSourceNode.cpp (104992 => 104993)
--- trunk/Source/WebCore/webaudio/AudioBufferSourceNode.cpp 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/webaudio/AudioBufferSourceNode.cpp 2012-01-13 22:42:46 UTC (rev 104993)
@@ -128,7 +128,7 @@
renderFromBuffer(outputBus, quantumFrameOffset, bufferFramesToProcess);
// Apply the gain (in-place) to the output bus.
- double totalGain = gain()->value() * m_buffer->gain();
+ float totalGain = gain()->value() * m_buffer->gain();
outputBus->copyWithGainFrom(*outputBus, &m_lastGain, totalGain);
// If the end time is somewhere in the middle of this time quantum, then simply zero out the
Modified: trunk/Source/WebCore/webaudio/AudioBufferSourceNode.h (104992 => 104993)
--- trunk/Source/WebCore/webaudio/AudioBufferSourceNode.h 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/webaudio/AudioBufferSourceNode.h 2012-01-13 22:42:46 UTC (rev 104993)
@@ -129,7 +129,7 @@
double totalPitchRate();
// m_lastGain provides continuity when we dynamically adjust the gain.
- double m_lastGain;
+ float m_lastGain;
// We optionally keep track of a panner node which has a doppler shift that is incorporated into the pitch rate.
RefPtr<AudioPannerNode> m_pannerNode;
Modified: trunk/Source/WebCore/webaudio/AudioGainNode.h (104992 => 104993)
--- trunk/Source/WebCore/webaudio/AudioGainNode.h 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/webaudio/AudioGainNode.h 2012-01-13 22:42:46 UTC (rev 104993)
@@ -57,7 +57,7 @@
private:
AudioGainNode(AudioContext*, float sampleRate);
- double m_lastGain; // for de-zippering
+ float m_lastGain; // for de-zippering
RefPtr<AudioGain> m_gain;
AudioFloatArray m_sampleAccurateGainValues;
Modified: trunk/Source/WebCore/webaudio/AudioPannerNode.h (104992 => 104993)
--- trunk/Source/WebCore/webaudio/AudioPannerNode.h 2012-01-13 22:42:33 UTC (rev 104992)
+++ trunk/Source/WebCore/webaudio/AudioPannerNode.h 2012-01-13 22:42:46 UTC (rev 104993)
@@ -138,7 +138,7 @@
RefPtr<AudioGain> m_coneGain;
DistanceEffect m_distanceEffect;
ConeEffect m_coneEffect;
- double m_lastGain;
+ float m_lastGain;
unsigned m_connectionCount;
};