Title: [91780] trunk/LayoutTests
Revision
91780
Author
[email protected]
Date
2011-07-26 13:36:25 -0700 (Tue, 26 Jul 2011)

Log Message

Add first basic layout test for the web audio API
https://bugs.webkit.org/show_bug.cgi?id=57977

Reviewed by Tony Chang.

* webaudio: Added.
* webaudio/resources: Added.
* webaudio/resources/audio-testing.js: Added.
(writeString):
(writeInt16):
(writeInt32):
(writeAudioBuffer):
(createWaveFileData):
(createAudioData):
(finishAudioTest):
* webaudio/test-basic-expected.wav: Added.
* webaudio/test-basic.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (91779 => 91780)


--- trunk/LayoutTests/ChangeLog	2011-07-26 20:28:15 UTC (rev 91779)
+++ trunk/LayoutTests/ChangeLog	2011-07-26 20:36:25 UTC (rev 91780)
@@ -1,3 +1,23 @@
+2011-07-26  Chris Rogers  <[email protected]>
+
+        Add first basic layout test for the web audio API
+        https://bugs.webkit.org/show_bug.cgi?id=57977
+
+        Reviewed by Tony Chang.
+
+        * webaudio: Added.
+        * webaudio/resources: Added.
+        * webaudio/resources/audio-testing.js: Added.
+        (writeString):
+        (writeInt16):
+        (writeInt32):
+        (writeAudioBuffer):
+        (createWaveFileData):
+        (createAudioData):
+        (finishAudioTest):
+        * webaudio/test-basic-expected.wav: Added.
+        * webaudio/test-basic.html: Added.
+
 2011-07-26  Dan Bernstein  <[email protected]>
 
         <rdar://problem/9842889> Add a generic pictograph font family

Added: trunk/LayoutTests/webaudio/resources/audio-testing.js (0 => 91780)


--- trunk/LayoutTests/webaudio/resources/audio-testing.js	                        (rev 0)
+++ trunk/LayoutTests/webaudio/resources/audio-testing.js	2011-07-26 20:36:25 UTC (rev 91780)
@@ -0,0 +1,104 @@
+function writeString(s, a, offset) {
+    for (var i = 0; i < s.length; ++i) {
+        a[offset + i] = s.charCodeAt(i);
+    }
+}
+
+function writeInt16(n, a, offset) {
+    n = Math.floor(n);
+    
+    var b1 = n & 255;
+    var b2 = (n >> 8) & 255;
+
+    a[offset + 0] = b1;
+    a[offset + 1] = b2;
+}
+
+function writeInt32(n, a, offset) {
+    n = Math.floor(n);
+    var b1 = n & 255;
+    var b2 = (n >> 8) & 255;
+    var b3 = (n >> 16) & 255;
+    var b4 = (n >> 24) & 255;
+
+    a[offset + 0] = b1;
+    a[offset + 1] = b2;
+    a[offset + 2] = b3;
+    a[offset + 3] = b4;
+}
+
+function writeAudioBuffer(audioBuffer, a, offset) {
+    var n = audioBuffer.length;
+    var bufferL = audioBuffer.getChannelData(0);
+    var bufferR = audioBuffer.getChannelData(1);
+    
+    for (var i = 0; i < n; ++i) {
+        // Write left and right
+        var sampleL = bufferL[i] * 32768.0;
+        var sampleR = bufferR[i] * 32768.0;
+
+        // Clip left and right samples to the limitations of 16-bit.
+        // If we don't do this then we'll get nasty wrap-around distortion.
+        if (sampleL < -32768)
+            sampleL = -32768;
+        if (sampleL > 32767)
+            sampleL = 32767;
+        if (sampleR < -32768)
+            sampleR = -32768;
+        if (sampleR > 32767)
+            sampleR = 32767;
+            
+        writeInt16(sampleL, a, offset);
+        writeInt16(sampleR, a, offset + 2);
+        offset += 4;
+    }
+}
+
+function createWaveFileData(audioBuffer) {
+    var frameLength = audioBuffer.length;
+    var numberOfChannels = audioBuffer.numberOfChannels;
+    var sampleRate = audioBuffer.sampleRate;
+    var bitsPerSample = 16;
+    var byteRate = sampleRate * numberOfChannels * bitsPerSample/8;
+    var blockAlign = numberOfChannels * bitsPerSample/8;
+    var wavDataByteLength = frameLength * numberOfChannels * 2; // 16-bit audio
+    var headerByteLength = 44;
+    var totalLength = headerByteLength + wavDataByteLength;
+
+    var waveFileData = new Uint8Array(totalLength);
+    
+    var subChunk1Size = 16; // for linear PCM
+    var subChunk2Size = wavDataByteLength;
+    var chunkSize = 4 + (8 + subChunk1Size) + (8 + subChunk2Size);
+
+    writeString("RIFF", waveFileData, 0);
+    writeInt32(chunkSize, waveFileData, 4);
+    writeString("WAVE", waveFileData, 8);
+    writeString("fmt ", waveFileData, 12);
+    
+    writeInt32(subChunk1Size, waveFileData, 16);      // SubChunk1Size (4)
+    writeInt16(1, waveFileData, 20);                  // AudioFormat (2)
+    writeInt16(numberOfChannels, waveFileData, 22);   // NumChannels (2)
+    writeInt32(sampleRate, waveFileData, 24);         // SampleRate (4)
+    writeInt32(byteRate, waveFileData, 28);           // ByteRate (4)
+    writeInt16(blockAlign, waveFileData, 32);         // BlockAlign (2)
+    writeInt32(bitsPerSample, waveFileData, 34);      // BitsPerSample (4)
+                                                      
+    writeString("data", waveFileData, 36);            
+    writeInt32(subChunk2Size, waveFileData, 40);      // SubChunk2Size (4)
+    
+    // Write actual audio data starting at offset 44.
+    writeAudioBuffer(audioBuffer, waveFileData, 44);
+    
+    return waveFileData;
+}
+
+function createAudioData(audioBuffer) {
+    return createWaveFileData(audioBuffer);
+}
+
+function finishAudioTest(event) {
+    var audioData = createAudioData(event.renderedBuffer);
+    layoutTestController.setAudioData(audioData);
+    layoutTestController.notifyDone();
+}

Added: trunk/LayoutTests/webaudio/test-basic-expected.wav


(Binary files differ)
Property changes on: trunk/LayoutTests/webaudio/test-basic-expected.wav ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/webaudio/test-basic.html (0 => 91780)


--- trunk/LayoutTests/webaudio/test-basic.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/test-basic.html	2011-07-26 20:36:25 UTC (rev 91780)
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+
+<!--
+This is a very basic test to make sure layoutTestController.setAudioData() works correctly.
+It generates a 2 seconds long stereo result @44.1KHz
+The left channel will be a 880Hz tone, while the right will be 440Hz.
+-->
+
+<html>
+<head>
+
+<link rel="stylesheet" href=""
+<script src=""
+<script type="text/_javascript_" src=""
+
+</head>
+<body>
+
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("Tests basic audio test infrastructure: specifically layoutTestController.setAudioData()");
+
+var sampleRate = 44100.0;
+var lengthInSeconds = 2;
+
+function generateSinWave(audioBuffer) {
+    var n = audioBuffer.length;
+    var channelL = audioBuffer.getChannelData(0);
+    var channelR = audioBuffer.getChannelData(1);
+    var sampleRate = audioBuffer.sampleRate;
+    
+    for (var i = 0; i < n; ++i) {
+        channelL[i] = Math.sin(880.0 * 2.0*Math.PI * i / sampleRate);
+        channelR[i] = Math.sin(440.0 * 2.0*Math.PI * i / sampleRate);
+    }
+}
+
+function runTest() {
+    if (!window.layoutTestController)
+        return;
+    
+    var context = new webkitAudioContext();
+    var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
+    
+    generateSinWave(audioBuffer);
+
+    var audioData = createAudioData(audioBuffer);
+    layoutTestController.setAudioData(audioData);
+
+    layoutTestController.notifyDone();
+}
+
+runTest();
+successfullyParsed = true;
+
+</script>
+
+<script src=""
+
+<body>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to