Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: ppapi/examples/audio_encode/audio_encode.html

Issue 1569553004: ppapi: examples: audio_encode: reduce array buffer reallocations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a set of buffers to hold the encoded audio data Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <!-- 3 <!--
4 Copyright 2015 The Chromium Authors. All rights reserved. 4 Copyright 2015 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be 5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file. 6 found in the LICENSE file.
7 --> 7 -->
8 <head> 8 <head>
9 <title>Audio Encoder Example</title> 9 <title>Audio Encoder Example</title>
10 <script type="text/javascript"> 10 <script type="text/javascript">
11 var plugin; 11 var plugin;
12 var track; 12 var track;
13 var writer; 13 var writer;
14 var profiles; 14 var profiles;
15 15
16 function writeString(array, offset, string) { 16 function writeString(array, offset, string) {
17 var out = new Uint8Array(array);
18 for (var i = 0; i < string.length; i++) 17 for (var i = 0; i < string.length; i++)
19 out.set([string.charCodeAt(i)], i + offset); 18 array.set([string.charCodeAt(i)], i + offset);
20 return string.length; 19 return string.length;
21 } 20 }
22 function writeValue(array, bytes, offset, value) { 21 function writeValue(array, bytes, offset, value) {
23 var out = new Uint8Array(array);
24 for (var i = 0; i < bytes; i++) 22 for (var i = 0; i < bytes; i++)
25 out.set([((value >>> (i * 8)) & 0xff)], offset + i); 23 array.set([((value >>> (i * 8)) & 0xff)], offset + i);
26 return bytes; 24 return bytes;
27 } 25 }
26
27 var BufferArray = function() {
28 this._arrays = [ this._createBuffer() ];
29 };
30 BufferArray.prototype = {
31 _createBuffer: function() {
32 var buffer = new Uint8Array(100 * 1024);
33 buffer.dataLength = 0;
34 return buffer;
35 },
36 appendData: function(data) {
37 var currentBuffer = this._arrays[this._arrays.length - 1];
38 if (currentBuffer.byteLength < (currentBuffer.dataLength + data.byteLeng th)) {
39 this._arrays.push(this._createBuffer());
40 currentBuffer = this._arrays[this._arrays.length - 1];
41 }
42 currentBuffer.set(new Uint8Array(data), currentBuffer.dataLength);
43 currentBuffer.dataLength += data.byteLength;
44 },
45 getByte: function(offset) {
46 var bufferOffset = 0;
47 for (var i = 0; i < this._arrays.length; i++) {
48 var buffer = this._arrays[i];
49 if (offset < (bufferOffset + buffer.dataLength)) {
50 return buffer[offset - bufferOffset];
51 }
52 bufferOffset += buffer.dataLength;
53 }
54 throw new Error('Out of range access');
55 },
56 getSize: function() {
57 var size = 0;
58 for (var i = 0; i < this._arrays.length; i++)
59 size += this._arrays[i].dataLength;
60 return size;
61 },
62 writeValue: function(bytes, offset, value) {
63 var bufferOffset = 0;
64 for (var i = 0; i < this._arrays.length; i++) {
65 var buffer = this._arrays[i];
66 if (offset < (bufferOffset + buffer.dataLength)) {
67 writeValue(buffer, bytes, offset - bufferOffset, value);
68 return;
69 }
70 bufferOffset += buffer.dataLength;
71 }
72 throw new Error('Out of range access');
73 },
74 toBlob: function() {
75 var result = new Uint8Array(this.getSize());
76 var offset = 0;
77 for (var i = 0; i < this._arrays.length; i++) {
78 var buffer = this._arrays[i];
79 result.set(buffer.subarray(0, buffer.dataLength), offset);
80 offset += buffer.dataLength;
81 }
82 return new Blob([result]);
83 },
84 };
85
28 // Writes way data. 86 // Writes way data.
bbudge 2016/01/20 19:13:09 s/way/wav ?
29 var WavWriter = function() { 87 var WavWriter = function() {
30 this.chunkSizeOffset = 0; 88 this.chunkSizeOffset = 0;
31 this.arrayBuffer = new ArrayBuffer(); 89 this.buffer = new BufferArray();
32 }; 90 };
33 WavWriter.prototype = { 91 WavWriter.prototype = {
34 writeHeader: function(format) { 92 writeHeader: function(format) {
35 this.arrayBuffer = 93 var buffer =
36 new ArrayBuffer(4 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 2 + 2 + 4 + 4); 94 new Uint8Array(4 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 2 + 2 + 4 + 4);
37 var i = 0; 95 var i = 0;
38 // File header 96 // File header
39 i += writeString(this.arrayBuffer, i, 'RIFF'); 97 i += writeString(buffer, i, 'RIFF');
40 i += 4; // Gap for final size. 98 i += 4; // Gap for final size.
41 i += writeString(this.arrayBuffer, i, 'WAVE'); 99 i += writeString(buffer, i, 'WAVE');
42 // Chunk ID. 100 // Chunk ID.
43 i += writeString(this.arrayBuffer, i, 'fmt '); 101 i += writeString(buffer, i, 'fmt ');
44 // Chunk length. 102 // Chunk length.
45 i += writeValue(this.arrayBuffer, 4, i, 16); 103 i += writeValue(buffer, 4, i, 16);
46 // Codec (uncompressed LPCM). 104 // Codec (uncompressed LPCM).
47 i += writeValue(this.arrayBuffer, 2, i, 1); 105 i += writeValue(buffer, 2, i, 1);
48 // Number of channels. 106 // Number of channels.
49 i += writeValue(this.arrayBuffer, 2, i, format.channels); 107 i += writeValue(buffer, 2, i, format.channels);
50 // Sample rate. 108 // Sample rate.
51 i += writeValue(this.arrayBuffer, 4, i, format.sample_rate); 109 i += writeValue(buffer, 4, i, format.sample_rate);
52 // Average bytes per seconds (sample rate * bytes per sample) 110 // Average bytes per seconds (sample rate * bytes per sample)
53 i += writeValue(this.arrayBuffer, 4, i, 111 i += writeValue(buffer, 4, i,
54 format.sample_rate * format.sample_size); 112 format.sample_rate * format.sample_size);
55 // Bytes per sample. 113 // Bytes per sample.
56 i += writeValue(this.arrayBuffer, 2, i, 114 i += writeValue(buffer, 2, i,
57 format.sample_size * format.channels); 115 format.sample_size * format.channels);
58 // Bits per sample. 116 // Bits per sample.
59 i += writeValue(this.arrayBuffer, 2, i, format.sample_size * 8); 117 i += writeValue(buffer, 2, i, format.sample_size * 8);
60 118
61 // Data chunk 119 // Data chunk
62 i += writeString(this.arrayBuffer, i, 'data'); 120 i += writeString(buffer, i, 'data');
63 this.chunkSizeOffset = i; // Location of the chunk's size 121 this.chunkSizeOffset = i; // Location of the chunk's size
122 this.buffer.appendData(buffer);
64 }, 123 },
65 writeData: function(data) { 124 writeData: function(data) {
66 var tmp = new Uint8Array(this.arrayBuffer.byteLength + data.byteLength); 125 this.buffer.appendData(data);
67 tmp.set(new Uint8Array(this.arrayBuffer), 0);
68 tmp.set(new Uint8Array(data), this.arrayBuffer.byteLength);
69 this.arrayBuffer = tmp.buffer;
70 }, 126 },
71 end: function() { 127 end: function() {
72 var out = new Uint32Array(this.arrayBuffer); 128 this.buffer.writeValue(4, 4, this.buffer.getSize() - 8);
73 out.set([this.arrayBuffer.byteLength - 8], 1); 129 this.buffer.writeValue(4, this.chunkSizeOffset,
74 out.set([this.arrayBuffer.byteLength - this.chunkSizeOffset], 130 this.buffer.getSize() - this.chunkSizeOffset);
75 this.chunkSizeOffset / 4);
76 }, 131 },
77 getSize: function() { 132 getSize: function() {
78 return this.arrayBuffer.byteLength; 133 return this.buffer.getSize();
79 }, 134 },
80 getData: function() { 135 getData: function() {
81 return this.arrayBuffer; 136 return this.buffer;
82 }, 137 },
83 getExtension: function() { 138 getExtension: function() {
84 return 'wav'; 139 return 'wav';
85 }, 140 },
86 }; 141 };
87 142
88 // Writes ogg data. 143 // Writes ogg data.
89 var OggWriter = function(profile) { 144 var OggWriter = function(profile) {
90 this.writeHeader = this._writeOpusHeader; 145 this.writeHeader = this._writeOpusHeader;
91 this.arrayBuffer = new ArrayBuffer(); 146 this.buffer = new BufferArray();
92 this.pageSequence = 0; 147 this.pageSequence = 0;
93 this.bitstreamNumber = 0; 148 this.bitstreamNumber = 0;
94 this.position = 0; 149 this.position = 0;
95 this.dataWritten = false; 150 this.dataWritten = false;
96 }; 151 };
97 OggWriter.prototype = { 152 OggWriter.prototype = {
98 _Start: 0x2, 153 _Start: 0x2,
99 _Continue: 0x1, 154 _Continue: 0x1,
100 _Stop: 0x4, 155 _Stop: 0x4,
101 _append: function(data) {
102 var tmp = new Uint8Array(this.arrayBuffer.byteLength + data.byteLength);
103 tmp.set(new Uint8Array(this.arrayBuffer), 0);
104 tmp.set(new Uint8Array(data), this.arrayBuffer.byteLength);
105 this.arrayBuffer = tmp.buffer;
106 },
107 _makeCRCTable: function() { 156 _makeCRCTable: function() {
108 var crcTable = []; 157 var crcTable = [];
109 for (var n = 0; n < 256; n++) { 158 for (var n = 0; n < 256; n++) {
110 var r = n << 24; 159 var r = n << 24;
111 for (var i = 0; i < 8; i++) { 160 for (var i = 0; i < 8; i++) {
112 if (r & 0x80000000) 161 if (r & 0x80000000)
113 r = (r << 1) ^ 0x04c11db7; 162 r = (r << 1) ^ 0x04c11db7;
114 else 163 else
115 r <<= 1; 164 r <<= 1;
116 } 165 }
117 crcTable[n] = r & 0xffffffff; 166 crcTable[n] = r & 0xffffffff;
118 } 167 }
119 return crcTable; 168 return crcTable;
120 }, 169 },
121 _crc32: function(data, start, end) { 170 _crc32: function(data, start, end) {
122 var crc = 0; 171 var crc = 0;
123 var u8data = new Uint8Array(data)
124 var crcTable = this._crcTable || (this._crcTable = this._makeCRCTable()) ; 172 var crcTable = this._crcTable || (this._crcTable = this._makeCRCTable()) ;
125 for (var i = start; i < end; i++) 173 for (var i = start; i < end; i++)
126 crc = (crc << 8) ^ crcTable[((crc >> 24) & 0xff) ^ u8data[i]]; 174 crc = (crc << 8) ^ crcTable[((crc >> 24) & 0xff) ^ data.getByte(i)];
127 return crc; 175 return crc;
128 }, 176 },
129 _writePage: function(flag, size, position) { 177 _writePage: function(flag, size, position) {
130 var pages = 1 + Math.floor(size / 255); 178 var pages = 1 + Math.floor(size / 255);
131 var buffer = new ArrayBuffer(27 + pages), i = 0; 179 var buffer = new Uint8Array(27 + pages), i = 0;
132 // capture_pattern. 180 // capture_pattern.
133 i += writeString(buffer, i, 'OggS'); 181 i += writeString(buffer, i, 'OggS');
134 // stream_structure_version. 182 // stream_structure_version.
135 i += writeValue(buffer, 1, i, 0); 183 i += writeValue(buffer, 1, i, 0);
136 // header_type_flag. 184 // header_type_flag.
137 i += writeValue(buffer, 1, i, flag); 185 i += writeValue(buffer, 1, i, flag);
138 // granule_position. 186 // granule_position.
139 // TODO(llandwerlin): Not writing more than 32bits for now, 187 // TODO(llandwerlin): Not writing more than 32bits for now,
140 // because Javascript doesn't have 64bits integers, this limits 188 // because Javascript doesn't have 64bits integers, this limits
141 // the duration to ~24 hours at 48kHz sampling rate. 189 // the duration to ~24 hours at 48kHz sampling rate.
142 i += writeValue(buffer, 4, i, position != undefined ? position : 0); 190 i += writeValue(buffer, 4, i, position != undefined ? position : 0);
143 i += writeValue(buffer, 4, i, 0); 191 i += writeValue(buffer, 4, i, 0);
144 // bitstream_serial_number. 192 // bitstream_serial_number.
145 i += writeValue(buffer, 4, i, this.bitstreamNumber); 193 i += writeValue(buffer, 4, i, this.bitstreamNumber);
146 // page_sequence_number. 194 // page_sequence_number.
147 i += writeValue(buffer, 4, i, this.pageSequence++); 195 i += writeValue(buffer, 4, i, this.pageSequence++);
148 // CRC_checksum. 196 // CRC_checksum.
149 i += writeValue(buffer, 4, i, 0); 197 i += writeValue(buffer, 4, i, 0);
150 // number_page_segments. 198 // number_page_segments.
151 i += writeValue(buffer, 1, i, pages); 199 i += writeValue(buffer, 1, i, pages);
152 // segment sizes. 200 // segment sizes.
153 for (var j = 0; j < (pages - 1); j++) 201 for (var j = 0; j < (pages - 1); j++)
154 i += writeValue(buffer, 1, i, 255); 202 i += writeValue(buffer, 1, i, 255);
155 i += writeValue(buffer, 1, i, size % 255); 203 i += writeValue(buffer, 1, i, size % 255);
156 204
157 this._append(buffer); 205 this.buffer.appendData(buffer);
158 }, 206 },
159 _writePageChecksum: function(pageOffset) { 207 _writePageChecksum: function(pageOffset) {
160 var crc = this._crc32(this.arrayBuffer, pageOffset, 208 var crc = this._crc32(this.buffer, pageOffset,
161 this.arrayBuffer.byteLength); 209 this.buffer.getSize());
162 writeValue(this.arrayBuffer, 4, pageOffset + 22, crc); 210 this.buffer.writeValue(4, pageOffset + 22, crc);
163 }, 211 },
164 _writeOpusHeader: function(format) { 212 _writeOpusHeader: function(format) {
165 this.format = format; 213 this.format = format;
166 var start = this.getSize(); 214 var start = this.buffer.getSize();
167 var buffer = new ArrayBuffer(8 + 1 + 1 + 2 + 4 + 2 + 1), i = 0; 215 var buffer = new Uint8Array(8 + 1 + 1 + 2 + 4 + 2 + 1), i = 0;
168 // Opus header. 216 // Opus header.
169 i += writeString(buffer, i, 'OpusHead'); 217 i += writeString(buffer, i, 'OpusHead');
170 // version. 218 // version.
171 i += writeValue(buffer, 1, i, 1); 219 i += writeValue(buffer, 1, i, 1);
172 // channel count. 220 // channel count.
173 i += writeValue(buffer, 1, i, format.channels); 221 i += writeValue(buffer, 1, i, format.channels);
174 // pre-skip. 222 // pre-skip.
175 i += writeValue(buffer, 2, i, 0); 223 i += writeValue(buffer, 2, i, 0);
176 // input sample rate. 224 // input sample rate.
177 i += writeValue(buffer, 4, i, format.sample_rate); 225 i += writeValue(buffer, 4, i, format.sample_rate);
178 // output gain. 226 // output gain.
179 i += writeValue(buffer, 2, i, 0); 227 i += writeValue(buffer, 2, i, 0);
180 // channel mapping family. 228 // channel mapping family.
181 i += writeValue(buffer, 1, i, 0); 229 i += writeValue(buffer, 1, i, 0);
182 230
183 this._writePage(this._Start, buffer.byteLength); 231 this._writePage(this._Start, buffer.byteLength);
184 this._append(buffer); 232 this.buffer.appendData(buffer);
185 this._writePageChecksum(start); 233 this._writePageChecksum(start);
186 this._writeCommentHeader('OpusTags'); 234 this._writeCommentHeader('OpusTags');
187 }, 235 },
188 _writeCommentHeader: function(name) { 236 _writeCommentHeader: function(name) {
189 var start = this.getSize(); 237 var start = this.buffer.getSize();
190 var buffer = new ArrayBuffer(8 + 4 + 8 + 4 + 4 + 13), i = 0; 238 var buffer = new Uint8Array(8 + 4 + 8 + 4 + 4 + 13), i = 0;
191 // Opus comment header. 239 // Opus comment header.
192 i += writeString(buffer, i, name); 240 i += writeString(buffer, i, name);
193 // Vendor string. 241 // Vendor string.
194 i += this._writeLengthString(buffer, i, 'Chromium'); 242 i += this._writeLengthString(buffer, i, 'Chromium');
195 // User comment list length 243 // User comment list length
196 i += writeValue(buffer, 4, i, 1); 244 i += writeValue(buffer, 4, i, 1);
197 // User comment 0 length. 245 // User comment 0 length.
198 i += this._writeLengthString(buffer, i, 'TITLE=example'); 246 i += this._writeLengthString(buffer, i, 'TITLE=example');
199 247
200 this._writePage(this._Continue, buffer.byteLength); 248 this._writePage(this._Continue, buffer.byteLength);
201 this._append(buffer); 249 this.buffer.appendData(buffer);
202 this._writePageChecksum(start); 250 this._writePageChecksum(start);
203 }, 251 },
204 _writeLengthString: function(buffer, offset, str) { 252 _writeLengthString: function(buffer, offset, str) {
205 return (writeValue(buffer, offset, 4, str.length) + 253 return (writeValue(buffer, offset, 4, str.length) +
206 writeString(buffer, offset, str)); 254 writeString(buffer, offset, str));
207 }, 255 },
208 writeData: function(data) { 256 writeData: function(data) {
209 this.position += this.format.sample_per_frame / this.format.channels; 257 this.position += this.format.sample_per_frame / this.format.channels;
210 var start = this.getSize(); 258 var start = this.buffer.getSize();
211 this._writePage(0, data.byteLength, this.position); 259 this._writePage(0, data.byteLength, this.position);
212 this._append(data); 260 this.buffer.appendData(data);
213 this._writePageChecksum(start); 261 this._writePageChecksum(start);
214 this.dataWritten = true; 262 this.dataWritten = true;
215 }, 263 },
216 end: function() { 264 end: function() {
217 this._writePage(this._Stop, 0); 265 this._writePage(this._Stop, 0);
218 }, 266 },
219 getSize: function() {
220 return this.arrayBuffer.byteLength;
221 },
222 getData: function() { 267 getData: function() {
223 return this.arrayBuffer; 268 return this.buffer;
224 }, 269 },
225 getExtension: function() { 270 getExtension: function() {
226 return 'ogg'; 271 return 'ogg';
227 }, 272 },
228 }; 273 };
229 274
230 function $(id) { 275 function $(id) {
231 return document.getElementById(id); 276 return document.getElementById(id);
232 } 277 }
233 278
(...skipping 14 matching lines...) Expand all
248 console.log("Error: ", e); 293 console.log("Error: ", e);
249 } 294 }
250 295
251 function cleanupDownload() { 296 function cleanupDownload() {
252 var download = $('download'); 297 var download = $('download');
253 if (!download) 298 if (!download)
254 return; 299 return;
255 download.parentNode.removeChild(download); 300 download.parentNode.removeChild(download);
256 } 301 }
257 302
258 function setDownload(data, filename) { 303 function setDownload(blob, filename) {
259 var mimeType = 'application/octet-stream'; 304 var mimeType = 'application/octet-stream';
260 var blob = new Blob([data], { type: mimeType });
261 var a = document.createElement('a'); 305 var a = document.createElement('a');
262 a.id = "download"; 306 a.id = "download";
263 a.download = filename; 307 a.download = filename;
264 a.href = window.URL.createObjectURL(blob); 308 a.href = window.URL.createObjectURL(blob);
265 a.textContent = 'Download'; 309 a.textContent = 'Download';
266 a.dataset.downloadurl = [mimeType, a.download, a.href].join(':'); 310 a.dataset.downloadurl = [mimeType, a.download, a.href].join(':');
267 $('download-box').appendChild(a); 311 $('download-box').appendChild(a);
268 } 312 }
269 313
270 function startRecord() { 314 function startRecord() {
(...skipping 19 matching lines...) Expand all
290 video: false}, 334 video: false},
291 success, failure); 335 success, failure);
292 } 336 }
293 337
294 function stopRecord() { 338 function stopRecord() {
295 plugin.postMessage({ 339 plugin.postMessage({
296 command: "stop" 340 command: "stop"
297 }); 341 });
298 track.stop(); 342 track.stop();
299 writer.end(); 343 writer.end();
300 setDownload(writer.getData(), 'Capture.' + writer.getExtension()); 344 setDownload(writer.getData().toBlob(),
301 } 345 'Capture.' + writer.getExtension());
302
303 function saveBlob(blob) {
304 var blobUrl = URL.createObjectURL(blob);
305 window.location = blobUrl;
306 } 346 }
307 347
308 function handleMessage(msg) { 348 function handleMessage(msg) {
309 if (msg.data.command == 'log') { 349 if (msg.data.command == 'log') {
310 console.log(msg.data.message); 350 console.log(msg.data.message);
311 } else if (msg.data.command == 'error') { 351 } else if (msg.data.command == 'error') {
312 console.error(msg.data.message); 352 console.error(msg.data.message);
313 } else if (msg.data.command == 'data') { 353 } else if (msg.data.command == 'data') {
314 writer.writeData(msg.data.buffer); 354 writer.writeData(msg.data.buffer);
315 $('length').textContent = ' Size: ' + writer.getSize() + ' bytes'; 355 $('length').textContent = ' Size: ' + writer.getData().getSize() + ' byt es';
316 } else if (msg.data.command == 'format') { 356 } else if (msg.data.command == 'format') {
317 writer.writeHeader(msg.data); 357 writer.writeHeader(msg.data);
318 $('length').textContent = ' Size: ' + writer.getSize() + ' bytes'; 358 $('length').textContent = ' Size: ' + writer.getData().getSize() + ' byt es';
319 } else if (msg.data.command == 'supportedProfiles') { 359 } else if (msg.data.command == 'supportedProfiles') {
320 profiles = []; 360 profiles = [];
321 var profileList = $('profileList'); 361 var profileList = $('profileList');
322 while (profileList.lastChild) 362 while (profileList.lastChild)
323 profileList.remove(profileList.lastChild); 363 profileList.remove(profileList.lastChild);
324 364
325 var item = document.createElement('option'); 365 var item = document.createElement('option');
326 item.label = 'wav'; 366 item.label = 'wav';
327 profiles.push({ name: 'wav', 367 profiles.push({ name: 'wav',
328 sample_rate: 0, 368 sample_rate: 0,
329 sample_size: 0, 369 sample_size: 0,
330 sample_per_frame: 370 sample_per_frame:
331 msg.data.profiles[0].sample_per_frame }); 371 msg.data.profiles[0].sample_per_frame });
332 profileList.appendChild(item); 372 profileList.appendChild(item);
333 for (var i = 0; i < msg.data.profiles.length; i++) { 373 for (var i = 0; i < msg.data.profiles.length; i++) {
334 var item = document.createElement('option'); 374 var item = document.createElement('option');
335 item.label = msg.data.profiles[i].name + ' - ' + 375 item.label = msg.data.profiles[i].name + ' - ' +
336 msg.data.profiles[i].sample_rate + 'Hz'; 376 msg.data.profiles[i].sample_rate + 'Hz';
337 profiles.push(msg.data.profiles[i]); 377 profiles.push(msg.data.profiles[i]);
338 profileList.appendChild(item); 378 profileList.appendChild(item);
339 } 379 }
340 } 380 }
341 } 381 }
342 382
343 function resetData() { 383 function resetData() {
344 writer = new WavWriter(); 384 writer = new WavWriter();
345 $('length').textContent = ' Size: ' + writer.getSize() + ' bytes'; 385 $('length').textContent = ' Size: ' + writer.getData().getSize() + ' bytes ';
346 } 386 }
347 387
348 function initialize() { 388 function initialize() {
349 plugin = $('plugin'); 389 plugin = $('plugin');
350 plugin.addEventListener('message', handleMessage, false); 390 plugin.addEventListener('message', handleMessage, false);
351 391
352 $('start').addEventListener('click', function (e) { 392 $('start').addEventListener('click', function (e) {
353 resetData(); 393 resetData();
354 startRecord(); 394 startRecord();
355 }); 395 });
(...skipping 13 matching lines...) Expand all
369 409
370 <select id="profileList"></select> 410 <select id="profileList"></select>
371 <input type="button" id="start" value="Start Recording"/> 411 <input type="button" id="start" value="Start Recording"/>
372 <input type="button" id="stop" value="Stop Recording"/> 412 <input type="button" id="stop" value="Stop Recording"/>
373 <div id="download-box"></div> 413 <div id="download-box"></div>
374 <div id="length"></div> 414 <div id="length"></div>
375 <br> 415 <br>
376 <embed id="plugin" type="application/x-ppapi-example-audio-encode"/> 416 <embed id="plugin" type="application/x-ppapi-example-audio-encode"/>
377 </body> 417 </body>
378 </html> 418 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698