-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Differential Revision: https://phabricator.services.mozilla.com/D84667 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1613833 gecko-commit: a93c24810dce7ea4a063abd6fff6b7d0d56a828d gecko-integration-branch: autoland gecko-reviewers: padenot
- Loading branch information
1 parent
d408bf7
commit e35de4d
Showing
1 changed file
with
130 additions
and
0 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
webaudio/the-audio-api/the-periodicwave-interface/periodicWave.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,130 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title> | ||
Test Constructor: MediaStreamAudioDestinationNode | ||
</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/webaudio/resources/audit-util.js"></script> | ||
<script src="/webaudio/resources/audit.js"></script> | ||
</head> | ||
<body> | ||
<script id="layout-test-code"> | ||
// real and imag are used in separate PeriodicWaves to make their peak values | ||
// easy to determine. | ||
const realMax = 99; | ||
var real = new Float32Array(realMax + 1); | ||
real[1] = 2.0; // fundamental | ||
real[realMax] = 3.0; | ||
const realPeak = real[1] + real[realMax]; | ||
const realFundamental = 19.0; | ||
var imag = new Float32Array(4); | ||
imag[0] = 6.0; // should be ignored. | ||
imag[3] = 0.5; | ||
const imagPeak = imag[3]; | ||
const imagFundamental = 551.0; | ||
|
||
const testLength = 4096; | ||
let context = new AudioContext(); | ||
|
||
let audit = Audit.createTaskRunner(); | ||
|
||
// Create with the factory method | ||
|
||
audit.define('create with factory method', (task, should) => { | ||
should(() => { | ||
context.createPeriodicWave(new Float32Array(4096), new Float32Array(4096)); | ||
}, 'context.createPeriodicWave(new Float32Array(4096), ' + | ||
'new Float32Array(4096))').notThrow(); | ||
task.done(); | ||
}); | ||
|
||
audit.define('different length with factory method', (task, should) => { | ||
should(() => { | ||
context.createPeriodicWave(new Float32Array(512), new Float32Array(4)); | ||
}, 'context.createPeriodicWave(new Float32Array(512), ' + | ||
'new Float32Array(4))').throw(DOMException, "IndexSizeError"); | ||
task.done(); | ||
}); | ||
|
||
audit.define('too small with factory method', (task, should) => { | ||
should(() => { | ||
context.createPeriodicWave(new Float32Array(1), new Float32Array(1)); | ||
}, 'context.createPeriodicWave(new Float32Array(1), ' + | ||
'new Float32Array(1))').throw(DOMException, "IndexSizeError"); | ||
task.done(); | ||
}); | ||
|
||
// Create with the constructor | ||
|
||
audit.define('create with constructor', (task, should) => { | ||
should(() => { | ||
new PeriodicWave(context, { real: new Float32Array(4096), imag: new Float32Array(4096) }); | ||
}, 'new PeriodicWave(context, { real : new Float32Array(4096), ' + | ||
'imag : new Float32Array(4096) })').notThrow(); | ||
task.done(); | ||
}); | ||
|
||
audit.define('different length with constructor', (task, should) => { | ||
should(() => { | ||
new PeriodicWave(context, { real: new Float32Array(4096), imag: new Float32Array(4) }); | ||
}, 'new PeriodicWave(context, { real : new Float32Array(4096), ' + | ||
'imag : new Float32Array(4) })').throw(DOMException, "IndexSizeError"); | ||
task.done(); | ||
}); | ||
|
||
audit.define('too small with constructor', (task, should) => { | ||
should(() => { | ||
new PeriodicWave(context, { real: new Float32Array(1), imag: new Float32Array(1) }); | ||
}, 'new PeriodicWave(context, { real : new Float32Array(1), ' + | ||
'imag : new Float32Array(1) })').throw(DOMException, "IndexSizeError"); | ||
task.done(); | ||
}); | ||
|
||
audit.define('output test', (task, should) => { | ||
let context = new OfflineAudioContext(2, 4096, 44100); | ||
// Create the expected output buffer | ||
let expectations = context.createBuffer(2, testLength, context.sampleRate); | ||
for (var i = 0; i < expectations.length; ++i) { | ||
|
||
expectations.getChannelData(0)[i] = 1.0 / realPeak * | ||
(real[1] * Math.cos(2 * Math.PI * realFundamental * i / | ||
context.sampleRate) + | ||
real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i / | ||
context.sampleRate)); | ||
|
||
expectations.getChannelData(1)[i] = 1.0 / imagPeak * | ||
imag[3] * Math.sin(2 * Math.PI * 3 * imagFundamental * i / | ||
context.sampleRate); | ||
} | ||
|
||
// Create the real output buffer | ||
let merger = context.createChannelMerger(); | ||
|
||
let osc1 = context.createOscillator(); | ||
let osc2 = context.createOscillator(); | ||
|
||
osc1.setPeriodicWave(context.createPeriodicWave( | ||
real, new Float32Array(real.length))); | ||
osc2.setPeriodicWave(context.createPeriodicWave( | ||
new Float32Array(imag.length), imag)); | ||
osc1.frequency.value = realFundamental; | ||
osc2.frequency.value = imagFundamental; | ||
|
||
osc1.start(); | ||
osc2.start(); | ||
|
||
osc1.connect(merger, 0, 0); | ||
osc2.connect(merger, 0, 1); | ||
|
||
context.startRendering().then(reality => { | ||
should(reality, 'rendering PeriodicWave').beEqualToArray(expectations); | ||
task.done(); | ||
}); | ||
}); | ||
|
||
audit.run(); | ||
</script> | ||
</body> | ||
</html> |