diff options
| author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
| commit | a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch) | |
| tree | b7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/WebCore/Modules/webaudio | |
| parent | 8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff) | |
| download | qtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz | |
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/WebCore/Modules/webaudio')
| -rw-r--r-- | Source/WebCore/Modules/webaudio/AudioNodeOutput.cpp | 9 | ||||
| -rw-r--r-- | Source/WebCore/Modules/webaudio/AudioParam.cpp | 82 | ||||
| -rw-r--r-- | Source/WebCore/Modules/webaudio/AudioParam.h | 18 |
3 files changed, 61 insertions, 48 deletions
diff --git a/Source/WebCore/Modules/webaudio/AudioNodeOutput.cpp b/Source/WebCore/Modules/webaudio/AudioNodeOutput.cpp index 4ea56e7dd..19eba64b2 100644 --- a/Source/WebCore/Modules/webaudio/AudioNodeOutput.cpp +++ b/Source/WebCore/Modules/webaudio/AudioNodeOutput.cpp @@ -218,10 +218,11 @@ void AudioNodeOutput::disconnectAllParams() { ASSERT(context()->isGraphOwner()); - for (ParamsIterator it = m_params.begin(); it != m_params.end(); ++it) - (*it)->disconnect(this); - - m_params.clear(); + // AudioParam::disconnect() changes m_params by calling removeParam(). + while (!m_params.isEmpty()) { + AudioParam* param = m_params.begin()->get(); + param->disconnect(this); + } } void AudioNodeOutput::disconnectAll() diff --git a/Source/WebCore/Modules/webaudio/AudioParam.cpp b/Source/WebCore/Modules/webaudio/AudioParam.cpp index dec708782..15c67431d 100644 --- a/Source/WebCore/Modules/webaudio/AudioParam.cpp +++ b/Source/WebCore/Modules/webaudio/AudioParam.cpp @@ -101,7 +101,7 @@ void AudioParam::calculateSampleAccurateValues(float* values, unsigned numberOfV if (!isSafe) return; - if (m_audioRateSignal) + if (numberOfRenderingConnections()) calculateAudioRateSignalValues(values, numberOfValues); else calculateTimelineValues(values, numberOfValues); @@ -109,26 +109,40 @@ void AudioParam::calculateSampleAccurateValues(float* values, unsigned numberOfV void AudioParam::calculateAudioRateSignalValues(float* values, unsigned numberOfValues) { - // FIXME: support fan-in (multiple audio connections to this parameter with unity-gain summing). - // https://bugs.webkit.org/show_bug.cgi?id=83610 - ASSERT(m_audioRateSignal); - - AudioBus* bus = m_audioRateSignal->pull(0, numberOfValues); - bool isBusGood = bus && bus->numberOfChannels() && bus->length() >= numberOfValues; - ASSERT(isBusGood); - if (!isBusGood) + bool isGood = numberOfRenderingConnections() && numberOfValues; + ASSERT(isGood); + if (!isGood) return; - if (bus->numberOfChannels() == 1) { - // The normal case is to deal with a mono audio-rate signal. - memcpy(values, bus->channel(0)->data(), sizeof(float) * numberOfValues); + // The calculated result will be the "intrinsic" value summed with all audio-rate connections. + + if (m_timeline.hasValues()) { + // Calculate regular timeline values, if we have any. + calculateTimelineValues(values, numberOfValues); } else { - // Do a standard mixdown to one channel if necessary. - AudioBus wrapperBus(1, numberOfValues, false); - wrapperBus.setChannelMemory(0, values, numberOfValues); - wrapperBus.copyFrom(*bus); // Mixdown. + // Otherwise set values array to our constant value. + float value = m_value; // Cache in local. + + // FIXME: can be optimized if we create a new VectorMath function. + for (unsigned i = 0; i < numberOfValues; ++i) + values[i] = value; + } + + // Now sum all of the audio-rate connections together (unity-gain summing junction). + // Note that connections would normally be mono, but we mix down to mono if necessary. + AudioBus summingBus(1, numberOfValues, false); + summingBus.setChannelMemory(0, values, numberOfValues); + + for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) { + AudioNodeOutput* output = renderingOutput(i); + ASSERT(output); + + // Render audio from this output. + AudioBus* connectionBus = output->pull(0, numberOfValues); + + // Sum, with unity-gain. + summingBus.sumFrom(*connectionBus); } - m_value = values[0]; // Update to first value. } void AudioParam::calculateTimelineValues(float* values, unsigned numberOfValues) @@ -144,33 +158,35 @@ void AudioParam::calculateTimelineValues(float* values, unsigned numberOfValues) m_value = m_timeline.valuesForTimeRange(startTime, endTime, narrowPrecisionToFloat(m_value), values, numberOfValues, sampleRate, sampleRate); } -void AudioParam::connect(AudioNodeOutput* audioRateSignal) +void AudioParam::connect(AudioNodeOutput* output) { ASSERT(context()->isGraphOwner()); - ASSERT(audioRateSignal); - if (!audioRateSignal) + + ASSERT(output); + if (!output) return; - if (m_audioRateSignal && m_audioRateSignal != audioRateSignal) { - // Because we don't currently support fan-in we must explicitly disconnect from an old output. - m_audioRateSignal->removeParam(this); - } + if (m_outputs.contains(output)) + return; - audioRateSignal->addParam(this); - m_audioRateSignal = audioRateSignal; + output->addParam(this); + m_outputs.add(output); + changedOutputs(); } -void AudioParam::disconnect(AudioNodeOutput* audioRateSignal) +void AudioParam::disconnect(AudioNodeOutput* output) { ASSERT(context()->isGraphOwner()); - ASSERT(audioRateSignal); - if (!audioRateSignal) + + ASSERT(output); + if (!output) return; - // FIXME: support fan-in (multiple audio connections to this parameter with unity-gain summing). - // https://bugs.webkit.org/show_bug.cgi?id=83610 - if (m_audioRateSignal == audioRateSignal) - m_audioRateSignal = 0; + if (m_outputs.contains(output)) { + m_outputs.remove(output); + changedOutputs(); + output->removeParam(this); + } } } // namespace WebCore diff --git a/Source/WebCore/Modules/webaudio/AudioParam.h b/Source/WebCore/Modules/webaudio/AudioParam.h index 3bd27abd8..90fde3b52 100644 --- a/Source/WebCore/Modules/webaudio/AudioParam.h +++ b/Source/WebCore/Modules/webaudio/AudioParam.h @@ -31,6 +31,7 @@ #include "AudioContext.h" #include "AudioParamTimeline.h" +#include "AudioSummingJunction.h" #include "PlatformString.h" #include <sys/types.h> #include <wtf/Float32Array.h> @@ -41,7 +42,7 @@ namespace WebCore { class AudioNodeOutput; -class AudioParam : public RefCounted<AudioParam> { +class AudioParam : public AudioSummingJunction, public RefCounted<AudioParam> { public: static const double DefaultSmoothingConstant; static const double SnapThreshold; @@ -51,7 +52,9 @@ public: return adoptRef(new AudioParam(context, name, defaultValue, minValue, maxValue, units)); } - AudioContext* context() { return m_context.get(); } + // AudioSummingJunction + virtual bool canUpdateState() OVERRIDE { return true; } + virtual void didUpdate() OVERRIDE { } float value(); void setValue(float); @@ -84,7 +87,7 @@ public: void setValueCurveAtTime(Float32Array* curve, float time, float duration) { m_timeline.setValueCurveAtTime(curve, time, duration); } void cancelScheduledValues(float startTime) { m_timeline.cancelScheduledValues(startTime); } - bool hasSampleAccurateValues() { return m_timeline.hasValues() || m_audioRateSignal; } + bool hasSampleAccurateValues() { return m_timeline.hasValues() || numberOfRenderingConnections(); } // Calculates numberOfValues parameter values starting at the context's current time. // Must be called in the context's render thread. @@ -96,7 +99,7 @@ public: protected: AudioParam(AudioContext* context, const String& name, double defaultValue, double minValue, double maxValue, unsigned units = 0) - : m_context(context) + : AudioSummingJunction(context) , m_name(name) , m_value(defaultValue) , m_defaultValue(defaultValue) @@ -105,7 +108,6 @@ protected: , m_units(units) , m_smoothedValue(defaultValue) , m_smoothingConstant(DefaultSmoothingConstant) - , m_audioRateSignal(0) { } @@ -113,7 +115,6 @@ private: void calculateAudioRateSignalValues(float* values, unsigned numberOfValues); void calculateTimelineValues(float* values, unsigned numberOfValues); - RefPtr<AudioContext> m_context; String m_name; double m_value; double m_defaultValue; @@ -126,11 +127,6 @@ private: double m_smoothingConstant; AudioParamTimeline m_timeline; - - // An audio-rate signal directly providing parameter values. - // FIXME: support fan-in (multiple audio connections to this parameter with unity-gain summing). - // https://bugs.webkit.org/show_bug.cgi?id=83610 - AudioNodeOutput* m_audioRateSignal; }; } // namespace WebCore |
