summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webaudio
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/webaudio')
-rw-r--r--Source/WebCore/Modules/webaudio/AudioContext.cpp15
-rw-r--r--Source/WebCore/Modules/webaudio/AudioParam.cpp34
-rw-r--r--Source/WebCore/Modules/webaudio/AudioParam.h8
-rw-r--r--Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp1
-rw-r--r--Source/WebCore/Modules/webaudio/ConvolverNode.idl2
-rw-r--r--Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp2
-rw-r--r--Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h4
-rw-r--r--Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h4
-rw-r--r--Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.idl2
-rw-r--r--Source/WebCore/Modules/webaudio/Oscillator.cpp12
-rw-r--r--Source/WebCore/Modules/webaudio/Oscillator.h2
-rw-r--r--Source/WebCore/Modules/webaudio/Oscillator.idl3
12 files changed, 57 insertions, 32 deletions
diff --git a/Source/WebCore/Modules/webaudio/AudioContext.cpp b/Source/WebCore/Modules/webaudio/AudioContext.cpp
index ab8e17228..599c8b61a 100644
--- a/Source/WebCore/Modules/webaudio/AudioContext.cpp
+++ b/Source/WebCore/Modules/webaudio/AudioContext.cpp
@@ -401,8 +401,19 @@ PassRefPtr<MediaStreamAudioSourceNode> AudioContext::createMediaStreamSource(Med
ASSERT(isMainThread());
lazyInitialize();
- // FIXME: For now we don't give it an AudioSourceProvider, so it will output silence.
- RefPtr<MediaStreamAudioSourceNode> node = MediaStreamAudioSourceNode::create(this, mediaStream, 0);
+ AudioSourceProvider* provider = 0;
+
+ if (mediaStream->isLocal() && mediaStream->audioTracks()->length())
+ provider = destination()->localAudioInputProvider();
+ else {
+ // FIXME: get a provider for non-local MediaStreams (like from a remote peer).
+ provider = 0;
+ }
+
+ RefPtr<MediaStreamAudioSourceNode> node = MediaStreamAudioSourceNode::create(this, mediaStream, provider);
+
+ // FIXME: Only stereo streams are supported right now. We should be able to accept multi-channel streams.
+ node->setFormat(2, sampleRate());
refNode(node.get()); // context keeps reference until node is disconnected
return node;
diff --git a/Source/WebCore/Modules/webaudio/AudioParam.cpp b/Source/WebCore/Modules/webaudio/AudioParam.cpp
index 15c67431d..c525b2e6c 100644
--- a/Source/WebCore/Modules/webaudio/AudioParam.cpp
+++ b/Source/WebCore/Modules/webaudio/AudioParam.cpp
@@ -94,6 +94,13 @@ bool AudioParam::smooth()
return false;
}
+float AudioParam::finalValue()
+{
+ float value;
+ calculateFinalValues(&value, 1, false);
+ return value;
+}
+
void AudioParam::calculateSampleAccurateValues(float* values, unsigned numberOfValues)
{
bool isSafe = context() && context()->isAudioThread() && values && numberOfValues;
@@ -101,31 +108,30 @@ void AudioParam::calculateSampleAccurateValues(float* values, unsigned numberOfV
if (!isSafe)
return;
- if (numberOfRenderingConnections())
- calculateAudioRateSignalValues(values, numberOfValues);
- else
- calculateTimelineValues(values, numberOfValues);
+ calculateFinalValues(values, numberOfValues, true);
}
-void AudioParam::calculateAudioRateSignalValues(float* values, unsigned numberOfValues)
+void AudioParam::calculateFinalValues(float* values, unsigned numberOfValues, bool sampleAccurate)
{
- bool isGood = numberOfRenderingConnections() && numberOfValues;
+ bool isGood = context() && context()->isAudioThread() && values && numberOfValues;
ASSERT(isGood);
if (!isGood)
return;
// 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.
+ if (sampleAccurate) {
+ // Calculate sample-accurate (a-rate) intrinsic values.
calculateTimelineValues(values, numberOfValues);
} else {
- // Otherwise set values array to our constant value.
- float value = m_value; // Cache in local.
+ // Calculate control-rate (k-rate) intrinsic value.
+ bool hasValue;
+ float timelineValue = m_timeline.valueForContextTime(context(), narrowPrecisionToFloat(m_value), hasValue);
+
+ if (hasValue)
+ m_value = timelineValue;
- // FIXME: can be optimized if we create a new VectorMath function.
- for (unsigned i = 0; i < numberOfValues; ++i)
- values[i] = value;
+ values[0] = narrowPrecisionToFloat(m_value);
}
// Now sum all of the audio-rate connections together (unity-gain summing junction).
@@ -138,7 +144,7 @@ void AudioParam::calculateAudioRateSignalValues(float* values, unsigned numberOf
ASSERT(output);
// Render audio from this output.
- AudioBus* connectionBus = output->pull(0, numberOfValues);
+ AudioBus* connectionBus = output->pull(0, AudioNode::ProcessingSizeInFrames);
// Sum, with unity-gain.
summingBus.sumFrom(*connectionBus);
diff --git a/Source/WebCore/Modules/webaudio/AudioParam.h b/Source/WebCore/Modules/webaudio/AudioParam.h
index 90fde3b52..7160b8297 100644
--- a/Source/WebCore/Modules/webaudio/AudioParam.h
+++ b/Source/WebCore/Modules/webaudio/AudioParam.h
@@ -56,9 +56,14 @@ public:
virtual bool canUpdateState() OVERRIDE { return true; }
virtual void didUpdate() OVERRIDE { }
+ // Intrinsic value.
float value();
void setValue(float);
+ // Final value for k-rate parameters, otherwise use calculateSampleAccurateValues() for a-rate.
+ // Must be called in the audio thread.
+ float finalValue();
+
String name() const { return m_name; }
float minValue() const { return static_cast<float>(m_minValue); }
@@ -112,7 +117,8 @@ protected:
}
private:
- void calculateAudioRateSignalValues(float* values, unsigned numberOfValues);
+ // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web Audio specification.
+ void calculateFinalValues(float* values, unsigned numberOfValues, bool sampleAccurate);
void calculateTimelineValues(float* values, unsigned numberOfValues);
String m_name;
diff --git a/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp b/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp
index c02121832..9b5c2c472 100644
--- a/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp
+++ b/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp
@@ -170,7 +170,6 @@ float AudioParamTimeline::valuesForTimeRangeImpl(float startTime,
return defaultValue;
// Return default value if there are no events matching the desired time range.
- ASSERT(m_events.size());
if (!m_events.size() || endTime <= m_events[0].time()) {
for (unsigned i = 0; i < numberOfValues; ++i)
values[i] = defaultValue;
diff --git a/Source/WebCore/Modules/webaudio/ConvolverNode.idl b/Source/WebCore/Modules/webaudio/ConvolverNode.idl
index 0f561f0ff..d1c2c5b7a 100644
--- a/Source/WebCore/Modules/webaudio/ConvolverNode.idl
+++ b/Source/WebCore/Modules/webaudio/ConvolverNode.idl
@@ -28,7 +28,7 @@ module audio {
Conditional=WEB_AUDIO,
JSGenerateToJSObject
] ConvolverNode : AudioNode {
- attribute [JSCustomSetter] AudioBuffer buffer;
+ attribute AudioBuffer buffer;
attribute boolean normalize;
};
}
diff --git a/Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp b/Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp
index 1f35e55a2..7838256a8 100644
--- a/Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp
+++ b/Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp
@@ -99,7 +99,7 @@ void DelayDSPKernel::process(const float* source, float* destination, size_t fra
return;
float sampleRate = this->sampleRate();
- double delayTime = delayProcessor() ? delayProcessor()->delayTime()->value() : m_desiredDelayFrames / sampleRate;
+ double delayTime = delayProcessor() ? delayProcessor()->delayTime()->finalValue() : m_desiredDelayFrames / sampleRate;
// Make sure the delay time is in a valid range.
delayTime = min(maxDelayTime(), delayTime);
diff --git a/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h b/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h
index cbf7b5024..0629ed6c4 100644
--- a/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h
+++ b/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h
@@ -25,7 +25,7 @@
#ifndef MediaElementAudioSourceNode_h
#define MediaElementAudioSourceNode_h
-#if ENABLE(VIDEO)
+#if ENABLE(WEB_AUDIO) && ENABLE(VIDEO)
#include "AudioSourceNode.h"
#include "AudioSourceProviderClient.h"
@@ -74,6 +74,6 @@ private:
} // namespace WebCore
-#endif // ENABLE(VIDEO)
+#endif // ENABLE(WEB_AUDIO) && ENABLE(VIDEO)
#endif // MediaElementAudioSourceNode_h
diff --git a/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h b/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h
index 8bdf28787..242e62122 100644
--- a/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h
+++ b/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h
@@ -25,7 +25,7 @@
#ifndef MediaStreamAudioSourceNode_h
#define MediaStreamAudioSourceNode_h
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_AUDIO) && ENABLE(MEDIA_STREAM)
#include "AudioSourceNode.h"
#include "AudioSourceProvider.h"
@@ -72,6 +72,6 @@ private:
} // namespace WebCore
-#endif // ENABLE(MEDIA_STREAM)
+#endif // ENABLE(WEB_AUDIO) && ENABLE(MEDIA_STREAM)
#endif // MediaStreamAudioSourceNode_h
diff --git a/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.idl b/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.idl
index 14b91a2c6..89e7e7888 100644
--- a/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.idl
+++ b/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.idl
@@ -24,7 +24,7 @@
module audio {
interface [
- Conditional=MEDIA_STREAM,
+ Conditional=WEB_AUDIO&MEDIA_STREAM,
JSGenerateToJSObject
] MediaStreamAudioSourceNode : AudioSourceNode {
readonly attribute MediaStream mediaStream;
diff --git a/Source/WebCore/Modules/webaudio/Oscillator.cpp b/Source/WebCore/Modules/webaudio/Oscillator.cpp
index ecbd4db9b..bad1bd714 100644
--- a/Source/WebCore/Modules/webaudio/Oscillator.cpp
+++ b/Source/WebCore/Modules/webaudio/Oscillator.cpp
@@ -31,6 +31,7 @@
#include "AudioContext.h"
#include "AudioNodeOutput.h"
#include "AudioUtilities.h"
+#include "ExceptionCode.h"
#include "VectorMath.h"
#include "WaveTable.h"
#include <algorithm>
@@ -68,7 +69,8 @@ Oscillator::Oscillator(AudioContext* context, float sampleRate)
m_detune = AudioParam::create(context, "detune", 0, -4800, 4800);
// Sets up default wavetable.
- setType(m_type);
+ ExceptionCode ec;
+ setType(m_type, ec);
// An oscillator is always mono.
addOutput(adoptPtr(new AudioNodeOutput(this, 1)));
@@ -81,7 +83,7 @@ Oscillator::~Oscillator()
uninitialize();
}
-void Oscillator::setType(unsigned short type)
+void Oscillator::setType(unsigned short type, ExceptionCode& ec)
{
WaveTable* waveTable = 0;
float sampleRate = this->sampleRate();
@@ -109,10 +111,10 @@ void Oscillator::setType(unsigned short type)
break;
case CUSTOM:
default:
- // FIXME: throw exception for invalid types or if the type is CUSTOM since setWaveTable()
- // method must be called explicitly in that case.
+ // Throw exception for invalid types, including CUSTOM since setWaveTable() method must be
+ // called explicitly.
+ ec = NOT_SUPPORTED_ERR;
return;
- break;
}
setWaveTable(waveTable);
diff --git a/Source/WebCore/Modules/webaudio/Oscillator.h b/Source/WebCore/Modules/webaudio/Oscillator.h
index 127b31b2d..3dacab951 100644
--- a/Source/WebCore/Modules/webaudio/Oscillator.h
+++ b/Source/WebCore/Modules/webaudio/Oscillator.h
@@ -61,7 +61,7 @@ public:
virtual void reset();
unsigned short type() const { return m_type; }
- void setType(unsigned short);
+ void setType(unsigned short, ExceptionCode&);
AudioParam* frequency() { return m_frequency.get(); }
AudioParam* detune() { return m_detune.get(); }
diff --git a/Source/WebCore/Modules/webaudio/Oscillator.idl b/Source/WebCore/Modules/webaudio/Oscillator.idl
index fb68e401c..f8e2a8892 100644
--- a/Source/WebCore/Modules/webaudio/Oscillator.idl
+++ b/Source/WebCore/Modules/webaudio/Oscillator.idl
@@ -36,7 +36,8 @@ module audio {
const unsigned short TRIANGLE = 3;
const unsigned short CUSTOM = 4;
- attribute unsigned short type;
+ attribute unsigned short type
+ setter raises(DOMException);
// Playback state constants.
const unsigned short UNSCHEDULED_STATE = 0;