Monday, October 16, 2017

Tone JS UI/UX Project Buffer Shuffler

https://tonejs.github.io/docs/

Tone.Buffer

↳ EXTENDS Tone
Buffer loading and storage. Tone.Buffer is used internally by all classes that make requests for audio files such as Tone.Player, Tone.Sampler and Tone.Convolver. Aside from load callbacks from individual buffers, Tone.Buffer provides events which keep track of the loading progress of all of the buffers. These are Tone.Buffer.on(“load” / “progress” / “error”)

CONSTRUCTOR

new Tone.Buffer ( 
url
 , [ 
onload
 ] , [ 
onerror
 ] )
url
The url to load, or the audio buffer to set.
TYPE: AudioBuffer OR String
onload
A callback which is invoked after the buffer is loaded. It’s recommended to use Tone.Buffer.on('load', callback) instead since it will give you a callback when all buffers are loaded.
TYPE: Function
OPTIONAL
onerror
The callback to invoke if there is an error
TYPE: Function
OPTIONAL

DEFAULTS

{
url : undefined ,
reverse : false
}

EXAMPLE

var buffer = new Tone.Buffer("path/to/sound.mp3", function(){
 //the buffer is now available.
 var buff = buffer.get();
});
 

EXAMPLE

//can load provide fallback extension types if the first type is not supported.
var buffer = new Tone.Buffer("path/to/sound.[mp3|ogg|wav]");

MEMBERS

.duration

  Number READONLY #
The duration of the buffer.

.length

  Number READONLY #
The length of the buffer in samples

.loaded

  Boolean READONLY #
If the buffer is loaded or not

.numberOfChannels

  Number READONLY #
The number of discrete audio channels. Returns 0 if no buffer is loaded.

.reverse

  Boolean #
Reverse the buffer.

METHODS

.dispose ( )

 #
↪ RETURNS Tone.Buffer
this
dispose and disconnect

.fromArray ( )

 #
array
The array to fill the audio buffer
TYPE: Float32Array
↪ RETURNS Tone.Buffer
this
Set the audio buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

.get ( )

 #
↪ RETURNS AudioBuffer
The audio buffer stored in the object.

.getChannelData ( )

 #
channel
The channel number to return
TYPE: Number
↪ RETURNS Float32Array
The audio as a TypedArray
Returns the Float32Array representing the PCM audio data for the specific channel.

.load ( )

 #
url
The url of the buffer to load. filetype support depends on the browser.
TYPE: String
↪ RETURNS Promise
returns a Promise which resolves with the Tone.Buffer
Makes an xhr reqest for the selected url then decodes the file as an audio buffer. Invokes the callback once the audio buffer loads.

.set ( )

 #
buffer
the buffer
TYPE: AudioBuffer OR Tone.Buffer
↪ RETURNS Tone.Buffer
this
Pass in an AudioBuffer or Tone.Buffer to set the value of this buffer.

.slice ( )

 #
start
The time to start the slice
TYPE: Time
end
The end time to slice. If none is given will default to the end of the buffer
TYPE: Time
OPTIONAL
↪ RETURNS Tone.Buffer
this
Cut a subsection of the array and return a buffer of the subsection. Does not modify the original buffer

.toArray ( )

 #
channel
Optionally only copy a single channel from the array.
TYPE: Number
OPTIONAL
↪ RETURNS Array
Get the buffer as an array. Single channel buffers will return a 1-dimensional Float32Array, and multichannel buffers will return multidimensional arrays.

.toMono ( )

 #
channel
Optionally only copy a single channel from the array.
TYPE: Number
OPTIONAL
↪ RETURNS Array
Sums muliple channels into 1 channel

STATIC METHODS

.cancelDownloads ( )

 #
↪ RETURNS Tone.Buffer
Stop all of the downloads in progress

.fromArray ( )

 #
array
The array to fill the audio buffer
TYPE: Float32Array
↪ RETURNS Tone.Buffer
A Tone.Buffer created from the array
Create a Tone.Buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

.load ( )

 #
url
TYPE: String
onload
TYPE: Function
onerror
TYPE: Function
onprogress
TYPE: Function
↪ RETURNS XMLHttpRequest
Loads a url using XMLHttpRequest.

.supportsType ( )

 #
url
The url/extension to test
TYPE: String
↪ RETURNS Boolean
If the file extension can be played
Checks a url’s extension to see if the current browser can play that file type.

EXAMPLE

Tone.Buffer.supportsType("wav"); //returns true
Tone.Buffer.supportsType("path/to/file.wav"); //returns true

No comments:

Post a Comment

Scripting for the Web Final

I spent a lot of time working on my updated portfolio website this semester. Here's an excerpt of the reflection post I wrote (because t...