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,14 +18,20 @@ ...@@ -18,14 +18,20 @@
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'
},
(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); let context = new OfflineAudioContext(2, renderFrames, sampleRate);
// Just use a default oscillator as the source. Doesn't really matter // Just use a default oscillator as the source. Doesn't really
// what we use. // matter what we use.
let src = context.createOscillator(); let src = context.createOscillator();
src.type = 'sawtooth'; src.type = 'sawtooth';
...@@ -34,9 +40,9 @@ ...@@ -34,9 +40,9 @@
let ws0 = context.createWaveShaper(); let ws0 = context.createWaveShaper();
let ws1 = context.createWaveShaper(); let ws1 = context.createWaveShaper();
// Wave shaper curves. Doesn't really matter what we use as long as it // Wave shaper curves. Doesn't really matter what we use as long as
// modifies the input in some way. Thus, keep it simple and just invert // it modifies the input in some way. Thus, keep it simple and just
// the input. // invert the input.
let desiredCurve = [1, 0, -1]; let desiredCurve = [1, 0, -1];
let curve0 = Float32Array.from(desiredCurve); let curve0 = Float32Array.from(desiredCurve);
let curve1 = Float32Array.from(desiredCurve); let curve1 = Float32Array.from(desiredCurve);
...@@ -59,10 +65,15 @@ ...@@ -59,10 +65,15 @@
// Doesn't really matter what we modify the curve to as long as it's // Doesn't really matter what we modify the curve to as long as it's
// different. // different.
context.suspend(256 / context.sampleRate) context.suspend(256 / context.sampleRate)
.then(function() { .then(() => {
should(
() => {
curve0[0] = -0.5; curve0[0] = -0.5;
curve0[1] = 0.125; curve0[1] = 0.125;
curve0[2] = 0.75; curve0[2] = 0.75;
},
`Modifying curve array at time ${context.currentTime}`)
.notThrow();
}) })
.then(context.resume.bind(context)); .then(context.resume.bind(context));
...@@ -73,10 +84,10 @@ ...@@ -73,10 +84,10 @@
let actual = renderedBuffer.getChannelData(0); let actual = renderedBuffer.getChannelData(0);
let expected = renderedBuffer.getChannelData(1); let expected = renderedBuffer.getChannelData(1);
// Modifying the wave shaper curve should not modify the output so // Modifying the wave shaper curve should not modify the
// the outputs from the two wave shaper nodes should be exactly // output so the outputs from the two wave shaper nodes should
// identical. // be exactly identical.
should(actual, 'WaveShaper with modified curve') should(actual, 'Output of WaveShaper with modified curve')
.beEqualToArray(expected); .beEqualToArray(expected);
}) })
......
...@@ -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