Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
AudioParam must support connections from audio-rate signals
https://bugs.webkit.org/show_bug.cgi?id=83524 Source/WebCore: Reviewed by Eric Carlson. In the Web Audio API, it's possible to connect one AudioNode to another AudioNode. Similary we should allow an AudioNode to connect to an AudioParam, thus controlling a parameter with an audio-rate signal. This is important in many audio processing applications. Test: webaudio/audioparam-connect-audioratesignal.html Simple method name change of AudioParam::hasTimelineValues() to AudioParam::hasSampleAccurateValues(). * Modules/webaudio/AudioGainNode.cpp: (WebCore::AudioGainNode::process): * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::connect): Add connect() method from AudioNode -> AudioParam. (WebCore): (WebCore::AudioNode::disconnect): (WebCore::AudioNode::finishDeref): Use AudioNodeOutput::disconnectAll() instead of AudioNodeOutput::disconnectAllInputs(). * Modules/webaudio/AudioNode.h: Add connect() method from AudioNode -> AudioParam. (WebCore): (AudioNode): * Modules/webaudio/AudioNode.idl: Add connect() method from AudioNode -> AudioParam. Implement support for an AudioNodeOutput to fanout to multiple AudioParams. * Modules/webaudio/AudioNodeOutput.cpp: (WebCore::AudioNodeOutput::AudioNodeOutput): (WebCore::AudioNodeOutput::updateRenderingState): Update rendering state related to AudioParams. (WebCore::AudioNodeOutput::pull): pull() must now take into account fanout to AudioParams for in-place processing. (WebCore::AudioNodeOutput::fanOutCount): (WebCore): (WebCore::AudioNodeOutput::paramFanOutCount): New method keeping track of number of connections to AudioParams. (WebCore::AudioNodeOutput::renderingParamFanOutCount): New method keeping track of number of connections to AudioParams for rendering. (WebCore::AudioNodeOutput::addParam): Add a connection to an AudioParam. (WebCore::AudioNodeOutput::removeParam): Remove a connection to an AudioParam. (WebCore::AudioNodeOutput::disconnectAllParams): Remove all connections to AudioParams. (WebCore::AudioNodeOutput::disconnectAll): New method to disconnect all AudioNodeInputs and AudioParams. * Modules/webaudio/AudioNodeOutput.h: (AudioNodeOutput): Allow an AudioParam to accept a connection from an AudioNodeOutput, thus being controlled by an audio-rate signal. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::calculateSampleAccurateValues): Calculates sample-accurate values from timeline or an AudioNode. (WebCore): (WebCore::AudioParam::calculateAudioRateSignalValues): Calculates sample-accurate values from an AudioNode. (WebCore::AudioParam::calculateTimelineValues): Calculates sample-accurate values scheduled on the timeline. (WebCore::AudioParam::connect): Connect from an AudioNodeOutput for control from an audio-rate signal. (WebCore::AudioParam::disconnect): Disconnect from an AudioNodeOutput. * Modules/webaudio/AudioParam.h: (WebCore): (WebCore::AudioParam::AudioParam): (WebCore::AudioParam::hasSampleAccurateValues): Change name from hasTimelineValues() and return true either if we have timeline values or if we've been connected from an AudioNode. (AudioParam): Simple method name change of AudioParam::hasTimelineValues() to AudioParam::hasSampleAccurateValues(). * Modules/webaudio/Oscillator.cpp: (WebCore::Oscillator::calculateSampleAccuratePhaseIncrements): (WebCore::Oscillator::process): LayoutTests: Reviewed by Eric Carlson. * webaudio/audioparam-connect-audioratesignal-expected.txt: Added. * webaudio/audioparam-connect-audioratesignal.html: Added. * webaudio/resources/audio-testing.js: (createLinearRampBuffer): (createConstantBuffer): Canonical link: https://commits.webkit.org/101068@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@113769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Chris Rogers
committed
Apr 10, 2012
1 parent
2a760a0
commit cb7e833
Showing
14 changed files
with
432 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
LayoutTests/webaudio/audioparam-connect-audioratesignal-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PASS Rendered signal is of correct length. | ||
PASS Rendered signal exactly matches the audio-rate gain changing signal. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
112 changes: 112 additions & 0 deletions
112
LayoutTests/webaudio/audioparam-connect-audioratesignal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<!DOCTYPE html> | ||
|
||
<!-- | ||
Tests that an audio-rate signal (AudioNode output) can be connected to an AudioParam. | ||
Specifically, this tests that an audio-rate signal coming from an AudioBufferSourceNode | ||
playing an AudioBuffer containing a specific curve can be connected to an AudioGainNode's | ||
.gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audio source | ||
having its gain changed. We load this one with an AudioBuffer containing a constant value of 1. | ||
Thus it's easy to check that the resultant signal should be equal to the gain-scaling curve. | ||
--> | ||
|
||
<html> | ||
<head> | ||
<link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/> | ||
<script src="resources/audio-testing.js"></script> | ||
<script src="../fast/js/resources/js-test-pre.js"></script> | ||
|
||
</head> | ||
<body> | ||
|
||
<script> | ||
|
||
var sampleRate = 44100.0; | ||
var lengthInSeconds = 1; | ||
|
||
var context = 0; | ||
var constantOneBuffer = 0; | ||
var linearRampBuffer = 0; | ||
|
||
function checkResult(event) { | ||
var renderedBuffer = event.renderedBuffer; | ||
var renderedData = renderedBuffer.getChannelData(0); | ||
var expectedData = linearRampBuffer.getChannelData(0); | ||
var n = renderedBuffer.length; | ||
|
||
if (n == linearRampBuffer.length) { | ||
testPassed("Rendered signal is of correct length."); | ||
} else { | ||
testFailed("Rendered signal is not of correct length."); | ||
} | ||
|
||
// Check that the rendered result exactly matches the buffer used to control gain. | ||
// This is because we're changing the gain of a signal having constant value 1. | ||
var success = true; | ||
for (var i = 0; i < n; ++i) { | ||
if (renderedData[i] != expectedData[i]) { | ||
success = false; | ||
break; | ||
} | ||
} | ||
|
||
if (success) { | ||
testPassed("Rendered signal exactly matches the audio-rate gain changing signal."); | ||
} else { | ||
testFailed("Rendered signal differs from the audio-rate gain changing signal."); | ||
} | ||
|
||
finishJSTest(); | ||
} | ||
|
||
function runTest() { | ||
if (window.layoutTestController) { | ||
layoutTestController.dumpAsText(); | ||
layoutTestController.waitUntilDone(); | ||
} | ||
|
||
window.jsTestIsAsync = true; | ||
|
||
var sampleFrameLength = sampleRate * lengthInSeconds; | ||
|
||
// Create offline audio context. | ||
context = new webkitAudioContext(1, sampleFrameLength, sampleRate); | ||
|
||
// Create buffer used by the source which will have its gain controlled. | ||
constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1); | ||
|
||
// Create buffer used to control gain. | ||
linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength); | ||
|
||
// Create the two sources. | ||
|
||
var constantSource = context.createBufferSource(); | ||
constantSource.buffer = constantOneBuffer; | ||
|
||
var gainChangingSource = context.createBufferSource(); | ||
gainChangingSource.buffer = linearRampBuffer; | ||
|
||
// Create a gain node controlling the gain of constantSource and make the connections. | ||
var gainNode = context.createGainNode(); | ||
constantSource.connect(gainNode); | ||
gainNode.connect(context.destination); | ||
|
||
// Connect an audio-rate signal to control the .gain AudioParam. | ||
// This is the heart of what is being tested. | ||
gainChangingSource.connect(gainNode.gain); | ||
|
||
// Start both sources at time 0. | ||
constantSource.noteOn(0); | ||
gainChangingSource.noteOn(0); | ||
|
||
context.oncomplete = checkResult; | ||
context.startRendering(); | ||
} | ||
|
||
runTest(); | ||
successfullyParsed = true; | ||
|
||
</script> | ||
<script src="../fast/js/resources/js-test-post.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.