Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 function createTestBuffer(context, sampleFrameLength) { | 1 function createTestBuffer(context, sampleFrameLength) { |
| 2 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate); | 2 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate); |
|
hongchan
2017/01/20 18:40:21
var => let (all instances in here)
Raymond Toy
2017/01/20 22:17:27
Done.
| |
| 3 var channelData = audioBuffer.getChannelData(0); | 3 var channelData = audioBuffer.getChannelData(0); |
| 4 | 4 |
| 5 // Create a simple linear ramp starting at zero, with each value in the buff er equal to its index position. | 5 // Create a simple linear ramp starting at zero, with each value in the buff er equal to its index position. |
| 6 for (var i = 0; i < sampleFrameLength; ++i) | 6 for (var i = 0; i < sampleFrameLength; ++i) |
| 7 channelData[i] = i; | 7 channelData[i] = i; |
| 8 | 8 |
| 9 return audioBuffer; | 9 return audioBuffer; |
| 10 } | 10 } |
| 11 | 11 |
| 12 function checkSingleTest(renderedBuffer, i) { | 12 function checkSingleTest(renderedBuffer, i, should) { |
| 13 var renderedData = renderedBuffer.getChannelData(0); | 13 var renderedData = renderedBuffer.getChannelData(0); |
| 14 var offsetFrame = i * testSpacingFrames; | 14 var offsetFrame = i * testSpacingFrames; |
| 15 | 15 |
| 16 var test = tests[i]; | 16 var test = tests[i]; |
| 17 var expected = test.expected; | 17 var expected = test.expected; |
| 18 var success = true; | |
| 19 var description; | 18 var description; |
| 20 | 19 |
| 21 if (test.description) { | 20 if (test.description) { |
| 22 description = test.description; | 21 description = test.description; |
| 23 } else { | 22 } else { |
| 24 // No description given, so create a basic one from the given test param eters. | 23 // No description given, so create a basic one from the given test param eters. |
| 25 description = "loop from " + test.loopStartFrame + " -> " + test.loopEnd Frame; | 24 description = "loop from " + test.loopStartFrame + " -> " + test.loopEnd Frame; |
| 26 if (test.offsetFrame) | 25 if (test.offsetFrame) |
| 27 description += " with offset " + test.offsetFrame; | 26 description += " with offset " + test.offsetFrame; |
| 28 if (test.playbackRate && test.playbackRate != 1) | 27 if (test.playbackRate && test.playbackRate != 1) |
| 29 description += " with playbackRate of " + test.playbackRate; | 28 description += " with playbackRate of " + test.playbackRate; |
| 30 } | 29 } |
| 31 | 30 |
| 32 var framesToTest; | 31 var framesToTest; |
| 33 | 32 |
| 34 if (test.renderFrames) | 33 if (test.renderFrames) |
| 35 framesToTest = test.renderFrames; | 34 framesToTest = test.renderFrames; |
| 36 else if (test.durationFrames) | 35 else if (test.durationFrames) |
| 37 framesToTest = test.durationFrames; | 36 framesToTest = test.durationFrames; |
| 38 | 37 |
| 39 // Verify that the output matches | 38 // Verify that the output matches |
| 40 for (var j = 0; j < framesToTest; ++j) { | 39 var prefix = "Case " + i + ": "; |
| 41 if (expected[j] != renderedData[offsetFrame + j]) { | 40 should(renderedData.slice(offsetFrame, offsetFrame + framesToTest), |
| 42 // Copy from Float32Array to regular JavaScript array for error mess age. | 41 prefix + description) |
| 43 var renderedArray = new Array(); | 42 .beEqualToArray(expected); |
| 44 for (var j = 0; j < test.renderFrames; ++j) | |
| 45 renderedArray[j] = renderedData[offsetFrame + j]; | |
| 46 | |
| 47 var s = description + ": expected: " + expected + " actual: " + rend eredArray; | |
| 48 success = false; | |
| 49 Should(s, success).beEqualTo(true); | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 | 43 |
| 54 // Verify that we get all zeroes after the buffer (or duration) has passed. | 44 // Verify that we get all zeroes after the buffer (or duration) has passed. |
| 55 for (var j = framesToTest; j < testSpacingFrames; ++j) { | 45 should(renderedData.slice(offsetFrame + framesToTest, offsetFrame + |
| 56 if (renderedData[offsetFrame + j]) { | 46 testSpacingFrames), |
| 57 // Copy from Float32Array to regular JavaScript array for error mess age. | 47 prefix + description + ": tail") |
| 58 var renderedArray = new Array(); | 48 .beConstantValueOf(0); |
| 59 for (var j = framesToTest; j < testSpacingFrames; ++j) | |
| 60 renderedArray[j - framesToTest] = renderedData[offsetFrame + j]; | |
| 61 | |
| 62 var s = description + ": expected: all zeroes actual: " + renderedAr ray; | |
| 63 success = false; | |
| 64 Should(s, success).beEqualTo(true); | |
| 65 break; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 Should("", success) | |
| 70 .summarize(description, description); | |
| 71 | |
| 72 return success; | |
| 73 } | 49 } |
| 74 | 50 |
| 75 function checkAllTests(event) { | 51 function checkAllTests(renderedBuffer, should) { |
| 76 var renderedBuffer = event.renderedBuffer; | |
| 77 for (var i = 0; i < tests.length; ++i) | 52 for (var i = 0; i < tests.length; ++i) |
| 78 checkSingleTest(renderedBuffer, i); | 53 checkSingleTest(renderedBuffer, i, should); |
| 79 | |
| 80 finishJSTest(); | |
| 81 } | 54 } |
| 82 | 55 |
| 83 | 56 |
| 84 // Create the actual result by modulating playbackRate or detune AudioParam of | 57 // Create the actual result by modulating playbackRate or detune AudioParam of |
| 85 // ABSN. |modTarget| is a string of AudioParam name, |modOffset| is the offset | 58 // ABSN. |modTarget| is a string of AudioParam name, |modOffset| is the offset |
| 86 // (anchor) point of modulation, and |modRange| is the range of modulation. | 59 // (anchor) point of modulation, and |modRange| is the range of modulation. |
| 87 // | 60 // |
| 88 // createSawtoothWithModulation(context, 'detune', 440, 1200); | 61 // createSawtoothWithModulation(context, 'detune', 440, 1200); |
| 89 // | 62 // |
| 90 // The above will perform a modulation on detune within the range of | 63 // The above will perform a modulation on detune within the range of |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 114 // The oscillator output should be amplified accordingly to drive the | 87 // The oscillator output should be amplified accordingly to drive the |
| 115 // modulation within the desired range. | 88 // modulation within the desired range. |
| 116 lfo.connect(amp); | 89 lfo.connect(amp); |
| 117 amp.connect(phasor[modTarget]); | 90 amp.connect(phasor[modTarget]); |
| 118 | 91 |
| 119 phasor.connect(context.destination); | 92 phasor.connect(context.destination); |
| 120 | 93 |
| 121 lfo.start(); | 94 lfo.start(); |
| 122 phasor.start(); | 95 phasor.start(); |
| 123 } | 96 } |
| OLD | NEW |