Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test DelayNode</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <pre id="test"> |
michael@0 | 10 | <script src="webaudio.js" type="text/javascript"></script> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | var gTest = { |
michael@0 | 14 | length: 4096, |
michael@0 | 15 | numberOfChannels: 1, |
michael@0 | 16 | createGraph: function(context) { |
michael@0 | 17 | var buffer = context.createBuffer(1, 2048, context.sampleRate); |
michael@0 | 18 | for (var i = 0; i < 2048; ++i) { |
michael@0 | 19 | buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | var source = context.createBufferSource(); |
michael@0 | 23 | |
michael@0 | 24 | var delay = context.createDelay(); |
michael@0 | 25 | |
michael@0 | 26 | source.buffer = buffer; |
michael@0 | 27 | |
michael@0 | 28 | source.connect(delay); |
michael@0 | 29 | |
michael@0 | 30 | ok(delay.delayTime, "The audioparam member must exist"); |
michael@0 | 31 | is(delay.delayTime.value, 0, "Correct initial value"); |
michael@0 | 32 | is(delay.delayTime.defaultValue, 0, "Correct default value"); |
michael@0 | 33 | delay.delayTime.value = 0.5; |
michael@0 | 34 | is(delay.delayTime.value, 0.5, "Correct initial value"); |
michael@0 | 35 | is(delay.delayTime.defaultValue, 0, "Correct default value"); |
michael@0 | 36 | is(delay.channelCount, 2, "delay node has 2 input channels by default"); |
michael@0 | 37 | is(delay.channelCountMode, "max", "Correct channelCountMode for the delay node"); |
michael@0 | 38 | is(delay.channelInterpretation, "speakers", "Correct channelCountInterpretation for the delay node"); |
michael@0 | 39 | |
michael@0 | 40 | expectException(function() { |
michael@0 | 41 | context.createDelay(0); |
michael@0 | 42 | }, DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 43 | expectException(function() { |
michael@0 | 44 | context.createDelay(180); |
michael@0 | 45 | }, DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 46 | expectTypeError(function() { |
michael@0 | 47 | context.createDelay(NaN); |
michael@0 | 48 | }, DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 49 | expectException(function() { |
michael@0 | 50 | context.createDelay(-1); |
michael@0 | 51 | }, DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 52 | context.createDelay(1); // should not throw |
michael@0 | 53 | |
michael@0 | 54 | // Delay the source stream by 2048 frames |
michael@0 | 55 | delay.delayTime.value = 2048 / context.sampleRate; |
michael@0 | 56 | |
michael@0 | 57 | source.start(0); |
michael@0 | 58 | return delay; |
michael@0 | 59 | }, |
michael@0 | 60 | createExpectedBuffers: function(context) { |
michael@0 | 61 | var expectedBuffer = context.createBuffer(1, 2048 * 2, context.sampleRate); |
michael@0 | 62 | for (var i = 2048; i < 2048 * 2; ++i) { |
michael@0 | 63 | expectedBuffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * (i - 2048) / context.sampleRate); |
michael@0 | 64 | } |
michael@0 | 65 | return expectedBuffer; |
michael@0 | 66 | }, |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | runTest(); |
michael@0 | 70 | |
michael@0 | 71 | </script> |
michael@0 | 72 | </pre> |
michael@0 | 73 | </body> |
michael@0 | 74 | </html> |