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 @@ ...@@ -18,70 +18,81 @@
let audit = Audit.createTaskRunner(); let audit = Audit.createTaskRunner();
audit.define('test copying', (task, should) => { audit.define(
// Two-channel context; channel 0 contains the test data and channel 1 {
// contains the expected result. Channel 1 has the normal WaveShaper label: 'test copying',
// output and channel 0 has the WaveShaper output with a modified curve. description: 'Modifying curve should not modify WaveShaper'
let context = new OfflineAudioContext(2, renderFrames, sampleRate); },
(task, should) => {
// Just use a default oscillator as the source. Doesn't really matter // Two-channel context; channel 0 contains the test data and channel
// what we use. // 1 contains the expected result. Channel 1 has the normal
let src = context.createOscillator(); // WaveShaper output and channel 0 has the WaveShaper output with a
src.type = 'sawtooth'; // modified curve.
let context = new OfflineAudioContext(2, renderFrames, sampleRate);
// Create the wave shapers: ws0 is the test shaper, and ws1 is the
// reference wave shaper. // Just use a default oscillator as the source. Doesn't really
let ws0 = context.createWaveShaper(); // matter what we use.
let ws1 = context.createWaveShaper(); let src = context.createOscillator();
src.type = 'sawtooth';
// 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 // Create the wave shapers: ws0 is the test shaper, and ws1 is the
// the input. // reference wave shaper.
let desiredCurve = [1, 0, -1]; let ws0 = context.createWaveShaper();
let curve0 = Float32Array.from(desiredCurve); let ws1 = context.createWaveShaper();
let curve1 = Float32Array.from(desiredCurve);
// Wave shaper curves. Doesn't really matter what we use as long as
ws0.curve = curve0; // it modifies the input in some way. Thus, keep it simple and just
ws1.curve = curve1; // invert the input.
let desiredCurve = [1, 0, -1];
let merger = context.createChannelMerger(2); let curve0 = Float32Array.from(desiredCurve);
let curve1 = Float32Array.from(desiredCurve);
// Connect the graph
src.connect(ws0); ws0.curve = curve0;
src.connect(ws1); ws1.curve = curve1;
ws0.connect(merger, 0, 0); let merger = context.createChannelMerger(2);
ws1.connect(merger, 0, 1);
// Connect the graph
merger.connect(context.destination); src.connect(ws0);
src.connect(ws1);
// 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 ws0.connect(merger, 0, 0);
// different. ws1.connect(merger, 0, 1);
context.suspend(256 / context.sampleRate)
.then(function() { merger.connect(context.destination);
curve0[0] = -0.5;
curve0[1] = 0.125; // Let the context run for a bit and then modify the curve for ws0.
curve0[2] = 0.75; // Doesn't really matter what we modify the curve to as long as it's
}) // different.
.then(context.resume.bind(context)); context.suspend(256 / context.sampleRate)
.then(() => {
src.start(); should(
() => {
context.startRendering() curve0[0] = -0.5;
.then(function(renderedBuffer) { curve0[1] = 0.125;
let actual = renderedBuffer.getChannelData(0); curve0[2] = 0.75;
let expected = renderedBuffer.getChannelData(1); },
`Modifying curve array at time ${context.currentTime}`)
// Modifying the wave shaper curve should not modify the output so .notThrow();
// the outputs from the two wave shaper nodes should be exactly })
// identical. .then(context.resume.bind(context));
should(actual, 'WaveShaper with modified curve')
.beEqualToArray(expected); src.start();
}) context.startRendering()
.then(() => task.done()); .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(); audit.run();
</script> </script>
......
...@@ -18,30 +18,38 @@ ...@@ -18,30 +18,38 @@
let shaper = context.createWaveShaper(); let shaper = context.createWaveShaper();
// Verify default values are correct. // Verify default values are correct.
should(shaper.curve, 'WaveShaper.curve').beEqualTo(null); should(shaper.curve, 'Initial WaveShaper.curve').beEqualTo(null);
should(shaper.oversample, 'WaveShaper.oversample').beEqualTo('none'); should(shaper.oversample, 'Initial WaveShaper.oversample')
.beEqualTo('none');
// Set oversample and verify that it is set correctly. // 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"') should(shaper.oversample, 'Waveshaper.oversample = "2x"')
.beEqualTo('2x'); .beEqualTo('2x');
shaper.oversample = '4x'; should(() => shaper.oversample = '4x', 'Setting oversample to "4x"')
.notThrow();
should(shaper.oversample, 'Waveshaper.oversample = "4x"') should(shaper.oversample, 'Waveshaper.oversample = "4x"')
.beEqualTo('4x'); .beEqualTo('4x');
shaper.oversample = 'invalid'; should(
() => shaper.oversample = 'invalid',
'Setting oversample to "invalid"')
.notThrow();
should(shaper.oversample, 'Waveshaper.oversample = "invalid"') should(shaper.oversample, 'Waveshaper.oversample = "invalid"')
.beEqualTo('4x'); .beEqualTo('4x');
// Set the curve and verify that the returned curve is the same as what // Set the curve and verify that the returned curve is the same as what
// it was set to. // it was set to.
let curve = Float32Array.from([-1, 0.25, .75]); 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); should(shaper.curve, 'WaveShaper.curve').beEqualToArray(curve);
// Verify setting the curve to null works. // 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); should(shaper.curve, 'Waveshaper.curve = null').beEqualTo(null);
task.done(); 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