Commit 7f7f418b authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Make WaveShaper test output more self-explanatory

When reading the output of the waveshaper tests, it's kind of hard to
tell exactly what's being tested.  Add a few more test messages and/or
labels to make it a bit clearer.

Bug: 789197
Test: WaveShaper/waveshaper-{copy-curve,simple}.html
Change-Id: Ic90ebe94282d4b416321766bc16daa3cbc53299c
Reviewed-on: https://chromium-review.googlesource.com/794018
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519891}
parent b3052a4a
......@@ -18,70 +18,81 @@
let audit = Audit.createTaskRunner();
audit.define('test copying', (task, should) => {
// Two-channel context; channel 0 contains the test data and channel 1
// contains the expected result. Channel 1 has the normal WaveShaper
// output and channel 0 has the WaveShaper output with a modified curve.
let context = new OfflineAudioContext(2, renderFrames, sampleRate);
// Just use a default oscillator as the source. Doesn't really matter
// what we use.
let src = context.createOscillator();
src.type = 'sawtooth';
// Create the wave shapers: ws0 is the test shaper, and ws1 is the
// reference wave shaper.
let ws0 = context.createWaveShaper();
let ws1 = context.createWaveShaper();
// Wave shaper curves. Doesn't really matter what we use as long as it
// modifies the input in some way. Thus, keep it simple and just invert
// the input.
let desiredCurve = [1, 0, -1];
let curve0 = Float32Array.from(desiredCurve);
let curve1 = Float32Array.from(desiredCurve);
ws0.curve = curve0;
ws1.curve = curve1;
let merger = context.createChannelMerger(2);
// Connect the graph
src.connect(ws0);
src.connect(ws1);
ws0.connect(merger, 0, 0);
ws1.connect(merger, 0, 1);
merger.connect(context.destination);
// Let the context run for a bit and then modify the curve for ws0.
// Doesn't really matter what we modify the curve to as long as it's
// different.
context.suspend(256 / context.sampleRate)
.then(function() {
curve0[0] = -0.5;
curve0[1] = 0.125;
curve0[2] = 0.75;
})
.then(context.resume.bind(context));
src.start();
context.startRendering()
.then(function(renderedBuffer) {
let actual = renderedBuffer.getChannelData(0);
let expected = renderedBuffer.getChannelData(1);
// Modifying the wave shaper curve should not modify the output so
// the outputs from the two wave shaper nodes should be exactly
// identical.
should(actual, 'WaveShaper with modified curve')
.beEqualToArray(expected);
})
.then(() => task.done());
});
audit.define(
{
label: 'test copying',
description: 'Modifying curve should not modify WaveShaper'
},
(task, should) => {
// Two-channel context; channel 0 contains the test data and channel
// 1 contains the expected result. Channel 1 has the normal
// WaveShaper output and channel 0 has the WaveShaper output with a
// modified curve.
let context = new OfflineAudioContext(2, renderFrames, sampleRate);
// Just use a default oscillator as the source. Doesn't really
// matter what we use.
let src = context.createOscillator();
src.type = 'sawtooth';
// Create the wave shapers: ws0 is the test shaper, and ws1 is the
// reference wave shaper.
let ws0 = context.createWaveShaper();
let ws1 = context.createWaveShaper();
// Wave shaper curves. Doesn't really matter what we use as long as
// it modifies the input in some way. Thus, keep it simple and just
// invert the input.
let desiredCurve = [1, 0, -1];
let curve0 = Float32Array.from(desiredCurve);
let curve1 = Float32Array.from(desiredCurve);
ws0.curve = curve0;
ws1.curve = curve1;
let merger = context.createChannelMerger(2);
// Connect the graph
src.connect(ws0);
src.connect(ws1);
ws0.connect(merger, 0, 0);
ws1.connect(merger, 0, 1);
merger.connect(context.destination);
// Let the context run for a bit and then modify the curve for ws0.
// Doesn't really matter what we modify the curve to as long as it's
// different.
context.suspend(256 / context.sampleRate)
.then(() => {
should(
() => {
curve0[0] = -0.5;
curve0[1] = 0.125;
curve0[2] = 0.75;
},
`Modifying curve array at time ${context.currentTime}`)
.notThrow();
})
.then(context.resume.bind(context));
src.start();
context.startRendering()
.then(function(renderedBuffer) {
let actual = renderedBuffer.getChannelData(0);
let expected = renderedBuffer.getChannelData(1);
// Modifying the wave shaper curve should not modify the
// output so the outputs from the two wave shaper nodes should
// be exactly identical.
should(actual, 'Output of WaveShaper with modified curve')
.beEqualToArray(expected);
})
.then(() => task.done());
});
audit.run();
</script>
......
......@@ -18,30 +18,38 @@
let shaper = context.createWaveShaper();
// Verify default values are correct.
should(shaper.curve, 'WaveShaper.curve').beEqualTo(null);
should(shaper.oversample, 'WaveShaper.oversample').beEqualTo('none');
should(shaper.curve, 'Initial WaveShaper.curve').beEqualTo(null);
should(shaper.oversample, 'Initial WaveShaper.oversample')
.beEqualTo('none');
// Set oversample and verify that it is set correctly.
shaper.oversample = '2x';
should(() => shaper.oversample = '2x', 'Setting oversample to "2x"')
.notThrow();
should(shaper.oversample, 'Waveshaper.oversample = "2x"')
.beEqualTo('2x');
shaper.oversample = '4x';
should(() => shaper.oversample = '4x', 'Setting oversample to "4x"')
.notThrow();
should(shaper.oversample, 'Waveshaper.oversample = "4x"')
.beEqualTo('4x');
shaper.oversample = 'invalid';
should(
() => shaper.oversample = 'invalid',
'Setting oversample to "invalid"')
.notThrow();
should(shaper.oversample, 'Waveshaper.oversample = "invalid"')
.beEqualTo('4x');
// Set the curve and verify that the returned curve is the same as what
// it was set to.
let curve = Float32Array.from([-1, 0.25, .75]);
shaper.curve = curve;
should(() => shaper.curve = curve, 'Setting curve to [' + curve + ']')
.notThrow();
should(shaper.curve, 'WaveShaper.curve').beEqualToArray(curve);
// Verify setting the curve to null works.
shaper.curve = null;
should(() => shaper.curve = null, 'Setting curve back to null')
.notThrow();
should(shaper.curve, 'Waveshaper.curve = null').beEqualTo(null);
task.done();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment