Skip to content

Commit

Permalink
AudioParam must support k-rate processing with audio-rate connections
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=94385

Reviewed by Kenneth Russell.

Fully implement AudioParam *final* value calculation according to spec:
https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioParam

In particular, this covers the case where the parameter is k-rate, and we also
have audio-rate connections to the AudioParam.

* Modules/webaudio/AudioParam.cpp:
(WebCore::AudioParam::finalValue):
(WebCore):
(WebCore::AudioParam::calculateSampleAccurateValues):
(WebCore::AudioParam::calculateFinalValues):
* Modules/webaudio/AudioParam.h:
(AudioParam):
* Modules/webaudio/DelayDSPKernel.cpp:
(WebCore::DelayDSPKernel::process):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@125957 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Chris Rogers committed Aug 18, 2012
1 parent 2005f64 commit b57d644
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
23 changes: 23 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
2012-08-17 Chris Rogers <crogers@google.com>

AudioParam must support k-rate processing with audio-rate connections
https://bugs.webkit.org/show_bug.cgi?id=94385

Reviewed by Kenneth Russell.

Fully implement AudioParam *final* value calculation according to spec:
https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioParam

In particular, this covers the case where the parameter is k-rate, and we also
have audio-rate connections to the AudioParam.

* Modules/webaudio/AudioParam.cpp:
(WebCore::AudioParam::finalValue):
(WebCore):
(WebCore::AudioParam::calculateSampleAccurateValues):
(WebCore::AudioParam::calculateFinalValues):
* Modules/webaudio/AudioParam.h:
(AudioParam):
* Modules/webaudio/DelayDSPKernel.cpp:
(WebCore::DelayDSPKernel::process):

2012-08-17 Alice Cheng <alice_cheng@apple.com>

Preserve styling elements in DeleteSelectionCommand
Expand Down
34 changes: 20 additions & 14 deletions Source/WebCore/Modules/webaudio/AudioParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,44 @@ 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;
ASSERT(isSafe);
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).
Expand All @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion Source/WebCore/Modules/webaudio/AudioParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ class AudioParam : public AudioSummingJunction, public RefCounted<AudioParam> {
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); }
Expand Down Expand Up @@ -112,7 +117,8 @@ class AudioParam : public AudioSummingJunction, public RefCounted<AudioParam> {
}

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;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/webaudio/DelayDSPKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b57d644

Please sign in to comment.