Skip to content

Instantly share code, notes, and snippets.

View 72lions's full-sized avatar
👋

Thodoris Tsiridis 72lions

👋
View GitHub Profile
@72lions
72lions / create.audio.buffer.from.array.buffer.js
Created January 14, 2013 09:11
Creates an AudioBuffer from and ArrayBuffer
/**
* Is triggered when a chunk is loaded
*/
var _onChunkLoaded = function() {
// Concat two ArrayBuffers into a new one
_activeBuffer = _appendBuffer(_activeBuffer, _request.response);
// Use decodeAudioData for creating an AudioBuffer,
// so that we don't block the main thread.
@72lions
72lions / loading.binary.data.xmlhttprequest.js
Created January 14, 2013 09:03
Loading a binary data with the HXMLHttpRequest object
/**
* It is responsible for loading all the different chunks
*
* @private
* @type {XMLHttpRequest}
*/
var _request = new XMLHttpRequest();
// Set the responseType to arraybuffer
_request.responseType = 'arraybuffer';
@72lions
72lions / replace.audiobuffer.from.audiosource.js
Created January 14, 2013 09:25
Replaces the AudioBuffer of an AudioSource
// Adding a bit of scheduling so that we won't have single digit milisecond overlaps.
// Thanks to Chris Wilson for his suggestion.
var scheduledTime = 0.015;
try {
_audioSource.stop(scheduledTime);
} catch (e) {}
_audioSource = _context.createBufferSource();
_audioSource.buffer = _audioBuffer;
@72lions
72lions / concat.array.buffers.js
Created January 14, 2013 09:22
Concatenates two ArrayBuffers
/**
* Creates a new Uint8Array based on two different ArrayBuffers
*
* @private
* @param {ArrayBuffers} buffer1 The first buffer.
* @param {ArrayBuffers} buffer2 The second buffer.
* @return {ArrayBuffers} The new ArrayBuffer created out of the two.
*/
var _appendBuffer = function(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);